1 project(hedgewars) |
1 project(hedgewars) |
2 |
2 |
3 |
3 |
4 #initialise cmake environment |
4 #initialise cmake environment |
5 cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR) |
5 cmake_minimum_required(VERSION 2.6.4) |
6 FOREACH(policy CMP0003 CMP0012) |
6 foreach(hwpolicy CMP0003 CMP0012 CMP0017 CMP0018) |
7 IF(POLICY ${policy}) |
7 if(POLICY ${hwpolicy}) |
8 CMAKE_POLICY(SET ${policy} NEW) |
8 cmake_policy(SET ${hwpolicy} NEW) |
9 ENDIF() |
9 endif() |
10 ENDFOREACH() |
10 endforeach() |
11 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules) |
11 |
12 |
12 foreach(hwpolicy CMP0026 CMP0068) |
13 |
13 if(POLICY ${hwpolicy}) |
14 #detect Mercurial revision (if present) |
14 cmake_policy(SET ${hwpolicy} OLD) |
15 set(version_suffix "-dev") #UNSET THIS VARIABLE AT RELEASE TIME |
15 endif() |
16 set(HGCHANGED "") |
16 endforeach() |
17 IF(version_suffix MATCHES "-dev") |
17 |
18 set(HW_DEV true) |
18 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules") |
19 set(default_build_type "DEBUG") |
19 include(${CMAKE_MODULE_PATH}/utils.cmake) |
20 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.hg) |
20 |
21 FIND_PROGRAM(HGCOMMAND hg) |
21 #possible cmake configuration |
22 IF(HGCOMMAND) |
22 option(NOSERVER "Disable gameServer build (off)" OFF) |
23 exec_program(${HGCOMMAND} |
23 if(NOT WIN32) |
24 ARGS identify -in ${CMAKE_CURRENT_SOURCE_DIR} |
24 option(NOPNG "Disable screenshoot compression (off)" OFF) |
25 OUTPUT_VARIABLE version_suffix |
25 endif() |
26 ) |
26 option(NOVIDEOREC "Disable video recording (off)" OFF) |
27 STRING(REGEX REPLACE "[^+]" "" HGCHANGED ${version_suffix}) |
27 |
28 STRING(REGEX REPLACE "([0-9a-zA-Z]+)(.*) ([0-9]+)(.*)" "\\3-\\1" version_suffix ${version_suffix}) |
28 #libraries are built shared unless explicitly added as a static |
29 IF (HGCHANGED) |
29 option(BUILD_SHARED_LIBS "Build libraries as shared modules (on)" ON) |
30 MESSAGE(STATUS "Building revision ${version_suffix} (SOURCE CODE MODIFIED)") |
30 |
31 ELSE() |
31 if(WIN32 OR APPLE) |
32 MESSAGE(STATUS "Building revision ${version_suffix}") |
32 option(LUA_SYSTEM "Use system Lua (off)" OFF) |
33 ENDIF() |
33 else() |
34 set(version_suffix "-${version_suffix}") |
34 option(LUA_SYSTEM "Use system Lua (on)" ON) |
35 ENDIF() |
35 endif() |
36 ENDIF() |
36 |
37 ELSE() |
37 option(BUILD_ENGINE_LIBRARY "Enable hwengine library (off)" OFF) |
38 set(HW_DEV false) |
38 option(ANDROID "Enable Android build (off)" OFF) |
39 set(default_build_type "RELEASE") |
39 |
40 ENDIF() |
40 option(MINIMAL_FLAGS "Respect system flags as much as possible (off)" OFF) |
41 |
41 option(NOAUTOUPDATE "Disable OS X Sparkle update checking (off)" OFF) |
|
42 option(SKIPBUNDLE "Do not create relocate bundle (off)" OFF) |
|
43 |
|
44 option(BUILD_ENGINE_C "Compile hwengine as native C (off)" OFF) |
|
45 option(BUILD_ENGINE_JS "Compile hwengine as JavaScript (off)" OFF) |
|
46 option(GL2 "Enable OpenGL 2 rendering, only use if you know what you're doing (off)" OFF) |
|
47 |
|
48 set(GHFLAGS "" CACHE STRING "Additional Haskell flags") |
|
49 if(UNIX AND NOT APPLE) |
|
50 set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path") |
|
51 endif() |
|
52 |
|
53 option(NOVERSIONINFOUPDATE "Disable update of version_info.txt. To be used if source is in a git/repo that is NOT the hedgewars repo" OFF) |
|
54 |
|
55 |
|
56 if(BUILD_ENGINE_C AND NOT NOVIDEOREC) |
|
57 if((CMAKE_BUILD_TYPE STREQUAL "Release") OR (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) |
|
58 message("NOTE: Video recorder support disabled. It's incompatible with BUILD_ENGINE_C") |
|
59 set(BUILD_ENGINE_C ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
60 else() |
|
61 message("WARNING: Video recorder support is currently incompatible with BUILD_ENGINE_C, the video recorder won't work (but demos are fine)! See <https://issues.hedgewars.org/show_bug.cgi?id=722>.") |
|
62 endif() |
|
63 endif() |
|
64 if(BUILD_ENGINE_JS) |
|
65 if(NOT CMAKE_TOOLCHAIN_FILE) |
|
66 message(FATAL_ERROR "Missing emscripten toolchain file\nClean your cache and rerun cmake with -DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/cmake_modules/Platform/Emscripten.cmake") |
|
67 endif() |
|
68 |
|
69 set(BUILD_ENGINE_C ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
70 set(BUILD_ENGINE_LIBRARY ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
71 set(NOAUTOUPDATE ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
72 set(LUA_SYSTEM OFF CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
73 set(NOVIDEOREC ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
74 set(NOSERVER ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
75 set(GL2 ON CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
76 set(BUILD_SHARED_LIBS OFF CACHE STRING "Required for BUILD_ENGINE_JS" FORCE) |
|
77 |
|
78 set(target_binary_install_dir "bin" CACHE PATH "install dest for binaries") |
|
79 set(target_library_install_dir "lib" CACHE PATH "install dest for libs") |
|
80 endif() |
|
81 |
|
82 if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4" AND UNIX AND NOT APPLE) |
|
83 set(BUILD_ENGINE_C ON CACHE STRING "PAS2C force-enabled due to a freepascal 32 bit alignment bug" FORCE) |
|
84 endif() |
|
85 |
|
86 #system paths for finding required fonts (see share/hedgewars/Data/fonts) |
|
87 #subdirectories will NOT be searched. |
|
88 #all fonts that can't be found will be bundled with hedgewars |
|
89 set(FONTS_DIRS "" CACHE STRING "Additional paths to folders where required fonts can be found ( ; is separator)") |
42 |
90 |
43 #versioning |
91 #versioning |
44 set(CPACK_PACKAGE_VERSION_MAJOR 0) |
92 set(CPACK_PACKAGE_VERSION_MAJOR 1) |
45 set(CPACK_PACKAGE_VERSION_MINOR 9) |
93 set(CPACK_PACKAGE_VERSION_MINOR 0) |
46 set(CPACK_PACKAGE_VERSION_PATCH 18${version_suffix}) |
94 set(CPACK_PACKAGE_VERSION_PATCH 0) |
47 set(HEDGEWARS_PROTO_VER 42) |
95 set(HEDGEWARS_PROTO_VER 59) |
48 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") |
96 if((CMAKE_BUILD_TYPE STREQUAL "Release") OR (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) |
49 |
97 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") |
50 |
98 else() |
51 #set some default values |
99 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-dev") |
52 option(NOSERVER "Disable gameServer build [default: auto]" OFF) |
100 endif() |
53 option(NOPNG "Disable screenshoot compression [default: auto]" OFF) |
101 include(${CMAKE_MODULE_PATH}/revinfo.cmake) |
54 option(NOVIDEOREC "Disable video recording [default: auto]" OFF) |
102 |
55 |
103 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})") |
56 option(BUILD_ENGINE_LIBRARY "Enable hwengine library [default: off]" OFF) |
104 |
57 option(ANDROID "Enable Android build [default: off]" OFF) |
105 #io library paths |
58 option(CROSSAPPLE "Enable OSX when not on OSX [default: off]" OFF) |
106 include(${CMAKE_MODULE_PATH}/paths.cmake) |
59 |
107 #general utilities |
60 |
108 include(${CMAKE_MODULE_PATH}/utils.cmake) |
61 #bundle .app setup |
109 #platform specific init code |
62 if(APPLE OR CROSSAPPLE) |
110 include(${CMAKE_MODULE_PATH}/platform.cmake) |
63 #paths for creating the bundle |
|
64 set(bundle_name Hedgewars.app) |
|
65 set(frameworks_dir ${bundle_name}/Contents/Frameworks/) |
|
66 set(CMAKE_INSTALL_PREFIX ${bundle_name}/Contents/MacOS/) |
|
67 set(DATA_INSTALL_DIR "../Resources/") |
|
68 set(target_dir ".") |
|
69 set(minimum_macosx_version "10.6") |
|
70 else() |
|
71 set(target_dir "bin") |
|
72 endif() |
|
73 |
|
74 if(APPLE) |
|
75 set(CMAKE_FIND_FRAMEWORK "FIRST") |
|
76 |
|
77 #what system are we building for |
|
78 set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET}) |
|
79 |
|
80 #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version |
|
81 find_program(sw_vers sw_vers) |
|
82 if(sw_vers) |
|
83 exec_program(${sw_vers} ARGS "-productVersion" OUTPUT_VARIABLE current_macosx_version) |
|
84 string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version}) |
|
85 else() |
|
86 if(NOT minimum_macosx_version) |
|
87 message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set") |
|
88 else() |
|
89 set(current_macosx_version ${minimum_macosx_version}) |
|
90 endif() |
|
91 endif() |
|
92 |
|
93 #if nothing is set, we deploy only for the current system |
|
94 if(NOT minimum_macosx_version) |
|
95 set(minimum_macosx_version ${current_macosx_version}) |
|
96 endif() |
|
97 |
|
98 #lower systems don't have enough processing power anyways |
|
99 if (minimum_macosx_version LESS "10.4") |
|
100 message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4") |
|
101 endif() |
|
102 |
|
103 #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2) |
|
104 if(current_macosx_version MATCHES "10.4") |
|
105 find_package(SDL_mixer REQUIRED) |
|
106 set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg") |
|
107 set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod") |
|
108 set(pascal_flags "-k${DYLIB_SMPEG}" "-k${DYLIB_MIKMOD}" ${pascal_flags}) |
|
109 set(CMAKE_C_FLAGS "${DYLIB_SMPEG}" "${DYLIB_MIKMOD}" ${CMAKE_C_FLAGS}) |
|
110 endif() |
|
111 |
|
112 #CMAKE_OSX_ARCHITECTURES and CMAKE_OSX_SYSROOT need to be set for universal binary and correct linking |
|
113 if(NOT CMAKE_OSX_ARCHITECTURES) |
|
114 if(current_macosx_version LESS "10.6") |
|
115 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*") |
|
116 set(CMAKE_OSX_ARCHITECTURES "ppc7400") |
|
117 else() |
|
118 set(CMAKE_OSX_ARCHITECTURES "i386") |
|
119 endif() |
|
120 else() |
|
121 set(CMAKE_OSX_ARCHITECTURES "x86_64") |
|
122 endif() |
|
123 endif() |
|
124 |
|
125 #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on |
|
126 #we need to provide the correct one when host and target differ |
|
127 if(NOT ${minimum_macosx_version} MATCHES ${current_macosx_version}) |
|
128 if(minimum_macosx_version MATCHES "10.4") |
|
129 set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/") |
|
130 set(CMAKE_C_COMPILER "gcc-4.0") |
|
131 set(CMAKE_CXX_COMPILER "g++-4.0") |
|
132 else() |
|
133 string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" sdk_version ${minimum_macosx_version}) |
|
134 set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX${sdk_version}.sdk/") |
|
135 endif() |
|
136 endif() |
|
137 |
|
138 #add user framework directory, other paths can be passed via FPFLAGS |
|
139 set(pascal_flags "-Ff~/Library/Frameworks" ${pascal_flags}) |
|
140 #set deployment target |
|
141 set(pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}" ${pascal_flags}) |
|
142 |
|
143 message(STATUS "Build system: Mac OS X ${current_macosx_version} with GCC:${CMAKE_C_COMPILER}") |
|
144 message(STATUS "Target system: Mac OS X ${minimum_macosx_version} for architecture(s):${CMAKE_OSX_ARCHITECTURES}") |
|
145 endif(APPLE) |
|
146 |
111 |
147 |
112 |
148 #when build type is not specified, assume Debug/Release according to build version information |
113 #when build type is not specified, assume Debug/Release according to build version information |
149 if (CMAKE_BUILD_TYPE) |
114 if(CMAKE_BUILD_TYPE) |
150 string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) |
115 if(NOT((CMAKE_BUILD_TYPE STREQUAL "Release") OR |
151 if ( NOT( (CMAKE_BUILD_TYPE MATCHES "RELEASE") OR (CMAKE_BUILD_TYPE MATCHES "DEBUG") ) ) |
116 (CMAKE_BUILD_TYPE STREQUAL "Debug") OR |
152 set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Only 'Debug' or 'Release' options are allowed." FORCE) |
117 (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))) |
153 message (STATUS "Unknown build type, using default (${default_build_type})") |
118 set(CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release/RelWithDebInfo)" FORCE) |
154 endif () |
119 message(STATUS "Unknown build type ${CMAKE_BUILD_TYPE}, using default (${default_build_type})") |
155 else (CMAKE_BUILD_TYPE) |
120 endif() |
156 set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Choose the build type, options are: Debug Release." FORCE) |
121 else(CMAKE_BUILD_TYPE) |
157 endif (CMAKE_BUILD_TYPE) |
122 set(CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release/RelWithDebInfo)" FORCE) |
158 |
123 endif(CMAKE_BUILD_TYPE) |
159 |
124 |
160 #set default flags values for all projects |
125 |
161 set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}") |
126 #perform safe check that enable/disable compilation features |
162 set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}") |
127 #skip when crosscompiling to javascript |
163 set(CMAKE_C_FLAGS_DEBUG "-Wall -O0 -g -DDEBUG ${CMAKE_C_FLAGS_DEBUG}") |
128 if(NOT BUILD_ENGINE_JS) |
164 set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS}) |
129 include(${CMAKE_MODULE_PATH}/compilerchecks.cmake) |
165 set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) |
130 endif() |
166 set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) |
131 |
|
132 #set default compiler flags |
|
133 if(WIN32 AND VCPKG_TOOLCHAIN) |
|
134 add_flag_append(CMAKE_C_FLAGS "/DWIN32_VCPKG /Wall") |
|
135 add_flag_append(CMAKE_C_FLAGS_RELEASE "/Ox") |
|
136 add_flag_append(CMAKE_C_FLAGS_DEBUG "/Od") |
|
137 add_flag_append(CMAKE_CXX_FLAGS "/DWIN32_VCPKG /Wall") |
|
138 add_flag_append(CMAKE_CXX_FLAGS_RELEASE "/Ox") |
|
139 add_flag_append(CMAKE_CXX_FLAGS_DEBUG "/Od") |
|
140 else() |
|
141 add_flag_append(CMAKE_C_FLAGS "-Wall -pipe") |
|
142 add_flag_append(CMAKE_C_FLAGS_RELEASE "-O2") |
|
143 add_flag_append(CMAKE_C_FLAGS_DEBUG "-Wextra -O0") |
|
144 add_flag_append(CMAKE_CXX_FLAGS "-Wall -pipe") |
|
145 add_flag_append(CMAKE_CXX_FLAGS_RELEASE "-O2") |
|
146 add_flag_append(CMAKE_CXX_FLAGS_DEBUG "-Wextra -O0") |
|
147 endif() |
|
148 |
|
149 #CMake adds a lot of additional configuration flags, so let's clear them up |
|
150 if(MINIMAL_FLAGS) |
|
151 unset(CMAKE_C_FLAGS_RELEASE) |
|
152 unset(CMAKE_C_FLAGS_DEBUG) |
|
153 unset(CMAKE_CXX_FLAGS_RELEASE) |
|
154 unset(CMAKE_CXX_FLAGS_DEBUG) |
|
155 endif() |
|
156 |
167 |
157 |
168 #parse additional parameters |
158 #parse additional parameters |
169 if(FPFLAGS OR GHFLAGS) |
159 if(GHFLAGS) |
170 math(EXPR cmake_version "${CMAKE_MAJOR_VERSION}*10000 + ${CMAKE_MINOR_VERSION}*100 + ${CMAKE_PATCH_VERSION}") |
160 if(${CMAKE_VERSION} VERSION_GREATER 2.6) |
171 if(cmake_version LESS "020800") |
161 separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS}) |
172 message(STATUS "FPFLAGS and GHFLAGS are available only when using CMake >= 2.8") |
|
173 else() |
162 else() |
174 separate_arguments(fpflags_parsed UNIX_COMMAND ${FPFLAGS}) |
163 message("*** GHFLAGS are available only when using CMake >= 2.8 ***") |
175 separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS}) |
164 endif() |
176 endif() |
165 endif() |
177 endif() |
166 |
178 |
|
179 set(pascal_flags ${fpflags_parsed} "-vm4079,4080,4081" "-B" "-FE../bin" "-Cs2000000" "-vewnq" "-dDEBUGFILE" ${pascal_flags}) |
|
180 set(haskell_flags "-O2" ${ghflags_parsed} ${haskell_flags}) |
|
181 |
167 |
182 #get BUILD_TYPE and enable/disable optimisation |
168 #get BUILD_TYPE and enable/disable optimisation |
183 if(CMAKE_BUILD_TYPE MATCHES "DEBUG") |
169 message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration") |
184 message(STATUS "Building Debug flavour") |
170 if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
185 set(pascal_flags "-O-" "-g" "-gl" "-gv" ${pascal_flags}) |
171 list(APPEND haskell_flags "-Wall" # all warnings |
186 set(haskell_flags "-Wall" "-debug" "-dcore-lint" "-fno-warn-unused-do-bind" ${haskell_flags}) |
172 "-debug" # debug mode |
187 else() |
173 "-fno-warn-unused-do-bind" |
188 message(STATUS "Building Release flavour") |
174 "-O0" |
189 # set(pascal_flags "-O3" "-OpPENTIUM4" "-CfSSE3" "-Xs" "-Si" ${pascal_flags}) |
175 ) |
190 set(pascal_flags "-Os" "-Ooregvar" "-Xs" "-Si" ${pascal_flags}) |
176 else() |
191 set(haskell_flags "-w" "-fno-warn-unused-do-bind" ${haskell_flags}) |
177 list(APPEND haskell_flags "-w" # no warnings |
192 endif() |
178 "-O2" |
193 |
179 ) |
194 |
180 endif() |
195 #finish setting paths |
181 |
196 if(DEFINED DATA_INSTALL_DIR) |
182 |
197 set(SHAREPATH ${DATA_INSTALL_DIR}/hedgewars/) |
183 #build engine without freepascal |
198 else() |
184 if(BUILD_ENGINE_C AND NOT BUILD_ENGINE_JS) |
199 set(SHAREPATH share/hedgewars/) |
185 find_package(Clang REQUIRED) |
200 endif() |
186 |
201 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) |
187 if(${CLANG_VERSION} VERSION_LESS "3.0") |
202 set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}) |
188 message(FATAL_ERROR "LLVM/Clang compiler required version is 3.0 but version ${CLANG_VERSION} was found!") |
203 |
189 endif() |
204 |
190 |
205 #server discovery |
191 set(CMAKE_C_COMPILER ${CLANG_EXECUTABLE}) |
|
192 set(CMAKE_CXX_COMPILER ${CLANG_EXECUTABLE}) |
|
193 endif() |
|
194 |
|
195 |
|
196 #server |
206 if(NOT NOSERVER) |
197 if(NOT NOSERVER) |
207 if(GHC) |
198 add_subdirectory(gameServer) |
208 set(ghc_executable ${GHC}) |
199 endif() |
|
200 |
|
201 |
|
202 #lua discovery |
|
203 if(LUA_SYSTEM) |
|
204 if(NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR) |
|
205 find_package(Lua) |
|
206 endif() |
|
207 |
|
208 if(LUA_LIBRARY AND LUA_INCLUDE_DIR) |
|
209 #use an IMPORTED tharget so that we can just use 'lua' to link |
|
210 add_library(lua UNKNOWN IMPORTED) |
|
211 set_target_properties(lua PROPERTIES IMPORTED_LOCATION ${LUA_LIBRARY}) |
209 else() |
212 else() |
210 find_program(ghc_executable ghc) |
213 message(FATAL_ERROR "Missing Lua! Rerun cmake with -DLUA_SYSTEM=off to build the internal version") |
211 endif() |
214 endif() |
212 |
215 else() |
213 if(ghc_executable) |
216 if(NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR) |
214 set(HAVE_NETSERVER true) |
217 message(STATUS "LUA will be provided by the bundled sources") |
215 add_subdirectory(gameServer) |
218 endif() |
216 message(STATUS "Found GHC: ${ghc_executable}") |
219 set(lua_output_name "hwlua") |
217 else() |
|
218 message(STATUS "Could NOT find GHC, server will not be built") |
|
219 set(HAVE_NETSERVER false) |
|
220 endif() |
|
221 else() |
|
222 message(STATUS "Server will not be built per user request") |
|
223 set(HAVE_NETSERVER false) |
|
224 endif() |
|
225 |
|
226 |
|
227 #lua discovery |
|
228 find_package(Lua) |
|
229 if(LUA_FOUND) |
|
230 message(STATUS "Found LUA: ${LUA_DEFAULT}") |
|
231 else() |
|
232 message(STATUS "LUA will be provided by the bundled sources") |
|
233 add_subdirectory(misc/liblua) |
220 add_subdirectory(misc/liblua) |
234 #linking with liblua.a requires system readline -- this works everywhere, right? |
221 endif() |
235 set(pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline" ${pascal_flags}) |
222 |
236 endif() |
223 |
237 |
224 #physfs discovery |
238 |
225 if(NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR) |
239 #main engine |
226 find_package(PhysFS) |
240 add_subdirectory(hedgewars) |
227 endif() |
|
228 |
|
229 find_file(physfs_h physfs.h ${PHYSFS_INCLUDE_DIR}) |
|
230 if(physfs_h) |
|
231 file(STRINGS ${physfs_h} physfs_majorversion REGEX "PHYSFS_VER_MAJOR[\t' ']+[0-9]+") |
|
232 file(STRINGS ${physfs_h} physfs_minorversion REGEX "PHYSFS_VER_MINOR[\t' ']+[0-9]+") |
|
233 file(STRINGS ${physfs_h} physfs_patchversion REGEX "PHYSFS_VER_PATCH[\t' ']+[0-9]+") |
|
234 string(REGEX MATCH "([0-9]+)" physfs_majorversion "${physfs_majorversion}") |
|
235 string(REGEX MATCH "([0-9]+)" physfs_minorversion "${physfs_minorversion}") |
|
236 string(REGEX MATCH "([0-9]+)" physfs_patchversion "${physfs_patchversion}") |
|
237 set(physfs_detected_ver "${physfs_majorversion}.${physfs_minorversion}.${physfs_patchversion}") |
|
238 |
|
239 if(${physfs_detected_ver} VERSION_LESS 3.0.0) |
|
240 message(FATAL_ERROR "PhysFS version is too old (detected ${physfs_detected_ver}, required 3.0.0)\n" |
|
241 "Perform an update of PhysFS to fix this.") |
|
242 endif() |
|
243 endif() |
|
244 |
|
245 if(PHYSFS_LIBRARY AND PHYSFS_INCLUDE_DIR) |
|
246 #use an IMPORTED tharget so that we can just use 'physfs' to link |
|
247 add_library(physfs UNKNOWN IMPORTED) |
|
248 set_target_properties(physfs PROPERTIES IMPORTED_LOCATION ${PHYSFS_LIBRARY}) |
|
249 else() |
|
250 message(FATAL_ERROR "Missing PhysFS! Install PhysFS to fix this.") |
|
251 endif() |
|
252 |
|
253 find_package_or_disable_msg(LIBAV NOVIDEOREC "Video recording will not be built") |
|
254 |
|
255 #physfs helper library |
|
256 add_subdirectory(misc/libphyslayer) |
|
257 |
|
258 #maybe this could be merged inside hedgewars/CMakeLists.txt |
|
259 if(BUILD_ENGINE_C) |
|
260 #pascal to c converter |
|
261 add_subdirectory(tools/pas2c) |
|
262 add_subdirectory(project_files/hwc) |
|
263 else() |
|
264 #main pascal engine |
|
265 add_subdirectory(hedgewars) |
|
266 endif() |
241 |
267 |
242 #Android related build scripts |
268 #Android related build scripts |
|
269 #TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set |
243 if(ANDROID) |
270 if(ANDROID) |
244 #run cmake -DANDROID=1 to enable this |
|
245 add_subdirectory(project_files/Android-build) |
271 add_subdirectory(project_files/Android-build) |
246 endif() |
272 else(ANDROID) |
247 |
273 #skip frontend for javascript |
248 #TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set |
274 if(NOT BUILD_ENGINE_JS) |
249 if(NOT (BUILD_ENGINE_LIBRARY OR ANDROID)) |
275 add_subdirectory(QTfrontend) |
|
276 add_subdirectory(share) |
|
277 endif() |
|
278 |
250 add_subdirectory(bin) |
279 add_subdirectory(bin) |
251 add_subdirectory(misc/quazip) |
|
252 add_subdirectory(QTfrontend) |
|
253 add_subdirectory(share) |
|
254 add_subdirectory(tools) |
280 add_subdirectory(tools) |
255 endif() |
281 endif(ANDROID) |
256 |
282 |
257 |
283 include(${CMAKE_MODULE_PATH}/cpackvars.cmake) |
258 # CPack variables |
284 |
259 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hedgewars, a free turn-based strategy") |
285 enable_testing() |
260 set(CPACK_PACKAGE_VENDOR "Hedgewars Project") |
286 |
261 set(CPACK_PACKAGE_FILE_NAME "hedgewars-${HEDGEWARS_VERSION}") |
287 add_custom_target(test_normal COMMAND ${CMAKE_CTEST_COMMAND} -E '^todo/' --timeout 300 --schedule-random) |
262 set(CPACK_SOURCE_PACKAGE_FILE_NAME "hedgewars-src-${HEDGEWARS_VERSION}") |
288 add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} -E '^todo/' --timeout 300 --schedule-random -V) |
263 set(CPACK_SOURCE_GENERATOR "TBZ2") |
289 |
264 set(CPACK_PACKAGE_EXECUTABLES "hedgewars" "hedgewars") |
290 set(LUATESTS_DIR "${CMAKE_SOURCE_DIR}/tests/lua") |
265 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") |
291 set(TESTSDATA_DIR "${CMAKE_SOURCE_DIR}/share/hedgewars/Data") |
266 set(CPACK_PACKAGE_INSTALL_DIRECTORY "Hedgewars ${HEDGEWARS_VERSION}") |
292 |
267 |
293 # set set this to "" if you want to see what's going on |
268 if(WIN32 AND NOT UNIX) |
294 # TODO: engine should do this implicitly when running tests, |
269 set(CPACK_NSIS_DISPLAY_NAME "Hedgewars") |
295 # unless some env var like HWENGINE_SHOWTESTS is set or something |
270 set(CPACK_NSIS_HELP_LINK "http://www.hedgewars.org/") |
296 set(STATSONLYFLAG "--stats-only") |
271 set(CPACK_NSIS_URL_INFO_ABOUT "http://www.hedgewars.org/") |
297 |
272 set(CPACK_NSIS_CONTACT "unC0Rr@gmail.com") |
298 # add all lua tests |
273 set(CPACK_NSIS_MODIFY_PATH OFF) |
299 file(GLOB_RECURSE luatests RELATIVE "${LUATESTS_DIR}" "${LUATESTS_DIR}/*.lua") |
274 set(CPACK_GENERATOR "ZIP;NSIS") |
300 foreach(luatest ${luatests}) |
275 set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "hedgewars") |
301 add_test("${luatest}" "bin/hwengine" "--prefix" "${TESTSDATA_DIR}" "--nosound" "--nomusic" "${STATSONLYFLAG}" "--lua-test" "${LUATESTS_DIR}/${luatest}") |
276 else(WIN32 AND NOT UNIX) |
302 endforeach(luatest) |
277 set(CPACK_STRIP_FILES "bin/hedgewars;bin/hwengine") |
303 |
278 endif(WIN32 AND NOT UNIX) |
|
279 |
|
280 set(CPACK_SOURCE_IGNORE_FILES |
|
281 "~" |
|
282 "\\\\.hg" |
|
283 "\\\\.svn" |
|
284 "\\\\.exe$" |
|
285 "\\\\.a$" |
|
286 "\\\\.dll$" |
|
287 "\\\\.xcf$" |
|
288 "\\\\.cxx$" |
|
289 "\\\\.db$" |
|
290 "\\\\.dof$" |
|
291 "\\\\.layout$" |
|
292 "\\\\.zip$" |
|
293 "\\\\.gz$" |
|
294 "\\\\.bz2$" |
|
295 "\\\\.tmp$" |
|
296 "\\\\.core$" |
|
297 "\\\\.sh$" |
|
298 "\\\\.sifz$" |
|
299 "\\\\.svg$" |
|
300 "\\\\.svgz$" |
|
301 "\\\\.ppu$" |
|
302 "\\\\.psd$" |
|
303 "\\\\.o$" |
|
304 "Makefile" |
|
305 "Doxyfile" |
|
306 "CMakeFiles" |
|
307 "debug" |
|
308 "release$" |
|
309 "Debug$" |
|
310 "Release$" |
|
311 "proto\\\\.inc$" |
|
312 "hwconsts\\\\.cpp$" |
|
313 "playlist\\\\.inc$" |
|
314 "CPack" |
|
315 "cmake_install\\\\.cmake$" |
|
316 "config\\\\.inc$" |
|
317 "hwengine\\\\.desktop$" |
|
318 "CMakeCache\\\\.txt$" |
|
319 # "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libopenalbridge" |
|
320 # "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libfreetype" |
|
321 "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" |
|
322 # "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libtremor" |
|
323 "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/HedgewarsMobile/" |
|
324 "^${CMAKE_CURRENT_SOURCE_DIR}/bin/[a-z]" |
|
325 "^${CMAKE_CURRENT_SOURCE_DIR}/tools/templates" |
|
326 "^${CMAKE_CURRENT_SOURCE_DIR}/doc" |
|
327 "^${CMAKE_CURRENT_SOURCE_DIR}/templates" |
|
328 "^${CMAKE_CURRENT_SOURCE_DIR}/Graphics" |
|
329 "^${CMAKE_CURRENT_SOURCE_DIR}/realtest" |
|
330 "^${CMAKE_CURRENT_SOURCE_DIR}/tmp" |
|
331 "^${CMAKE_CURRENT_SOURCE_DIR}/utils" |
|
332 "^${CMAKE_CURRENT_SOURCE_DIR}/share/hedgewars/Data/Maps/test" |
|
333 "^${CMAKE_CURRENT_SOURCE_DIR}/share/hedgewars/Data/Themes/ethereal" |
|
334 "^${CMAKE_CURRENT_SOURCE_DIR}/install_manifest.txt" |
|
335 "^${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt" |
|
336 "^${CMAKE_CURRENT_SOURCE_DIR}/hedgewars\\\\." |
|
337 ) |
|
338 |
|
339 include(CPack) |
|
340 |
|