9 configure_file(${hedgewars_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc) |
9 configure_file(${hedgewars_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc) |
10 |
10 |
11 #SOURCE AND PROGRAMS SECTION |
11 #SOURCE AND PROGRAMS SECTION |
12 set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas) |
12 set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas) |
13 set(engine_output_name "hwengine") |
13 set(engine_output_name "hwengine") |
|
14 |
|
15 if (APPLE) |
|
16 set(required_fpc_version 2.6) |
|
17 else() |
|
18 set(required_fpc_version 2.2) |
|
19 endif() |
14 |
20 |
15 set(engine_sources |
21 set(engine_sources |
16 ${hwengine_project} |
22 ${hwengine_project} |
17 LuaPas.pas |
23 LuaPas.pas |
18 PNGh.pas |
24 PNGh.pas |
99 set(engine_output_name "libhwengine.dylib") |
105 set(engine_output_name "libhwengine.dylib") |
100 endif (APPLE) |
106 endif (APPLE) |
101 endif(BUILD_ENGINE_LIBRARY) |
107 endif(BUILD_ENGINE_LIBRARY) |
102 |
108 |
103 |
109 |
104 #PASCAL DETECTION SECTION |
110 # Check Freepascal version |
105 IF(FPC) |
111 find_package(Freepascal) |
106 set(fpc_executable ${FPC}) |
112 |
107 ELSE() |
113 if (FPC_VERSION VERSION_LESS required_fpc_version) |
108 find_program(fpc_executable fpc) |
114 message(FATAL_ERROR "Necessary FPC version not found (version >= ${required_fpc_version} required)") |
109 ENDIF() |
115 else() |
110 |
116 message(STATUS "Found FPC: ${FPC_EXECUTABLE} (version ${FPC_VERSION})") |
111 message(STATUS "Check for working FPC compiler: ${fpc_executable}") |
117 endif() |
112 execute_process(COMMAND ${fpc_executable} -iV OUTPUT_VARIABLE fpc_output ERROR_VARIABLE fpc_error) |
118 |
113 if(fpc_error) |
|
114 message(STATUS "Check for working FPC compiler: ${fpc_executable} -- broken") |
|
115 else(fpc_error) |
|
116 message(STATUS "Check for working FPC compiler: ${fpc_executable} -- works") |
|
117 endif(fpc_error) |
|
118 |
|
119 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}") |
|
120 if(fpc_version) |
|
121 string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}") |
|
122 string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}") |
|
123 string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}") |
|
124 message(STATUS "Found Freepascal: ${fpc_executable} (version ${fpc_vers_major}.${fpc_vers_minor})") |
|
125 math(EXPR fpc_version "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}") |
|
126 |
|
127 if(fpc_version LESS "020200") |
|
128 message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0") |
|
129 elseif(APPLE AND (fpc_version LESS "020600")) |
|
130 message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X") |
|
131 endif() |
|
132 else() |
|
133 message(FATAL_ERROR "No FreePascal compiler found!") |
|
134 endif() |
|
135 |
|
136 message(STATUS "Checking whether linker supports noexecstack flag") |
|
137 set(noexecstack_flags "-k-z" "-knoexecstack") |
|
138 file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.") |
|
139 |
|
140 execute_process(COMMAND ${fpc_executable} ${noexecstack_flags} checkstack.pas |
|
141 WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} |
|
142 RESULT_VARIABLE testnoexecstack |
|
143 OUTPUT_QUIET ERROR_QUIET |
|
144 ) |
|
145 |
|
146 if(${testnoexecstack}) |
|
147 set (noexecstack_flags "") |
|
148 message(STATUS "Checking whether linker supports noexecstack flag -- no") |
|
149 else(${testnoexecstack}) |
|
150 message(STATUS "Checking whether linker supports noexecstack flag -- yes") |
|
151 endif(${testnoexecstack}) |
|
152 |
119 |
153 #DEPENDECIES AND EXECUTABLES SECTION |
120 #DEPENDECIES AND EXECUTABLES SECTION |
154 if(APPLE) |
121 if(APPLE) |
155 string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}") |
122 string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}") |
156 string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}") |
123 string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}") |
239 |
206 |
240 set(pascal_flags "-Fl${LIBRARY_OUTPUT_PATH}" ${pascal_flags}) |
207 set(pascal_flags "-Fl${LIBRARY_OUTPUT_PATH}" ${pascal_flags}) |
241 |
208 |
242 set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project}) |
209 set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project}) |
243 |
210 |
244 IF(NOT APPLE) |
211 if(NOT APPLE) |
245 #here is the command for standard executables or for shared library |
212 #here is the command for standard executables or for shared library |
246 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}" |
213 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}" |
247 COMMAND "${fpc_executable}" |
214 COMMAND "${fpc_executable}" |
248 ARGS ${fpc_flags} |
215 ARGS ${fpc_flags} |
249 MAIN_DEPENDENCY ${hwengine_project} |
216 MAIN_DEPENDENCY ${hwengine_project} |
250 DEPENDS ${engine_sources} |
217 DEPENDS ${engine_sources} |
251 ) |
218 ) |
252 ELSE() |
219 else() |
253 #these are the dependencies for building a universal binary on Mac OS X |
220 #these are the dependencies for building a universal binary on Mac OS X |
254 foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build}) |
221 foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build}) |
255 set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list}) |
222 set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list}) |
256 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" |
223 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" |
257 COMMAND "${fpc_executable}" |
224 COMMAND "${fpc_executable}" |
265 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" |
232 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" |
266 COMMAND "lipo" |
233 COMMAND "lipo" |
267 ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/${engine_output_name} |
234 ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/${engine_output_name} |
268 DEPENDS ${lipo_args_list} |
235 DEPENDS ${lipo_args_list} |
269 ) |
236 ) |
270 ENDIF() |
237 endif() |
271 |
238 |
272 |
239 |
273 add_custom_target(${engine_output_name} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}") |
240 add_custom_target(${engine_output_name} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}") |
274 |
241 |
275 #when system Lua is not found we need to compile it before engine |
242 #when system Lua is not found we need to compile it before engine |