First go at supporting mods.
[gemrb.git] / CMakeLists.txt
blob36cbbfb463eb1c0f41115c2a041f0deca104b394
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                 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc/gemrb )
87         ENDIF( NOT SYSCONF_DIR )
88         IF( NOT ICON_DIR )
89                 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
90         ENDIF( NOT ICON_DIR )
91         IF( NOT MENU_DIR )
92                 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
93         ENDIF( NOT MENU_DIR )
94 else (${LAYOUT} MATCHES "opt")
95         IF( NOT LIB_DIR )
96                 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib )
97         ENDIF( NOT LIB_DIR )
98         IF( NOT PLUGIN_DIR )
99                 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
100         ENDIF( NOT PLUGIN_DIR )
101         IF( NOT DATA_DIR )
102                 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/ )
103         ENDIF( NOT DATA_DIR )
104         IF( NOT MAN_DIR )
105                 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
106         ENDIF( NOT MAN_DIR )
107         IF( NOT BIN_DIR )
108                 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
109         ENDIF( NOT BIN_DIR )
110         IF( NOT SYSCONF_DIR )
111                 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc )
112         ENDIF( NOT SYSCONF_DIR )
113         IF( NOT ICON_DIR )
114                 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
115         ENDIF( NOT ICON_DIR )
116         IF( NOT MENU_DIR )
117                 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
118         ENDIF( NOT MENU_DIR )
119 endif (${LAYOUT} MATCHES "home")
122 IF(CMAKE_COMPILER_IS_GNUCXX)
123         if ( NOT DISABLE_WERROR )
124                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
125         endif ( NOT DISABLE_WERROR )
126         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wpointer-arith -Wcast-align")
127         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-format-y2k -Wno-long-long -fno-strict-aliasing")
128         # only export symbols explicitly marked to be exported.
129         INCLUDE(CheckCXXCompilerFlag)
130         CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" VISIBILITY_HIDDEN)
131         IF (VISIBILITY_HIDDEN)
132                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
133         ENDIF (VISIBILITY_HIDDEN)
134         if (WIN32)
135                 # GCC 4.5.0+ has shared libstdc++ without dllimport
136                 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-auto-import")
137                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-auto-import")
138         endif (WIN32)
139         # Ensure all plugin symbols exist.
140         if (NOT APPLE)
141                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
142         endif (NOT APPLE)
143 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
145 MESSAGE(STATUS "Looking for Python libraries")
146 INCLUDE(FindPythonLibs)
147 IF(PYTHON_LIBRARY)
148  MESSAGE(STATUS "Python Libraries Found")
149 ELSE(PYTHON_LIBRARY)
150  MESSAGE(FATAL_ERROR "Unable to find Python development libraries. Please get it from www.python.org")
151 ENDIF(PYTHON_LIBRARY)
153 MESSAGE(STATUS "Looking for openAL libraries")
154 INCLUDE(FindOpenAL)
155 IF(OPENAL_FOUND)
156  MESSAGE(STATUS "openal found")
157 ELSE(OPENAL_FOUND)
158  MESSAGE(ERROR "unable to find openal. please set OPENALDIR environment variable or get it from www.openal.org")
159 ENDIF(OPENAL_FOUND)
161 MESSAGE(STATUS "Looking for SDL")
162 INCLUDE(FindSDL)
163 IF(SDL_FOUND)
164  MESSAGE(STATUS "SDL found")
165 ELSE(SDL_FOUND)
166  MESSAGE(FATAL_ERROR "unable to find SDL. please get it from www.libsdl.org")
167 ENDIF(SDL_FOUND)
169 MESSAGE( STATUS "Looking for Zlib" )
170 #SET(ZLIB_FIND_REQUIRED TRUE)
171 INCLUDE(FindZLIB)
173 MESSAGE( STATUS "Looking for libPNG" )
174 INCLUDE(FindPNG)
175 IF(PNG_FOUND)
176  MESSAGE( STATUS "libPNG found" )
177 ELSE(PNG_FOUND)
178  MESSAGE( STATUS "WARNING : GemRB will be built without any PNG support. Get it from www.libpng.org" )
179 ENDIF(PNG_FOUND)
181 IF(UNIX)
182  MESSAGE(STATUS "Looking for dl library")
183  FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
184  IF(DLD_LIBRARY_PATH)
185   MESSAGE(STATUS "dl library found")
186  ELSE(DLD_LIBRARY_PATH)
187   MESSAGE(FATAL_ERROR "dl library not found")
188  ENDIF(DLD_LIBRARY_PATH)
189 ENDIF(UNIX)
191 MESSAGE(STATUS "Looking for Ogg Vorbis support")
192 FIND_LIBRARY(VORBIS_LIBRARY vorbisfile)
194 ADD_DEFINITIONS("-DHAVE_CONFIG_H")
196 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} gemrb/includes gemrb/core)
198 #Platform checks
199 INCLUDE (CheckTypeSize)
200 CHECK_TYPE_SIZE("int" SIZEOF_INT)
201 CHECK_TYPE_SIZE("long int" SIZEOF_LONG_INT)
203 INCLUDE (CheckFunctionExists)
204 CHECK_FUNCTION_EXISTS("snprintf" HAVE_SNPRINTF)
205 CHECK_FUNCTION_EXISTS("strndup" HAVE_STRNDUP)
207 #Unneeded on windows
208 IF(NOT WIN32)
209 INCLUDE (CheckCXXSourceCompiles)
210 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
212 void *object = 0;
213 voidvoid function;
214 function = (voidvoid) object;
215 " PERMITS_OBJECT_TO_FUNCTION_CAST)
217 IF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
218  SET(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST 1)
219 ENDIF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
220 ENDIF(NOT WIN32)
222 IF(VORBIS_LIBRARY)
223  SET(HAS_VORBIS_SUPPORT 1)
224 ELSE(VORBIS_LIBRARY)
225  SET(VORBIS_LIBRARY "")
226 ENDIF(VORBIS_LIBRARY)
228 IF(APPLE)
229  FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
230  FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
231 ENDIF(APPLE)
233 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.h.in
234         ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
236 #Plugin addition macro
237 MACRO(ADD_GEMRB_PLUGIN plugin_name)
238         ADD_LIBRARY(${plugin_name} MODULE ${ARGN})
239         SET_TARGET_PROPERTIES(${plugin_name} PROPERTIES PREFIX ""
240                 INSTALL_RPATH ${LIB_DIR}
241                 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/gemrb/plugins)
242         TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
243         INSTALL(TARGETS ${plugin_name} DESTINATION ${PLUGIN_DIR})
244 ENDMACRO(ADD_GEMRB_PLUGIN)
246 #gemrb overrides macro
247 MACRO(ADD_GEMRB_OVERRIDE game_name)
248 FILE( GLOB FILES_TO_INSTALL *.2da *.bmp *.ini *.chu *.ids *.bcs *.vvc *.mos *.spl *.wav *.pro)
249 INSTALL( FILES ${FILES_TO_INSTALL} DESTINATION ${DATA_DIR}/override/${game_name} )
250 ENDMACRO(ADD_GEMRB_OVERRIDE )
252 ADD_SUBDIRECTORY( gemrb )
253 INSTALL( FILES gemrb.6 DESTINATION ${MAN_DIR} )
254 INSTALL( FILES artwork/gemrb-logo.png DESTINATION ${ICON_DIR} )
255 INSTALL( FILES gemrb.desktop DESTINATION ${MENU_DIR} )
257 CONFIGURE_FILE(
258   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
259   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
260   IMMEDIATE @ONLY
263 # copy the variable, since the file uses @VERSION@
264 set(VERSION ${GEMRB_VERSION})
265 CONFIGURE_FILE(
266   "${CMAKE_CURRENT_SOURCE_DIR}/gemrb.spec.in"
267   "${CMAKE_CURRENT_BINARY_DIR}/gemrb.spec"
268   IMMEDIATE @ONLY
271 ADD_CUSTOM_TARGET( uninstall
272   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )
274 # make dist for a gzipped tarball of current HEAD
275 set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GEMRB_VERSION})
276 add_custom_target( dist
277   COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
278     | gzip --best > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz
279   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}