cmake: Use SYSCONF_DIR=/etc for fhs build into /usr.
[gemrb.git] / CMakeLists.txt
bloba21dd0b6d3c44534d5b888236637a02bc5a096a2
1 cmake_minimum_required(VERSION 2.4.4)
2 if(COMMAND cmake_policy)
3       cmake_policy(SET CMP0003 NEW)
4       cmake_policy(SET CMP0005 NEW)
5 endif(COMMAND cmake_policy)
7 # If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition
8 # and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE
9 # to Release prior to calling PROJECT()
10 IF(DEFINED CMAKE_BUILD_TYPE)
11    SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
12 ELSE(DEFINED CMAKE_BUILD_TYPE)
13    SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
14 ENDIF(DEFINED CMAKE_BUILD_TYPE)
16 PROJECT(gemrb)
17 # try to extract the version from the source
18 execute_process(
19   COMMAND sed -n "s/\#define VERSION_GEMRB .\\([^\"]*\\).$/\\1/p" ${CMAKE_CURRENT_SOURCE_DIR}/gemrb/includes/globals.h
20   OUTPUT_VARIABLE GEMRB_VERSION
21   RESULT_VARIABLE RC
22   OUTPUT_STRIP_TRAILING_WHITESPACE
24 if(${RC} GREATER 0) # lookup failed
25   set(GEMRB_VERSION "unknown")
26 endif(${RC} GREATER 0)
27 message("Detected version: ${GEMRB_VERSION}")
29 IF(PREFIX)
30   SET(PREFIX CACHE PATH "Abbreviation for CMAKE_INSTALL_PREFIX.")
31   SET(CMAKE_INSTALL_PREFIX ${PREFIX})
32 ENDIF(PREFIX)
34 if (NOT LAYOUT)
35         if (WIN32)
36                 set(LAYOUT "home")
37         else (WIN32)
38                 set(LAYOUT "fhs")
39         endif (WIN32)
40 endif (NOT LAYOUT)
42 SET(LAYOUT "${LAYOUT}" CACHE STRING "Directory layout.")
44 if (${LAYOUT} MATCHES "home")
45         IF( NOT PLUGIN_DIR )
46                 SET( PLUGIN_DIR ${CMAKE_INSTALL_PREFIX}/plugins )
47         ENDIF( NOT PLUGIN_DIR )
48         IF( NOT DATA_DIR )
49                 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX} )
50         ENDIF( NOT DATA_DIR )
51         IF( NOT MAN_DIR )
52                 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
53         ENDIF( NOT MAN_DIR )
54         IF( NOT BIN_DIR )
55                 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX} )
56         ENDIF( NOT BIN_DIR )
57         IF( NOT SYSCONF_DIR )
58                 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX} )
59         ENDIF( NOT SYSCONF_DIR )
60         IF( NOT LIB_DIR )
61                 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX} )
62         ENDIF( NOT LIB_DIR )
63         IF( NOT ICON_DIR )
64                 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX} )
65         ENDIF( NOT ICON_DIR )
66         IF( NOT MENU_DIR )
67                 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX} )
68         ENDIF( NOT MENU_DIR )
69 elseif (${LAYOUT} MATCHES "fhs")
70         IF( NOT LIB_DIR )
71                 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/gemrb )
72         ENDIF( NOT LIB_DIR )
73         IF( NOT PLUGIN_DIR )
74                 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
75         ENDIF( NOT PLUGIN_DIR )
76         IF( NOT DATA_DIR )
77                 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/gemrb )
78         ENDIF( NOT DATA_DIR )
79         IF( NOT MAN_DIR )
80                 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/share/man/man6 )
81         ENDIF( NOT MAN_DIR )
82         IF( NOT BIN_DIR )
83                 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
84         ENDIF( NOT BIN_DIR )
85         IF( NOT SYSCONF_DIR )
86                 if ( ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr" )
87                         SET( SYSCONF_DIR /etc/gemrb )
88                 else ()
89                         SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc/gemrb )
90                 endif ()
91         ENDIF( NOT SYSCONF_DIR )
92         IF( NOT ICON_DIR )
93                 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
94         ENDIF( NOT ICON_DIR )
95         IF( NOT MENU_DIR )
96                 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
97         ENDIF( NOT MENU_DIR )
98 else (${LAYOUT} MATCHES "opt")
99         IF( NOT LIB_DIR )
100                 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib )
101         ENDIF( NOT LIB_DIR )
102         IF( NOT PLUGIN_DIR )
103                 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
104         ENDIF( NOT PLUGIN_DIR )
105         IF( NOT DATA_DIR )
106                 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/ )
107         ENDIF( NOT DATA_DIR )
108         IF( NOT MAN_DIR )
109                 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
110         ENDIF( NOT MAN_DIR )
111         IF( NOT BIN_DIR )
112                 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
113         ENDIF( NOT BIN_DIR )
114         IF( NOT SYSCONF_DIR )
115                 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc )
116         ENDIF( NOT SYSCONF_DIR )
117         IF( NOT ICON_DIR )
118                 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
119         ENDIF( NOT ICON_DIR )
120         IF( NOT MENU_DIR )
121                 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
122         ENDIF( NOT MENU_DIR )
123 endif (${LAYOUT} MATCHES "home")
126 IF(CMAKE_COMPILER_IS_GNUCXX)
127         if ( NOT DISABLE_WERROR )
128                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
129         endif ( NOT DISABLE_WERROR )
130         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wpointer-arith -Wcast-align")
131         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-format-y2k -Wno-long-long -fno-strict-aliasing")
132         # only export symbols explicitly marked to be exported.
133         INCLUDE(CheckCXXCompilerFlag)
134         CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" VISIBILITY_HIDDEN)
135         IF (VISIBILITY_HIDDEN)
136                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
137         ENDIF (VISIBILITY_HIDDEN)
138         if (WIN32)
139                 # GCC 4.5.0+ has shared libstdc++ without dllimport
140                 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-auto-import")
141                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-auto-import")
142         endif (WIN32)
143         # Ensure all plugin symbols exist.
144         if (NOT APPLE)
145                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
146         endif (NOT APPLE)
147 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
149 MESSAGE(STATUS "Looking for Python libraries")
150 INCLUDE(FindPythonLibs)
151 IF(PYTHON_LIBRARY)
152  MESSAGE(STATUS "Python Libraries Found")
153 ELSE(PYTHON_LIBRARY)
154  MESSAGE(FATAL_ERROR "Unable to find Python development libraries. Please get it from www.python.org")
155 ENDIF(PYTHON_LIBRARY)
157 MESSAGE(STATUS "Looking for openAL libraries")
158 INCLUDE(FindOpenAL)
159 IF(OPENAL_FOUND)
160  MESSAGE(STATUS "openal found")
161 ELSE(OPENAL_FOUND)
162  MESSAGE(ERROR "unable to find openal. please set OPENALDIR environment variable or get it from www.openal.org")
163 ENDIF(OPENAL_FOUND)
165 MESSAGE(STATUS "Looking for SDL")
166 INCLUDE(FindSDL)
167 IF(SDL_FOUND)
168  MESSAGE(STATUS "SDL found")
169 ELSE(SDL_FOUND)
170  MESSAGE(FATAL_ERROR "unable to find SDL. please get it from www.libsdl.org")
171 ENDIF(SDL_FOUND)
173 MESSAGE( STATUS "Looking for Zlib" )
174 #SET(ZLIB_FIND_REQUIRED TRUE)
175 INCLUDE(FindZLIB)
177 MESSAGE( STATUS "Looking for libPNG" )
178 INCLUDE(FindPNG)
179 IF(PNG_FOUND)
180  MESSAGE( STATUS "libPNG found" )
181 ELSE(PNG_FOUND)
182  MESSAGE( STATUS "WARNING : GemRB will be built without any PNG support. Get it from www.libpng.org" )
183 ENDIF(PNG_FOUND)
185 IF(UNIX)
186  MESSAGE(STATUS "Looking for dl library")
187  FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
188  IF(DLD_LIBRARY_PATH)
189   MESSAGE(STATUS "dl library found")
190  ELSE(DLD_LIBRARY_PATH)
191   MESSAGE(FATAL_ERROR "dl library not found")
192  ENDIF(DLD_LIBRARY_PATH)
193 ENDIF(UNIX)
195 MESSAGE(STATUS "Looking for Ogg Vorbis support")
196 FIND_LIBRARY(VORBIS_LIBRARY vorbisfile)
198 ADD_DEFINITIONS("-DHAVE_CONFIG_H")
200 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} gemrb/includes gemrb/core)
202 #Platform checks
203 INCLUDE (CheckTypeSize)
204 CHECK_TYPE_SIZE("int" SIZEOF_INT)
205 CHECK_TYPE_SIZE("long int" SIZEOF_LONG_INT)
207 INCLUDE (CheckFunctionExists)
208 CHECK_FUNCTION_EXISTS("snprintf" HAVE_SNPRINTF)
209 CHECK_FUNCTION_EXISTS("strndup" HAVE_STRNDUP)
211 #Unneeded on windows
212 IF(NOT WIN32)
213 INCLUDE (CheckCXXSourceCompiles)
214 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
216 void *object = 0;
217 voidvoid function;
218 function = (voidvoid) object;
219 " PERMITS_OBJECT_TO_FUNCTION_CAST)
221 IF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
222  SET(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST 1)
223 ENDIF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
224 ENDIF(NOT WIN32)
226 IF(VORBIS_LIBRARY)
227  SET(HAS_VORBIS_SUPPORT 1)
228 ELSE(VORBIS_LIBRARY)
229  SET(VORBIS_LIBRARY "")
230 ENDIF(VORBIS_LIBRARY)
232 IF(APPLE)
233  FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
234  FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
235 ENDIF(APPLE)
237 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.h.in
238         ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
240 #Plugin addition macro
241 MACRO(ADD_GEMRB_PLUGIN plugin_name)
242         ADD_LIBRARY(${plugin_name} MODULE ${ARGN})
243         SET_TARGET_PROPERTIES(${plugin_name} PROPERTIES PREFIX ""
244                 INSTALL_RPATH ${LIB_DIR}
245                 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/gemrb/plugins)
246         TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
247         INSTALL(TARGETS ${plugin_name} DESTINATION ${PLUGIN_DIR})
248 ENDMACRO(ADD_GEMRB_PLUGIN)
250 #gemrb overrides macro
251 MACRO(ADD_GEMRB_OVERRIDE game_name)
252 FILE( GLOB FILES_TO_INSTALL *.2da *.bmp *.ini *.chu *.ids *.bcs *.vvc *.mos *.spl *.wav *.pro)
253 INSTALL( FILES ${FILES_TO_INSTALL} DESTINATION ${DATA_DIR}/override/${game_name} )
254 ENDMACRO(ADD_GEMRB_OVERRIDE )
256 ADD_SUBDIRECTORY( gemrb )
257 INSTALL( FILES gemrb.6 DESTINATION ${MAN_DIR} )
258 INSTALL( FILES artwork/gemrb-logo.png DESTINATION ${ICON_DIR} )
259 INSTALL( FILES gemrb.desktop DESTINATION ${MENU_DIR} )
261 CONFIGURE_FILE(
262   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
263   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
264   IMMEDIATE @ONLY
267 # copy the variable, since the file uses @VERSION@
268 set(VERSION ${GEMRB_VERSION})
269 CONFIGURE_FILE(
270   "${CMAKE_CURRENT_SOURCE_DIR}/gemrb.spec.in"
271   "${CMAKE_CURRENT_BINARY_DIR}/gemrb.spec"
272   IMMEDIATE @ONLY
275 ADD_CUSTOM_TARGET( uninstall
276   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )
278 # make dist for a gzipped tarball of current HEAD
279 set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GEMRB_VERSION})
280 add_custom_target( dist
281   COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
282     | gzip --best > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz
283   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}