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.
154 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
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")
209 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} gemrb/includes gemrb/core)
212 INCLUDE (CheckTypeSize)
213 CHECK_TYPE_SIZE("int" SIZEOF_INT)
214 CHECK_TYPE_SIZE("long int" SIZEOF_LONG_INT)
216 INCLUDE (CheckFunctionExists)
217 CHECK_FUNCTION_EXISTS("snprintf" HAVE_SNPRINTF)
218 CHECK_FUNCTION_EXISTS("strndup" HAVE_STRNDUP)
222 INCLUDE (CheckCXXSourceCompiles)
223 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
227 function = (voidvoid) object;
228 " PERMITS_OBJECT_TO_FUNCTION_CAST)
230 IF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
231 SET(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST 1)
232 ENDIF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
236 SET(HAS_VORBIS_SUPPORT 1)
238 SET(VORBIS_LIBRARY "")
239 ENDIF(VORBIS_LIBRARY)
242 FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
243 FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
246 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.h.in
247 ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
249 #Plugin addition macro
250 MACRO(ADD_GEMRB_PLUGIN plugin_name)
251 ADD_LIBRARY(${plugin_name} MODULE ${ARGN})
252 SET_TARGET_PROPERTIES(${plugin_name} PROPERTIES PREFIX ""
253 INSTALL_RPATH ${LIB_DIR}
254 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/gemrb/plugins)
255 TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
256 INSTALL(TARGETS ${plugin_name} DESTINATION ${PLUGIN_DIR})
257 ENDMACRO(ADD_GEMRB_PLUGIN)
259 #gemrb overrides macro
260 MACRO(ADD_GEMRB_OVERRIDE game_name)
261 FILE( GLOB FILES_TO_INSTALL *.2da *.bmp *.ini *.chu *.ids *.bcs *.vvc *.mos *.spl *.wav *.pro)
262 INSTALL( FILES ${FILES_TO_INSTALL} DESTINATION ${DATA_DIR}/override/${game_name} )
263 ENDMACRO(ADD_GEMRB_OVERRIDE )
265 ADD_SUBDIRECTORY( gemrb )
266 INSTALL( FILES gemrb.6 DESTINATION ${MAN_DIR} )
267 INSTALL( FILES artwork/gemrb-logo.png DESTINATION ${ICON_DIR} )
268 INSTALL( FILES gemrb.desktop DESTINATION ${MENU_DIR} )
269 INSTALL( FILES README INSTALL COPYING NEWS AUTHORS DESTINATION ${DOC_DIR} )
272 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
273 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
277 # copy the variable, since the file uses @VERSION@
278 set(VERSION ${GEMRB_VERSION})
280 "${CMAKE_CURRENT_SOURCE_DIR}/gemrb.spec.in"
281 "${CMAKE_CURRENT_BINARY_DIR}/gemrb.spec"
285 ADD_CUSTOM_TARGET( uninstall
286 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )
288 # make dist for a gzipped tarball of current HEAD
289 set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GEMRB_VERSION})
290 add_custom_target( dist
291 COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
292 | gzip --best > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz
293 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
297 message(STATUS "These are the configured paths:")
298 message(STATUS " PREFIX: ${CMAKE_INSTALL_PREFIX}")
299 message(STATUS " LIB_DIR: ${LIB_DIR}")
300 message(STATUS " PLUGIN_DIR: ${PLUGIN_DIR}")
301 message(STATUS " BIN_DIR: ${BIN_DIR}")
302 message(STATUS " DATA_DIR: ${DATA_DIR}")
303 message(STATUS " MAN_DIR: ${MAN_DIR}")
304 message(STATUS " SYSCONF_DIR: ${SYSCONF_DIR}")
305 message(STATUS " DOC_DIR: ${DOC_DIR}")
306 message(STATUS " ICON_DIR: ${ICON_DIR}")
307 message(STATUS " MENU_DIR: ${MENU_DIR}")
309 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")