70 ) |
70 ) |
71 |
71 |
72 if(BUILD_ENGINE_LIBRARY) |
72 if(BUILD_ENGINE_LIBRARY) |
73 message(STATUS "Engine will be built as library (experimental)") |
73 message(STATUS "Engine will be built as library (experimental)") |
74 set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas) |
74 set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas) |
75 set(engine_sources ${hwengine_project} PascalExports.pas ${engine_sources}) |
75 set(pascal_flags "-dHWLIBRARY" ${pascal_flags}) |
76 set(pascal_compiler_flags_cmn "-dHWLIBRARY" ${pascal_compiler_flags_cmn}) |
|
77 |
76 |
78 # create position independent code, only required for x68_64 builds, similar to -fPIC |
77 # create position independent code, only required for x68_64 builds, similar to -fPIC |
79 if(CMAKE_SIZEOF_VOID_P MATCHES "8") |
78 if(CMAKE_SIZEOF_VOID_P MATCHES "8") |
80 set(pascal_compiler_flags_cmn "-Cg" ${pascal_compiler_flags_cmn}) |
79 set(pascal_flags "-Cg" ${pascal_flags}) |
81 endif(CMAKE_SIZEOF_VOID_P MATCHES "8") |
80 endif(CMAKE_SIZEOF_VOID_P MATCHES "8") |
82 |
81 |
83 # due to compiling/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail |
82 # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail |
84 if(APPLE AND current_macosx_version GREATER "10.5") |
83 if(APPLE AND current_macosx_version GREATER "10.5") |
85 set(pascal_compiler_flags_cmn "-k-no_order_inits" ${pascal_compiler_flags_cmn}) |
84 set(pascal_flags "-k-no_order_inits" ${pascal_flags}) |
86 endif() |
85 endif() |
87 |
86 |
88 if (APPLE) |
87 if (APPLE) |
89 set(engine_output_name "hwengine.dylib") |
88 set(engine_output_name "hwengine.dylib") |
90 endif (APPLE) |
89 endif (APPLE) |
120 string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}") |
119 string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}") |
121 |
120 |
122 if(powerpc_build) |
121 if(powerpc_build) |
123 set(powerpc_build "powerpc") |
122 set(powerpc_build "powerpc") |
124 endif() |
123 endif() |
125 endif(APPLE) |
124 |
126 |
|
127 |
|
128 #PASCAL DETECTION SECTION |
|
129 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}") |
|
130 |
|
131 if(fpc_version) |
|
132 string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}") |
|
133 string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}") |
|
134 string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}") |
|
135 message(STATUS "Freepascal version installed: ${fpc_vers_major}.${fpc_vers_minor}") |
|
136 math(EXPR fpc_ver "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}") |
|
137 |
|
138 if(fpc_ver LESS "020200") |
|
139 message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0") |
|
140 elseif(APPLE AND (fpc_ver LESS "020600")) |
|
141 message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X") |
|
142 endif() |
|
143 else() |
|
144 message(FATAL_ERROR "No FreePascal compiler found!") |
|
145 endif() |
|
146 |
|
147 |
|
148 #DEPENDECIES AND EXECUTABLES SECTION |
|
149 find_package(PNG) |
|
150 if(${PNG_FOUND}) |
|
151 message(STATUS "PNG screenshots enabled (library found at ${PNG_LIBRARY})") |
|
152 set(pascal_compiler_flags_cmn "-dPNG_SCREENSHOTS" ${pascal_compiler_flags_cmn}) |
|
153 if(APPLE) # need to explictly link with the static lib |
|
154 string(REGEX REPLACE "(.*)libpng.*" "\\1" PNG_LIBDIR "${PNG_LIBRARY}") |
|
155 set(pascal_compiler_flags_cmn "-k${PNG_LIBDIR}/libpng.a" ${pascal_compiler_flags_cmn}) |
|
156 endif() |
|
157 else() |
|
158 message(STATUS "PNG library not found, switching to screenshots in BMP format") |
|
159 endif() |
|
160 |
|
161 set(pascal_compiler ${fpc_executable}) |
|
162 set(pascal_compiler_flags ${noexecstack_flags} ${pascal_compiler_flags_cmn} ${hwengine_project}) |
|
163 |
|
164 |
|
165 IF(NOT APPLE) |
|
166 #here is the command for standard executables or for shared library |
|
167 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}" |
|
168 COMMAND "${pascal_compiler}" |
|
169 ARGS ${pascal_compiler_flags} |
|
170 MAIN_DEPENDENCY ${hwengine_project} |
|
171 DEPENDS ${engine_sources} |
|
172 ) |
|
173 ELSE() |
|
174 #on OSX we need to provide the main() function when building as executable |
125 #on OSX we need to provide the main() function when building as executable |
175 if(NOT BUILD_ENGINE_LIBRARY) |
126 if(NOT BUILD_ENGINE_LIBRARY) |
176 #let's look for the bundled sdlmain, if not found build our own |
127 #let's look for the bundled sdlmain, if not found build our own |
177 find_package(SDL REQUIRED) |
128 find_package(SDL REQUIRED) |
178 #remove the ";-framework Cocoa" from the SDL_LIBRARY variable |
129 #remove the ";-framework Cocoa" from the SDL_LIBRARY variable |
183 if(SDLMAIN_LIB MATCHES "SDLMAIN_LIB-NOTFOUND") |
134 if(SDLMAIN_LIB MATCHES "SDLMAIN_LIB-NOTFOUND") |
184 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) |
135 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) |
185 include_directories(${SDL_INCLUDE_DIR}) |
136 include_directories(${SDL_INCLUDE_DIR}) |
186 add_library (SDLmain STATIC SDLMain.m) |
137 add_library (SDLmain STATIC SDLMain.m) |
187 #add a dependency to the hwengine target |
138 #add a dependency to the hwengine target |
188 set(engine_sources ${engine_sources} "SDLmain") |
139 set(engine_sources ${engine_sources} SDLmain) |
189 set(SDLMAIN_LIB "${CMAKE_BINARY_DIR}/bin/libSDLmain.a") |
140 set(SDLMAIN_LIB "${CMAKE_BINARY_DIR}/bin/libSDLmain.a") |
190 endif() |
141 endif() |
191 |
142 |
192 set(pascal_compiler_flags "-k${SDLMAIN_LIB}" ${pascal_compiler_flags}) |
143 set(pascal_flags "-k${SDLMAIN_LIB}" ${pascal_flags}) |
193 endif() |
144 endif() |
194 |
145 endif(APPLE) |
|
146 |
|
147 |
|
148 #PASCAL DETECTION SECTION |
|
149 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}") |
|
150 |
|
151 if(fpc_version) |
|
152 string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}") |
|
153 string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}") |
|
154 string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}") |
|
155 message(STATUS "Freepascal version installed: ${fpc_vers_major}.${fpc_vers_minor}") |
|
156 math(EXPR fpc_version "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}") |
|
157 |
|
158 if(fpc_version LESS "020200") |
|
159 message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0") |
|
160 elseif(APPLE AND (fpc_version LESS "020600")) |
|
161 message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X") |
|
162 endif() |
|
163 else() |
|
164 message(FATAL_ERROR "No FreePascal compiler found!") |
|
165 endif() |
|
166 |
|
167 |
|
168 #DEPENDECIES AND EXECUTABLES SECTION |
|
169 find_package(PNG) |
|
170 if(${PNG_FOUND}) |
|
171 message(STATUS "PNG screenshots enabled (library found at ${PNG_LIBRARY})") |
|
172 set(pascal_flags "-dPNG_SCREENSHOTS" ${pascal_flags}) |
|
173 if(APPLE) # need to explictly link with the static lib |
|
174 string(REGEX REPLACE "(.*)libpng.*" "\\1" PNG_LIBDIR "${PNG_LIBRARY}") |
|
175 set(pascal_flags "-k${PNG_LIBDIR}/libpng.a" ${pascal_flags}) |
|
176 endif() |
|
177 else() |
|
178 message(STATUS "PNG library not found, switching to screenshots in BMP format") |
|
179 endif() |
|
180 |
|
181 set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project}) |
|
182 |
|
183 |
|
184 IF(NOT APPLE) |
|
185 #here is the command for standard executables or for shared library |
|
186 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}" |
|
187 COMMAND "${fpc_executable}" |
|
188 ARGS ${fpc_flags} |
|
189 MAIN_DEPENDENCY ${hwengine_project} |
|
190 DEPENDS ${engine_sources} |
|
191 ) |
|
192 ELSE() |
195 #these are the dependencies for building a universal binary on Mac OS X |
193 #these are the dependencies for building a universal binary on Mac OS X |
196 foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build}) |
194 foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build}) |
197 set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list}) |
195 set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list}) |
198 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" |
196 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" |
199 COMMAND "${pascal_compiler}" |
197 COMMAND "${fpc_executable}" |
200 ARGS ${pascal_compiler_flags} -ohwengine.${build_arch} -P${build_arch} |
198 ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch} |
201 MAIN_DEPENDENCY ${hwengine_project} |
199 MAIN_DEPENDENCY ${hwengine_project} |
202 DEPENDS ${engine_sources} |
200 DEPENDS ${engine_sources} |
203 ) |
201 ) |
204 add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}") |
202 add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}") |
205 endforeach() |
203 endforeach() |