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 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc/gemrb )
87 ENDIF( NOT SYSCONF_DIR )
89 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
92 SET( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
94 else (${LAYOUT} MATCHES "opt")
96 SET( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib )
99 SET( PLUGIN_DIR ${LIB_DIR}/plugins )
100 ENDIF( NOT PLUGIN_DIR )
102 SET( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/ )
103 ENDIF( NOT DATA_DIR )
105 SET( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
108 SET( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
110 IF( NOT SYSCONF_DIR )
111 SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc )
112 ENDIF( NOT SYSCONF_DIR )
114 SET( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
115 ENDIF( NOT ICON_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)
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")
139 # Ensure all plugin symbols exist.
141 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
143 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
145 MESSAGE(STATUS "Looking for Python libraries")
146 INCLUDE(FindPythonLibs)
148 MESSAGE(STATUS "Python Libraries Found")
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")
156 MESSAGE(STATUS "openal found")
158 MESSAGE(ERROR "unable to find openal. please set OPENALDIR environment variable or get it from www.openal.org")
161 MESSAGE(STATUS "Looking for SDL")
164 MESSAGE(STATUS "SDL found")
166 MESSAGE(FATAL_ERROR "unable to find SDL. please get it from www.libsdl.org")
169 MESSAGE( STATUS "Looking for Zlib" )
170 #SET(ZLIB_FIND_REQUIRED TRUE)
173 MESSAGE( STATUS "Looking for libPNG" )
176 MESSAGE( STATUS "libPNG found" )
178 MESSAGE( STATUS "WARNING : GemRB will be built without any PNG support. Get it from www.libpng.org" )
182 MESSAGE(STATUS "Looking for dl library")
183 FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
185 MESSAGE(STATUS "dl library found")
186 ELSE(DLD_LIBRARY_PATH)
187 MESSAGE(FATAL_ERROR "dl library not found")
188 ENDIF(DLD_LIBRARY_PATH)
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)
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)
209 INCLUDE (CheckCXXSourceCompiles)
210 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
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 )
223 SET(HAS_VORBIS_SUPPORT 1)
225 SET(VORBIS_LIBRARY "")
226 ENDIF(VORBIS_LIBRARY)
229 FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
230 FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
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} )
258 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
259 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
263 # copy the variable, since the file uses @VERSION@
264 set(VERSION ${GEMRB_VERSION})
266 "${CMAKE_CURRENT_SOURCE_DIR}/gemrb.spec.in"
267 "${CMAKE_CURRENT_BINARY_DIR}/gemrb.spec"
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}