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( ICON_DIR ${CMAKE_INSTALL_PREFIX} )
67 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX} )
69 elseif (${LAYOUT} MATCHES "fhs")
71 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/gemrb )
74 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
75 ENDIF( NOT PLUGIN_DIR )
77 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/gemrb )
80 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/share/man/man6 )
83 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
86 if ( ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr" )
87 SET( SYSCONF_DIR /etc/gemrb )
89 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc/gemrb )
91 ENDIF( NOT SYSCONF_DIR )
93 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
96 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
98 else (${LAYOUT} MATCHES "opt")
100 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib )
103 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
104 ENDIF( NOT PLUGIN_DIR )
106 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/ )
107 ENDIF( NOT DATA_DIR )
109 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
112 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
114 IF( NOT SYSCONF_DIR )
115 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc )
116 ENDIF( NOT SYSCONF_DIR )
118 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
119 ENDIF( NOT ICON_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)
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")
143 # Ensure all plugin symbols exist.
145 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
147 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
149 MESSAGE(STATUS "Looking for Python libraries")
150 INCLUDE(FindPythonLibs)
152 MESSAGE(STATUS "Python Libraries Found")
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")
160 MESSAGE(STATUS "openal found")
162 MESSAGE(ERROR "unable to find openal. please set OPENALDIR environment variable or get it from www.openal.org")
165 MESSAGE(STATUS "Looking for SDL")
168 MESSAGE(STATUS "SDL found")
170 MESSAGE(FATAL_ERROR "unable to find SDL. please get it from www.libsdl.org")
173 MESSAGE( STATUS "Looking for Zlib" )
174 #SET(ZLIB_FIND_REQUIRED TRUE)
177 MESSAGE( STATUS "Looking for libPNG" )
180 MESSAGE( STATUS "libPNG found" )
182 MESSAGE( STATUS "WARNING : GemRB will be built without any PNG support. Get it from www.libpng.org" )
186 MESSAGE(STATUS "Looking for dl library")
187 FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
189 MESSAGE(STATUS "dl library found")
190 ELSE(DLD_LIBRARY_PATH)
191 MESSAGE(FATAL_ERROR "dl library not found")
192 ENDIF(DLD_LIBRARY_PATH)
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)
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)
213 INCLUDE (CheckCXXSourceCompiles)
214 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
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 )
227 SET(HAS_VORBIS_SUPPORT 1)
229 SET(VORBIS_LIBRARY "")
230 ENDIF(VORBIS_LIBRARY)
233 FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
234 FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
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} )
262 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
263 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
267 # copy the variable, since the file uses @VERSION@
268 set(VERSION ${GEMRB_VERSION})
270 "${CMAKE_CURRENT_SOURCE_DIR}/gemrb.spec.in"
271 "${CMAKE_CURRENT_BINARY_DIR}/gemrb.spec"
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}