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 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -W -Wpointer-arith -Wcast-align")
124 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-format-y2k -Wno-long-long -fno-strict-aliasing")
125 # only export symbols explicitly marked to be exported.
126 INCLUDE(CheckCXXCompilerFlag)
127 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" VISIBILITY_HIDDEN)
128 IF (VISIBILITY_HIDDEN)
129 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
130 ENDIF (VISIBILITY_HIDDEN)
131 # Ensure all plugin symbols exist.
133 set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined")
135 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
137 MESSAGE(STATUS "Looking for Python libraries")
138 INCLUDE(FindPythonLibs)
140 MESSAGE(STATUS "Python Libraries Found")
142 MESSAGE(FATAL_ERROR "Unable to find Python development libraries. Please get it from www.python.org")
143 ENDIF(PYTHON_LIBRARY)
145 MESSAGE(STATUS "Looking for openAL libraries")
148 MESSAGE(STATUS "openal found")
150 MESSAGE(ERROR "unable to find openal. please set OPENALDIR environment variable or get it from www.openal.org")
153 MESSAGE(STATUS "Looking for SDL")
156 MESSAGE(STATUS "SDL found")
158 MESSAGE(FATAL_ERROR "unable to find SDL. please get it from www.libsdl.org")
161 MESSAGE( STATUS "Looking for Zlib" )
162 #SET(ZLIB_FIND_REQUIRED TRUE)
165 MESSAGE( STATUS "Looking for libPNG" )
168 MESSAGE( STATUS "libPNG found" )
170 MESSAGE( STATUS "WARNING : GemRB will be built without any PNG support. Get it from www.libpng.org" )
174 MESSAGE(STATUS "Looking for dl library")
175 FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
177 MESSAGE(STATUS "dl library found")
178 ELSE(DLD_LIBRARY_PATH)
179 MESSAGE(FATAL_ERROR "dl library not found")
180 ENDIF(DLD_LIBRARY_PATH)
183 MESSAGE(STATUS "Looking for Ogg Vorbis support")
184 FIND_LIBRARY(VORBIS_LIBRARY vorbisfile)
186 ADD_DEFINITIONS("-DHAVE_CONFIG_H")
188 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} gemrb/includes gemrb/core)
191 INCLUDE (CheckTypeSize)
192 CHECK_TYPE_SIZE("int" SIZEOF_INT)
193 CHECK_TYPE_SIZE("long int" SIZEOF_LONG_INT)
195 INCLUDE (CheckFunctionExists)
196 CHECK_FUNCTION_EXISTS("snprintf" HAVE_SNPRINTF)
197 CHECK_FUNCTION_EXISTS("strndup" HAVE_STRNDUP)
201 INCLUDE (CheckCXXSourceCompiles)
202 CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
206 function = (voidvoid) object;
207 " PERMITS_OBJECT_TO_FUNCTION_CAST)
209 IF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
210 SET(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST 1)
211 ENDIF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
215 SET(HAS_VORBIS_SUPPORT 1)
217 SET(VORBIS_LIBRARY "")
218 ENDIF(VORBIS_LIBRARY)
221 FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
222 FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
225 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
227 #Plugin addition macro
228 MACRO(ADD_GEMRB_PLUGIN plugin_name)
229 ADD_LIBRARY(${plugin_name} MODULE ${ARGN})
230 SET_TARGET_PROPERTIES(${plugin_name} PROPERTIES PREFIX ""
231 INSTALL_RPATH ${LIB_DIR}
232 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/gemrb/plugins)
233 TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core)
234 INSTALL(TARGETS ${plugin_name} DESTINATION ${PLUGIN_DIR})
235 ENDMACRO(ADD_GEMRB_PLUGIN)
237 #gemrb overrides macro
238 MACRO(ADD_GEMRB_OVERRIDE game_name)
239 FILE( GLOB FILES_TO_INSTALL *.2da *.bmp *.ini *.chu *.ids *.bcs *.vvc *.mos *.spl *.wav *.pro)
240 INSTALL( FILES ${FILES_TO_INSTALL} DESTINATION ${DATA_DIR}/override/${game_name} )
241 ENDMACRO(ADD_GEMRB_OVERRIDE )
243 ADD_SUBDIRECTORY( gemrb )
244 INSTALL( FILES gemrb.6 DESTINATION ${MAN_DIR} )
245 INSTALL( FILES gemrb-logo.png DESTINATION ${ICON_DIR} )
246 INSTALL( FILES gemrb.desktop DESTINATION ${MENU_DIR} )
249 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
250 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
254 # copy the variable, since the file uses @VERSION@
255 set(VERSION ${GEMRB_VERSION})
257 "${CMAKE_CURRENT_SOURCE_DIR}/gemrb.spec.in"
258 "${CMAKE_CURRENT_BINARY_DIR}/gemrb.spec"
262 ADD_CUSTOM_TARGET( uninstall
263 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )
265 # make dist for a gzipped tarball of current HEAD
266 set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GEMRB_VERSION})
267 add_custom_target( dist
268 COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
269 | gzip --best > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz
270 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}