renamed Inventory::Copy to Inventory::CopyFrom for clarity
[gemrb.git] / CMakeLists.txt
blob225376f3995a9efc788f86523421f18bd92989c5
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)
6 # allow empty else and endif constructs (available by default since 2.6.0)
7 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
9 # If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition
10 # and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE
11 # to Release prior to calling PROJECT()
12 IF(DEFINED CMAKE_BUILD_TYPE)
13    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.")
14 ELSE(DEFINED CMAKE_BUILD_TYPE)
15    SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
16 ENDIF(DEFINED CMAKE_BUILD_TYPE)
18 PROJECT(gemrb)
19 # try to extract the version from the source
20 execute_process(
21   COMMAND sed -n "s/\#define VERSION_GEMRB .\\([^\"]*\\).$/\\1/p" ${CMAKE_CURRENT_SOURCE_DIR}/gemrb/includes/globals.h
22   OUTPUT_VARIABLE GEMRB_VERSION
23   RESULT_VARIABLE RC
24   OUTPUT_STRIP_TRAILING_WHITESPACE
26 if(${RC} GREATER 0) # lookup failed
27   set(GEMRB_VERSION "unknown")
28 endif(${RC} GREATER 0)
29 message("Detected version: ${GEMRB_VERSION}")
31 IF(PREFIX)
32   SET(PREFIX CACHE PATH "Abbreviation for CMAKE_INSTALL_PREFIX.")
33   SET(CMAKE_INSTALL_PREFIX ${PREFIX})
34 ENDIF(PREFIX)
36 if (NOT LAYOUT)
37         if (WIN32)
38                 set(LAYOUT "home")
39         else (WIN32)
40                 set(LAYOUT "fhs")
41         endif (WIN32)
42 endif (NOT LAYOUT)
44 SET(LAYOUT "${LAYOUT}" CACHE STRING "Directory layout.")
46 # macro that sets a default (path) if one wasn't specified
47 MACRO(SET_PATH variable default)
48         IF(NOT ${variable})
49                 SET(${variable} ${default})
50         ENDIF(NOT ${variable})
51 ENDMACRO(SET_PATH)
53 if (${LAYOUT} MATCHES "home")
54         SET_PATH( PLUGIN_DIR ${CMAKE_INSTALL_PREFIX}/plugins )
55         SET_PATH( DATA_DIR ${CMAKE_INSTALL_PREFIX} )
56         SET_PATH( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
57         SET_PATH( BIN_DIR ${CMAKE_INSTALL_PREFIX} )
58         SET_PATH( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX} )
59         SET_PATH( LIB_DIR ${CMAKE_INSTALL_PREFIX} )
60         SET_PATH( DOC_DIR ${CMAKE_INSTALL_PREFIX}/doc )
61         SET_PATH( ICON_DIR ${CMAKE_INSTALL_PREFIX} )
62         SET_PATH( SVG_DIR ${CMAKE_INSTALL_PREFIX} )
63         SET_PATH( MENU_DIR ${CMAKE_INSTALL_PREFIX} )
64 elseif (${LAYOUT} MATCHES "fhs")
65         SET_PATH( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/gemrb )
66         SET_PATH( PLUGIN_DIR ${LIB_DIR}/plugins )
67         SET_PATH( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/gemrb )
68         SET_PATH( MAN_DIR ${CMAKE_INSTALL_PREFIX}/share/man/man6 )
69         SET_PATH( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
70         IF( NOT SYSCONF_DIR )
71                 if ( ${CMAKE_INSTALL_PREFIX} STREQUAL "/usr" )
72                         SET( SYSCONF_DIR /etc/gemrb )
73                 else ()
74                         SET( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc/gemrb )
75                 endif ()
76         ENDIF( NOT SYSCONF_DIR )
77         SET_PATH( DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/gemrb )
78         SET_PATH( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
79         SET_PATH( SVG_DIR ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps )
80         SET_PATH( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
81 else (${LAYOUT} MATCHES "opt")
82         SET_PATH( LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib )
83         SET_PATH( PLUGIN_DIR ${LIB_DIR}/plugins )
84         SET_PATH( DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/ )
85         SET_PATH( MAN_DIR ${CMAKE_INSTALL_PREFIX}/man/man6 )
86         SET_PATH( BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin )
87         SET_PATH( SYSCONF_DIR ${CMAKE_INSTALL_PREFIX}/etc )
88         SET_PATH( DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/gemrb )
89         SET_PATH( ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/pixmaps )
90         SET_PATH( SVG_DIR ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps )
91         SET_PATH( MENU_DIR ${CMAKE_INSTALL_PREFIX}/share/applications )
92 endif (${LAYOUT} MATCHES "home")
95 IF(CMAKE_COMPILER_IS_GNUCXX)
96         if ( NOT DISABLE_WERROR )
97                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
98         endif ( NOT DISABLE_WERROR )
99         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wpointer-arith -Wcast-align")
100         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-format-y2k -Wno-long-long -fno-strict-aliasing")
101         # only export symbols explicitly marked to be exported.
102         INCLUDE(CheckCXXCompilerFlag)
103         CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" VISIBILITY_HIDDEN)
104         IF (VISIBILITY_HIDDEN)
105                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
106         ENDIF (VISIBILITY_HIDDEN)
107         if (WIN32)
108                 # GCC 4.5.0+ has shared libstdc++ without dllimport
109                 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-auto-import")
110                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-auto-import")
111         endif (WIN32)
112         # Ensure all plugin symbols exist.
113         if (NOT APPLE AND NOT UNSAFE_PLUGIN)
114                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined")
115         endif (NOT APPLE AND NOT UNSAFE_PLUGIN)
116 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
118 # Check for all the required and optional dependencies
119 INCLUDE(FindPythonLibs)
120 IF(PYTHON_LIBRARY)
121         MESSAGE(STATUS "Looking for Python libraries: found")
122 ELSE()
123         MESSAGE(SEND_ERROR "Looking for Python libraries: not found!")
124         MESSAGE(FATAL_ERROR "Please get the development libraries from www.python.org")
125 ENDIF()
127 INCLUDE(FindSDL)
128 IF(SDL_FOUND)
129         MESSAGE(STATUS "Looking for SDL: found")
130 ELSE()
131         MESSAGE(SEND_ERROR "Looking for SDL: not found!")
132         MESSAGE(FATAL_ERROR "Please get it from www.libsdl.org")
133 ENDIF()
135 INCLUDE(FindZLIB)
136 IF(ZLIB_FOUND)
137         MESSAGE(STATUS "Looking for Zlib: found")
138 ELSE()
139         MESSAGE(SEND_ERROR "Looking for Zlib: not found!")
140         MESSAGE(FATAL_ERROR "Please install the Zlib library and headers first!")
141 ENDIF()
143 IF(UNIX)
144         FIND_LIBRARY(DLD_LIBRARY_PATH dl dld)
145         IF(DLD_LIBRARY_PATH)
146                 MESSAGE(STATUS "Looking for dl library: found")
147         ELSE(DLD_LIBRARY_PATH)
148                 MESSAGE(FATAL_ERROR "Looking for dl library: not found!")
149         ENDIF(DLD_LIBRARY_PATH)
151         SET(CMAKE_THREAD_PREFER_PTHREAD true)
152         FIND_PACKAGE(Threads REQUIRED)
153 ENDIF(UNIX)
155 INCLUDE(FindOpenAL)
156 IF(OPENAL_FOUND)
157         MESSAGE(STATUS "Looking for OpenAL: found")
158 ELSE()
159         MESSAGE(WARNING "Looking for OpenAL: not found!")
160         MESSAGE(WARNING "If you want to build the OpenAL plugin, get OpenAL from www.openal.org.")
161         MESSAGE(WARNING "If it just wasn't found, try setting the OPENALDIR environment variable.")
162 ENDIF()
164 INCLUDE(FindSDL_mixer)
165 IF(SDLMIXER_FOUND)
166         MESSAGE(STATUS "Looking for SDL_mixer: found")
167 ELSE()
168         MESSAGE(WARNING "Looking for SDL_mixer: not found!")
169         MESSAGE(WARNING "If you want to build the SDL_mixer plugin, install SDL_mixer first.")
170 ENDIF()
172 INCLUDE(FindPNG)
173 IF(PNG_FOUND)
174         MESSAGE(STATUS "Looking for libPNG: found")
175 ELSE()
176         MESSAGE(WARNING "Looking for libPNG: not found!")
177         MESSAGE(WARNING "GemRB will be built without any PNG support. Get it from www.libpng.org" )
178         MESSAGE(WARNING "While no original game data is in PNG format, some mod data is and will need conversion.")
179 ENDIF()
181 FIND_LIBRARY(VORBIS_LIBRARY vorbisfile)
182 find_path(VORBIS_FILE vorbisfile.h PATH_SUFFIXES vorbis)
183 IF(VORBIS_LIBRARY AND VORBIS_FILE)
184         MESSAGE(STATUS "Looking for Ogg Vorbis support: found")
185 ELSE()
186         unset(VORBIS_LIBRARY) # disable the build for this plugin
187         MESSAGE(WARNING "Looking for Ogg Vorbis support: not found!")
188         MESSAGE(WARNING "While no original game data is in OGG format, some mod data is and will need conversion.")
189 ENDIF()
191 ADD_DEFINITIONS("-DHAVE_CONFIG_H")
193 # On Release builds cmake automatically defines NDEBUG, so we
194 # explicitly undefine it:
195 if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT MSVC)
196         ADD_DEFINITIONS("-UNDEBUG")
197 endif()
199 if (STATIC_LINK)
200         if (NOT WIN32 AND NOT APPLE)
201                 ADD_DEFINITIONS("-DSTATIC_LINK")
202         else (NOT WIN32 AND NOT APPLE)
203                 unset(STATIC_LINK CACHE)
204                 MESSAGE(STATUS "Static linking not (yet) supported on this platform.")
205         endif (NOT WIN32 AND NOT APPLE)
206 endif (STATIC_LINK)
208 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} gemrb/includes gemrb/core)
210 #Platform checks
211 INCLUDE (CheckTypeSize)
212 CHECK_TYPE_SIZE("int" SIZEOF_INT)
213 CHECK_TYPE_SIZE("long int" SIZEOF_LONG_INT)
215 INCLUDE (CheckFunctionExists)
216 CHECK_FUNCTION_EXISTS("snprintf" HAVE_SNPRINTF)
217 CHECK_FUNCTION_EXISTS("strndup" HAVE_STRNDUP)
219 #Unneeded on windows
220 IF(NOT WIN32)
221         INCLUDE (CheckCXXSourceCompiles)
222         CHECK_CXX_SOURCE_COMPILES("typedef void *(* voidvoid)(void);
224                 void *object = 0;
225                 voidvoid function;
226                 function = (voidvoid) object;
227                 " PERMITS_OBJECT_TO_FUNCTION_CAST)
229         IF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
230                 SET(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST 1)
231         ENDIF( NOT PERMITS_OBJECT_TO_FUNCTION_CAST )
232 ENDIF(NOT WIN32)
234 IF(APPLE)
235  FIND_LIBRARY(SDL_MAIN_LIBRARY_PATH SDLmain)
236  FIND_LIBRARY(COCOA_LIBRARY_PATH Cocoa)
237 ENDIF(APPLE)
239 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_config.h.in
240         ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
242 #Plugin addition macro
243 MACRO(ADD_GEMRB_PLUGIN plugin_name)
244         if (STATIC_LINK)
245                 ADD_LIBRARY(${plugin_name} STATIC ${ARGN})
246                 set(plugins "${plugins};${plugin_name}" PARENT_SCOPE)
247         else (STATIC_LINK)
248                 ADD_LIBRARY(${plugin_name} MODULE ${ARGN})
249                 if (NOT UNSAFE_PLUGIN)
250                         TARGET_LINK_LIBRARIES(${plugin_name} gemrb_core ${CMAKE_THREAD_LIBS_INIT})
251                 endif (NOT UNSAFE_PLUGIN)
252                 INSTALL(TARGETS ${plugin_name} DESTINATION ${PLUGIN_DIR})
253         endif (STATIC_LINK)
254         SET_TARGET_PROPERTIES(${plugin_name} PROPERTIES PREFIX ""
255                 INSTALL_RPATH ${LIB_DIR}
256                 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/gemrb/plugins)
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} RENAME gemrb.png )
268 INSTALL( FILES artwork/logo04-rb_only.svg DESTINATION ${SVG_DIR} RENAME gemrb.svg )
269 INSTALL( FILES gemrb.desktop DESTINATION ${MENU_DIR} )
270 INSTALL( FILES README INSTALL COPYING NEWS AUTHORS DESTINATION ${DOC_DIR} )
272 CONFIGURE_FILE(
273   "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
274   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
275   IMMEDIATE @ONLY
278 # copy the variable, since the file uses @VERSION@
279 set(VERSION ${GEMRB_VERSION})
280 CONFIGURE_FILE(
281   "${CMAKE_CURRENT_SOURCE_DIR}/gemrb.spec.in"
282   "${CMAKE_CURRENT_BINARY_DIR}/gemrb.spec"
283   IMMEDIATE @ONLY
286 ADD_CUSTOM_TARGET( uninstall
287   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" )
289 # make dist for a gzipped tarball of current HEAD
290 set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${GEMRB_VERSION})
291 add_custom_target( dist
292   COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
293     | gzip --best > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz
294   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
297 message(STATUS "")
298 message(STATUS "These are the configured paths:")
299 message(STATUS "  PREFIX: ${CMAKE_INSTALL_PREFIX}")
300 message(STATUS "  LIB_DIR: ${LIB_DIR}")
301 message(STATUS "  PLUGIN_DIR: ${PLUGIN_DIR}")
302 message(STATUS "  BIN_DIR: ${BIN_DIR}")
303 message(STATUS "  DATA_DIR: ${DATA_DIR}")
304 message(STATUS "  MAN_DIR: ${MAN_DIR}")
305 message(STATUS "  SYSCONF_DIR: ${SYSCONF_DIR}")
306 message(STATUS "  DOC_DIR: ${DOC_DIR}")
307 message(STATUS "  ICON_DIR: ${ICON_DIR}")
308 message(STATUS "  SVG_DIR: ${SVG_DIR}")
309 message(STATUS "  MENU_DIR: ${MENU_DIR}")
310 message(STATUS "")
311 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
312 message(STATUS "")