44 if(UNIX AND NOT APPLE) |
37 if(UNIX AND NOT APPLE) |
45 set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path") |
38 set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path") |
46 endif() |
39 endif() |
47 |
40 |
48 |
41 |
49 #detect Mercurial revision and init rev/hash information |
|
50 find_program(HGCOMMAND hg) |
|
51 if(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg)) |
|
52 execute_process(COMMAND ${HGCOMMAND} identify -in |
|
53 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
|
54 OUTPUT_VARIABLE internal_version |
|
55 ERROR_QUIET |
|
56 ) |
|
57 #check local repo status |
|
58 string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version}) |
|
59 string(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" HEDGEWARS_REVISION ${internal_version}) |
|
60 string(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" HEDGEWARS_HASH ${internal_version}) |
|
61 |
|
62 if(HGCHANGED) |
|
63 message(${WARNING} "You have uncommitted changes in your repository!") |
|
64 endif() |
|
65 #let's assume that if you have hg you might be interested in debugging |
|
66 set(default_build_type "DEBUG") |
|
67 #write down hash and rev for easy picking should hg be missing |
|
68 file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n") |
|
69 else() |
|
70 set(default_build_type "RELEASE") |
|
71 # when compiling outside rev control, fetch revision and hash information from version_info.txt |
|
72 find_file(version_info version_info.txt PATH ${CMAKE_SOURCE_DIR}/share) |
|
73 if(version_info) |
|
74 file(STRINGS ${version_info} internal_version REGEX "rev") |
|
75 string(REGEX REPLACE "rev ([0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version}) |
|
76 file(STRINGS ${version_info} internal_version REGEX "hash") |
|
77 string(REGEX REPLACE "hash ([a-zA-Z0-9]*)" "\\1" HEDGEWARS_HASH ${internal_version}) |
|
78 else() |
|
79 message(${WARNING} "${CMAKE_SOURCE_DIR}/share/version_info.txt not found, revision information " |
|
80 "will be incorrect!!! Contact your source provider to fix this!") |
|
81 set(HEDGEWARS_REVISION "0000") |
|
82 set(HEDGEWARS_HASH "unknown") |
|
83 endif() |
|
84 endif() |
|
85 |
|
86 |
|
87 #versioning |
42 #versioning |
88 set(CPACK_PACKAGE_VERSION_MAJOR 0) |
43 set(CPACK_PACKAGE_VERSION_MAJOR 0) |
89 set(CPACK_PACKAGE_VERSION_MINOR 9) |
44 set(CPACK_PACKAGE_VERSION_MINOR 9) |
90 set(CPACK_PACKAGE_VERSION_PATCH 19) |
45 set(CPACK_PACKAGE_VERSION_PATCH 20) |
91 set(HEDGEWARS_PROTO_VER 45) |
46 set(HEDGEWARS_PROTO_VER 46) |
92 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") |
47 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") |
|
48 include(${CMAKE_MODULE_PATH}/revinfo.cmake) |
93 set(required_clang_version 3.0) |
49 set(required_clang_version 3.0) |
94 |
50 |
95 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})") |
51 message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})") |
96 |
52 |
97 if (${NOPASCAL}) |
53 if (${NOPASCAL}) |
136 set(HEDGEWARS_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/") |
92 set(HEDGEWARS_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/") |
137 link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin") |
93 link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin") |
138 endif() |
94 endif() |
139 endif() |
95 endif() |
140 |
96 |
141 |
97 #platform specific init code |
142 if(APPLE) |
98 include(${CMAKE_MODULE_PATH}/platform.cmake) |
143 set(CMAKE_FIND_FRAMEWORK "FIRST") |
|
144 |
|
145 #what system are we building for |
|
146 set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET}) |
|
147 |
|
148 #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version |
|
149 find_program(sw_vers sw_vers) |
|
150 if(sw_vers) |
|
151 execute_process(COMMAND ${sw_vers} "-productVersion" |
|
152 OUTPUT_VARIABLE current_macosx_version |
|
153 OUTPUT_STRIP_TRAILING_WHITESPACE) |
|
154 string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version}) |
|
155 else() |
|
156 if(NOT minimum_macosx_version) |
|
157 message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set") |
|
158 else() |
|
159 message(${WARNING} "sw_vers not found! Fallback to MACOSX_DEPLOYMENT_TARGET variable") |
|
160 set(current_macosx_version ${minimum_macosx_version}) |
|
161 endif() |
|
162 endif() |
|
163 |
|
164 #if nothing is set, we deploy only for the current system |
|
165 if(NOT minimum_macosx_version) |
|
166 set(minimum_macosx_version ${current_macosx_version}) |
|
167 endif() |
|
168 |
|
169 #lower systems don't have enough processing power anyway |
|
170 if (minimum_macosx_version VERSION_LESS "10.4") |
|
171 message(FATAL_ERROR "Hedgewars is not supported on Mac OS X pre-10.4") |
|
172 endif() |
|
173 |
|
174 #workaround for http://playcontrol.net/ewing/jibberjabber/big_behind-the-scenes_chang.html#SDL_mixer (Update 2) |
|
175 if(current_macosx_version VERSION_EQUAL "10.4") |
|
176 find_package(SDL_mixer REQUIRED) |
|
177 set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg") |
|
178 set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod") |
|
179 set(CMAKE_C_FLAGS "${DYLIB_SMPEG} ${DYLIB_MIKMOD}") |
|
180 list(APPEND pascal_flags "-k${DYLIB_SMPEG}" "-k${DYLIB_MIKMOD}") |
|
181 endif() |
|
182 |
|
183 #CMAKE_OSX_ARCHITECTURES and CMAKE_OSX_SYSROOT need to be set for universal binary and correct linking |
|
184 if(NOT CMAKE_OSX_ARCHITECTURES) |
|
185 if(current_macosx_version VERSION_LESS "10.6") |
|
186 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "powerpc*") |
|
187 set(CMAKE_OSX_ARCHITECTURES "ppc7400") |
|
188 else() |
|
189 set(CMAKE_OSX_ARCHITECTURES "i386") |
|
190 endif() |
|
191 else() |
|
192 set(CMAKE_OSX_ARCHITECTURES "x86_64") |
|
193 endif() |
|
194 endif() |
|
195 |
|
196 #CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on |
|
197 #we need to provide the correct one when host and target differ |
|
198 if(NOT ${minimum_macosx_version} VERSION_EQUAL ${current_macosx_version}) |
|
199 if(minimum_macosx_version VERSION_EQUAL "10.4") |
|
200 set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk/") |
|
201 set(CMAKE_C_COMPILER "/Developer/usr/bin/gcc-4.0") |
|
202 set(CMAKE_CXX_COMPILER "/Developer/usr/bin/g++-4.0") |
|
203 else() |
|
204 string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" sdk_version ${minimum_macosx_version}) |
|
205 set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX${sdk_version}.sdk/") |
|
206 endif() |
|
207 endif() |
|
208 |
|
209 #add user framework directory, other paths can be passed via FPFLAGS |
|
210 list(APPEND pascal_flags "-Ff~/Library/Frameworks") |
|
211 #set deployment target |
|
212 list(APPEND pascal_flags "-k-macosx_version_min" "-k${minimum_macosx_version}" "-XR${CMAKE_OSX_SYSROOT}") |
|
213 endif(APPLE) |
|
214 |
99 |
215 |
100 |
216 #when build type is not specified, assume Debug/Release according to build version information |
101 #when build type is not specified, assume Debug/Release according to build version information |
217 if (CMAKE_BUILD_TYPE) |
102 if (CMAKE_BUILD_TYPE) |
218 string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) |
103 string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) |
223 else (CMAKE_BUILD_TYPE) |
108 else (CMAKE_BUILD_TYPE) |
224 set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release)" FORCE) |
109 set (CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Build type (Debug/Release)" FORCE) |
225 endif (CMAKE_BUILD_TYPE) |
110 endif (CMAKE_BUILD_TYPE) |
226 |
111 |
227 |
112 |
|
113 #perform safe check that enable/disable compilation features |
|
114 include(${CMAKE_MODULE_PATH}/compilerchecks.cmake) |
|
115 |
228 #set default flags values for all projects (unless MINIMAL_FLAGS is true) |
116 #set default flags values for all projects (unless MINIMAL_FLAGS is true) |
229 if(NOT ${MINIMAL_FLAGS}) |
117 if(NOT ${MINIMAL_FLAGS}) |
230 if(WINDOWS) |
|
231 #this flags prevents a few dll hell problems |
|
232 set(CMAKE_C_FLAGS "-static-libgcc ${CMAKE_C_FLAGS}") |
|
233 endif(WINDOWS) |
|
234 set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}") |
118 set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}") |
235 set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}") |
119 set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}") |
236 set(CMAKE_C_FLAGS_DEBUG "-Wall -O0 -g -DDEBUG ${CMAKE_C_FLAGS_DEBUG}") |
120 set(CMAKE_C_FLAGS_DEBUG "-Wall -O0 -g -DDEBUG ${CMAKE_C_FLAGS_DEBUG}") |
237 set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS}) |
121 set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS}) |
238 set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) |
122 set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) |
243 set(CMAKE_C_FLAGS_DEBUG "-Wall -DDEBUG") |
127 set(CMAKE_C_FLAGS_DEBUG "-Wall -DDEBUG") |
244 set(CMAKE_CXX_FLAGS_RELEASE "") |
128 set(CMAKE_CXX_FLAGS_RELEASE "") |
245 set(CMAKE_CXX_FLAGS_DEBUG "-Wall -DDEBUG") |
129 set(CMAKE_CXX_FLAGS_DEBUG "-Wall -DDEBUG") |
246 endif() |
130 endif() |
247 |
131 |
248 |
|
249 #TESTING TIME |
|
250 include(CheckCCompilerFlag) |
|
251 |
|
252 #check for noexecstack on ELF, should be set on Gentoo and similar |
|
253 set(CMAKE_REQUIRED_FLAGS "-Wl,-z -Wl,noexecstack") |
|
254 check_c_compiler_flag("" HAVE_NOEXECSTACK) #empty because we are testing a linker flag |
|
255 if(HAVE_NOEXECSTACK) |
|
256 list(APPEND pascal_flags "-k-z" "-knoexecstack") |
|
257 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
|
258 endif() |
|
259 unset(CMAKE_REQUIRED_FLAGS) |
|
260 |
|
261 #check for ASLR and DEP security features on Windows |
|
262 #both supported in binutils >= 2.20, available since Vista and XP SP2 respectively |
|
263 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat -Wl,--dynamicbase") |
|
264 check_c_compiler_flag("" HAVE_WINASLRDEP) #empty because we are testing a linker flag |
|
265 if(HAVE_WINASLRDEP) |
|
266 list(APPEND pascal_flags "-k--nxcompat" "-k--dynamicbase") |
|
267 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
|
268 endif() |
|
269 unset(CMAKE_REQUIRED_FLAGS) |
|
270 |
|
271 #parse additional parameters |
132 #parse additional parameters |
272 if(FPFLAGS OR GHFLAGS) |
133 if(FPFLAGS OR GHFLAGS) |
273 if(${allow_parse_args}) |
134 if(CMAKE_VERSION VERSION_GREATER "2.6") |
274 separate_arguments(fpflags_parsed UNIX_COMMAND ${FPFLAGS}) |
135 separate_arguments(fpflags_parsed UNIX_COMMAND ${FPFLAGS}) |
275 separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS}) |
136 separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS}) |
276 else() |
137 else() |
277 message(${WARNING} "FPFLAGS and GHFLAGS are available only when using CMake >= 2.8") |
138 message("*** FPFLAGS and GHFLAGS are available only when using CMake >= 2.8 ***") |
278 endif() |
139 endif() |
279 endif() |
140 endif() |
280 |
141 |
281 list(APPEND pascal_flags ${fpflags_parsed} # user flags |
142 list(APPEND pascal_flags ${fpflags_parsed} # user flags |
282 "-B" # compile all units |
143 "-B" # compile all units |