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)
17 # try to extract the version from the source
19 COMMAND sed -n "s/\#define VERSION_GEMRB .\\([^\"]*\\).$/\\1/p" ${CMAKE_CURRENT_SOURCE_DIR}/gemrb/includes/globals.h
20 OUTPUT_VARIABLE GEMRB_VERSION
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}")
30 SET(PREFIX CACHE PATH "Abbreviation for CMAKE_INSTALL_PREFIX.")
31 SET(CMAKE_INSTALL_PREFIX ${PREFIX})
42 SET(LAYOUT "${LAYOUT}" CACHE STRING "Directory layout.")
44 if (${LAYOUT} MATCHES "home")
46 SET( PLUGIN_DIR ${CMAKE_INSTALL_PREFIX}/plugins )
47 ENDIF( NOT PLUGIN_DIR )
49 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX} )
52 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
55 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX} )
58 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX} )
59 ENDIF( NOT SYSCONF_DIR )
61 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX} )
64 SET( DOC_DIR ${CMAKE_INSTALL_PREFIX}/doc )
67 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX} )
70 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX} )
72 elseif (${LAYOUT} MATCHES "fhs")
74 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/gemrb )
77 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
78 ENDIF( NOT PLUGIN_DIR )
80 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/gemrb )
83 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/share/man/man6 )
86 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
89 if ( ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr" )
90 SET( SYSCONF_DIR /etc/gemrb )
92 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc/gemrb )
94 ENDIF( NOT SYSCONF_DIR )
96 SET( DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/gemrb )
99 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
100 ENDIF( NOT ICON_DIR )
102 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
103 ENDIF( NOT MENU_DIR )
104 else (${LAYOUT} MATCHES "opt")
106 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib )
109 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
110 ENDIF( NOT PLUGIN_DIR )
112 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/ )
113 ENDIF( NOT DATA_DIR )
115 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
118 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
120 IF( NOT SYSCONF_DIR )
121 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc )
122 ENDIF( NOT SYSCONF_DIR )
124 SET( DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/gemrb )
127 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
128 ENDIF( NOT ICON_DIR )
130 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
131 ENDIF( NOT MENU_DIR )
132 endif (${LAYOUT} MATCHES "home")
135 IF(CMAKE_COMPILER_IS_GNUCXX)
136 if ( NOT DISABLE_WERROR )
137 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
138 endif ( NOT DISABLE_WERROR )
139 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wpointer-arith -Wcast-align")
140 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-format-y2k -Wno-long-long -fno-strict-aliasing")
141 # only export symbols explicitly marked to be exported.
142 INCLUDE(CheckCXXCompilerFlag)
143 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" VISIBILITY_HIDDEN)
144 IF (VISIBILITY_HIDDEN)
145 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
146 ENDIF (VISIBILITY_HIDDEN)
148 # GCC 4.5.0+ has shared libstdc++ without dllimport
149 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-auto-import")
150 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-auto-import")
152 # Ensure all plugin symbols exist.
153 if (NOT APPLE AND NOT UNSAFE_PLUGIN)
154 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
155 endif (NOT APPLE AND NOT UNSAFE_PLUGIN)
156 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
158 MESSAGE(STATUS "Looking for Python libraries")
159 INCLUDE(FindPythonLibs)
161 MESSAGE(STATUS "Python Libraries Found")
163 MESSAGE(FATAL_ERROR "Unable to find Python development libraries. Please get it from www.python.org")
164 ENDIF(PYTHON_LIBRARY)
166 MESSAGE(STATUS "Looking for openAL libraries")
169 MESSAGE(STATUS "openal found")
171 MESSAGE(ERROR "unable to find openal. please set OPENALDIR environment variable or get it from www.openal.org")
174 MESSAGE(STATUS "Looking for SDL")
177 MESSAGE(STATUS "SDL found")
179 MESSAGE(FATAL_ERROR "unable to find SDL. please get it from www.libsdl.org")
182 MESSAGE( STATUS "Looking for Zlib" )
183 #SET(ZLIB_FIND_REQUIRED TRUE)
186 MESSAGE( STATUS "Looking for libPNG" )
189 MESSAGE( STATUS "libPNG found" )
191 MESSAGE( STATUS "WARNING : GemRB will be built without any PNG support. Get it from www.libpng.org" )
195 MESSAGE(STATUS "Looking for dl library")
196 FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
198 MESSAGE(STATUS "dl library found")
199 ELSE(DLD_LIBRARY_PATH)
200 MESSAGE(FATAL_ERROR "dl library not found")
201 ENDIF(DLD_LIBRARY_PATH)
204 MESSAGE(STATUS "Looking for Ogg Vorbis support")
205 FIND_LIBRARY(VORBIS_LIBRARY vorbisfile)
207 ADD_DEFINITIONS("-DHAVE_CONFIG_H")
210 if (NOT WIN32 AND NOT APPLE)
211 ADD_DEFINITIONS("-DSTATIC_LINK")
212 else (NOT WIN32 AND NOT APPLE)
214 endif (NOT WIN32 AND NOT APPLE)
217 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} gemrb/includes gemrb/core)
220 INCLUDE (CheckTypeSize)
221 CHECK_TYPE_SIZE("int" SIZEOF_INT)
222 CHECK_TYPE_SIZE("long int" SIZEOF_LONG_INT)
224 INCLUDE (CheckFunctionExists)
225 CHECK_FUNCTION_EXISTS("snprintf" HAVE_SNPRINTF)
226 CHECK_FUNCTION_EXISTS("strndup" HAVE_STRNDUP)
230 INCLUDE (CheckCXXSourceCompiles)
231 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
235 function = (voidvoid) object;
236 " PERMITS_OBJECT_TO_FUNCTION_CAST)
238 IF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
239 SET(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST 1)
240 ENDIF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
244 SET(HAS_VORBIS_SUPPORT 1)
246 SET(VORBIS_LIBRARY "")
247 ENDIF(VORBIS_LIBRARY)
250 FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
251 FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
254 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.h.in
255 ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
257 #Plugin addition macro
258 MACRO(ADD_GEMRB_PLUGIN plugin_name)
260 ADD_LIBRARY(${plugin_name} STATIC ${ARGN})
261 set(plugins "${plugins};${plugin_name}" PARENT_SCOPE)
263 ADD_LIBRARY(${plugin_name} MODULE ${ARGN})
264 if (NOT UNSAFE_PLUGIN)
265 TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
266 endif (NOT UNSAFE_PLUGIN)
267 INSTALL(TARGETS ${plugin_name} DESTINATION ${PLUGIN_DIR})
269 SET_TARGET_PROPERTIES(${plugin_name} PROPERTIES PREFIX ""
270 INSTALL_RPATH ${LIB_DIR}
271 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/gemrb/plugins)
272 ENDMACRO(ADD_GEMRB_PLUGIN)
274 #gemrb overrides macro
275 MACRO(ADD_GEMRB_OVERRIDE game_name)
276 FILE( GLOB FILES_TO_INSTALL *.2da *.bmp *.ini *.chu *.ids *.bcs *.vvc *.mos *.spl *.wav *.pro)
277 INSTALL( FILES ${FILES_TO_INSTALL} DESTINATION ${DATA_DIR}/override/${game_name} )
278 ENDMACRO(ADD_GEMRB_OVERRIDE )
280 ADD_SUBDIRECTORY( gemrb )
281 INSTALL( FILES gemrb.6 DESTINATION ${MAN_DIR} )
282 INSTALL( FILES artwork/gemrb-logo.png DESTINATION ${ICON_DIR} )
283 INSTALL( FILES gemrb.desktop DESTINATION ${MENU_DIR} )
284 INSTALL( FILES README INSTALL COPYING NEWS AUTHORS DESTINATION ${DOC_DIR} )
287 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
288 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
292 # copy the variable, since the file uses @VERSION@
293 set(VERSION ${GEMRB_VERSION})
295 "${CMAKE_CURRENT_SOURCE_DIR}/gemrb.spec.in"
296 "${CMAKE_CURRENT_BINARY_DIR}/gemrb.spec"
300 ADD_CUSTOM_TARGET( uninstall
301 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )
303 # make dist for a gzipped tarball of current HEAD
304 set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GEMRB_VERSION})
305 add_custom_target( dist
306 COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
307 | gzip --best > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz
308 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
312 message(STATUS "These are the configured paths:")
313 message(STATUS " PREFIX: ${CMAKE_INSTALL_PREFIX}")
314 message(STATUS " LIB_DIR: ${LIB_DIR}")
315 message(STATUS " PLUGIN_DIR: ${PLUGIN_DIR}")
316 message(STATUS " BIN_DIR: ${BIN_DIR}")
317 message(STATUS " DATA_DIR: ${DATA_DIR}")
318 message(STATUS " MAN_DIR: ${MAN_DIR}")
319 message(STATUS " SYSCONF_DIR: ${SYSCONF_DIR}")
320 message(STATUS " DOC_DIR: ${DOC_DIR}")
321 message(STATUS " ICON_DIR: ${ICON_DIR}")
322 message(STATUS " MENU_DIR: ${MENU_DIR}")
324 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")