3 find_package(SDL_net) |
3 find_package(SDL_net) |
4 find_package(SDL_ttf) |
4 find_package(SDL_ttf) |
5 find_package(SDL_mixer) |
5 find_package(SDL_mixer) |
6 |
6 |
7 include (CheckLibraryExists) |
7 include (CheckLibraryExists) |
8 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10 |
8 |
9 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT) |
9 |
10 if(HAVE_MIXINIT) |
10 enable_language(Pascal) |
11 list(APPEND pascal_flags "-dSDL_MIXER_NEWER") |
|
12 endif() |
|
13 #IMG_Init/IMG_Quit from SDL_image 1.2.8 |
|
14 check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT) |
|
15 if(HAVE_IMGINIT) |
|
16 list(APPEND pascal_flags "-dSDL_IMAGE_NEWER") |
|
17 endif() |
|
18 |
|
19 |
|
20 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc) |
11 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc) |
21 |
12 include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
22 #SOURCE AND PROGRAMS SECTION |
13 |
23 if(${BUILD_ENGINE_LIBRARY}) |
|
24 set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}") |
|
25 set(hwengine_project hwLibrary.pas) |
|
26 else() |
|
27 set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}") |
|
28 set(hwengine_project hwengine.pas) |
|
29 endif() |
|
30 |
|
31 if (APPLE) |
|
32 set(required_fpc_version 2.6) |
|
33 else() |
|
34 set(required_fpc_version 2.2) |
|
35 endif() |
|
36 |
14 |
37 set(engine_sources |
15 set(engine_sources |
38 ${hwengine_project} |
16 SDLh.pas |
|
17 uSinTable.pas |
|
18 uFloat.pas |
|
19 uConsts.pas |
39 LuaPas.pas |
20 LuaPas.pas |
40 PNGh.pas |
21 PNGh.pas |
41 SDLh.pas |
22 uTypes.pas |
|
23 uUtils.pas |
|
24 uVariables.pas |
|
25 uMisc.pas |
|
26 uConsole.pas |
|
27 uDebug.pas |
|
28 uCommands.pas |
|
29 uInputHandler.pas |
|
30 uTextures.pas |
|
31 uRenderUtils.pas |
|
32 uRender.pas |
|
33 uCaptions.pas |
|
34 uLandTexture.pas |
|
35 uIO.pas |
|
36 uChat.pas |
|
37 uPhysFSLayer.pas |
|
38 uStore.pas |
|
39 uSound.pas |
|
40 uRandom.pas |
|
41 uLocale.pas |
|
42 uStats.pas |
|
43 uCursor.pas |
|
44 uVideoRec.pas |
|
45 uAILandMarks.pas |
|
46 adler32.pas |
|
47 uLandTemplates.pas |
|
48 uLandGraphics.pas |
|
49 uLandPainted.pas |
|
50 uLandOutline.pas |
|
51 uLandGenMaze.pas |
|
52 uLandObjects.pas |
|
53 uLand.pas |
|
54 uAmmos.pas |
|
55 |
|
56 uAIMisc.pas |
|
57 uAIActions.pas |
42 uAI.pas |
58 uAI.pas |
43 uAIActions.pas |
59 uWorld.pas |
44 uAILandMarks.pas |
60 uVisualGears.pas |
|
61 uTeams.pas |
|
62 |
|
63 uGearsList.pas |
|
64 uCollisions.pas |
45 uAIAmmoTests.pas |
65 uAIAmmoTests.pas |
46 uAIMisc.pas |
66 uGears.pas |
47 uAmmos.pas |
67 uGame.pas |
48 uCaptions.pas |
|
49 uChat.pas |
|
50 uCollisions.pas |
|
51 uCommands.pas |
|
52 uCommandHandlers.pas |
68 uCommandHandlers.pas |
53 uConsole.pas |
|
54 uConsts.pas |
|
55 uCursor.pas |
|
56 uDebug.pas |
|
57 uFloat.pas |
|
58 uGame.pas |
|
59 uGears.pas |
|
60 uGearsHandlers.pas |
69 uGearsHandlers.pas |
61 uGearsHandlersRope.pas |
70 uGearsHandlersRope.pas |
62 uGearsHedgehog.pas |
71 uGearsHedgehog.pas |
63 uGearsList.pas |
|
64 uGearsRender.pas |
72 uGearsRender.pas |
65 uGearsUtils.pas |
73 uGearsUtils.pas |
66 uIO.pas |
|
67 uInputHandler.pas |
|
68 uLand.pas |
|
69 uLandGenMaze.pas |
|
70 uLandGraphics.pas |
|
71 uLandObjects.pas |
|
72 uLandOutline.pas |
|
73 uLandPainted.pas |
|
74 uLandTemplates.pas |
|
75 uLandTexture.pas |
|
76 uLocale.pas |
|
77 uMisc.pas |
|
78 uPhysFSLayer.pas |
|
79 uRandom.pas |
|
80 uRender.pas |
|
81 uRenderUtils.pas |
|
82 uScript.pas |
74 uScript.pas |
83 uSinTable.pas |
75 hwengine.pas |
84 uSound.pas |
76 |
85 uStats.pas |
|
86 uStore.pas |
|
87 uTeams.pas |
|
88 uTextures.pas |
|
89 uTouch.pas |
|
90 uTypes.pas |
|
91 uUtils.pas |
|
92 uVariables.pas |
|
93 uVideoRec.pas |
|
94 uVisualGears.pas |
|
95 uWorld.pas |
|
96 GSHandlers.inc |
77 GSHandlers.inc |
97 VGSHandlers.inc |
78 VGSHandlers.inc |
98 ArgParsers.inc |
79 ArgParsers.inc |
99 options.inc |
80 options.inc |
100 adler32.pas |
|
101 ${CMAKE_CURRENT_BINARY_DIR}/config.inc |
81 ${CMAKE_CURRENT_BINARY_DIR}/config.inc |
102 ) |
82 ) |
103 |
83 |
104 if(${BUILD_ENGINE_LIBRARY}) |
84 if(${BUILD_ENGINE_LIBRARY}) |
105 message("*** Engine will be built as library (experimental) ***") |
85 message("*** Engine will be built as library (experimental) ***") |
106 list(APPEND pascal_flags "-dHWLIBRARY") |
86 list(APPEND pascal_flags "-dHWLIBRARY") |
107 |
87 endif() |
108 # create position independent code, only required for x68_64 builds, similar to -fPIC |
|
109 if(CMAKE_SIZEOF_VOID_P MATCHES "8") |
|
110 list(APPEND pascal_flags "-Cg") |
|
111 endif(CMAKE_SIZEOF_VOID_P MATCHES "8") |
|
112 |
|
113 # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail |
|
114 if(APPLE AND current_macosx_version VERSION_GREATER "10.5") |
|
115 list(APPEND pascal_flags "-k-no_order_inits") |
|
116 endif() |
|
117 set(destination_dir ${target_library_install_dir}) |
|
118 else(${BUILD_ENGINE_LIBRARY}) |
|
119 set(destination_dir ${target_binary_install_dir}) |
|
120 endif(${BUILD_ENGINE_LIBRARY}) |
|
121 |
|
122 |
88 |
123 include(${CMAKE_MODULE_PATH}/utils.cmake) |
89 include(${CMAKE_MODULE_PATH}/utils.cmake) |
124 |
90 |
125 find_package_or_fail(FreePascal) |
91 if (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.2 OR # older versions are just ancient |
126 |
92 (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.6 AND APPLE)) # because of 64bit and opengl bindings |
127 #when cmake-2.6 support is dropped, this ought to be inside FindFreePascal.cmake |
93 message(FATAL_ERROR "Your FreePascal installation is too old (fpc ${CMAKE_Pascal_COMPILER_VERSION})!") |
128 if (FREEPASCAL_VERSION VERSION_LESS required_fpc_version) |
94 elseif(CMAKE_Pascal_COMPILER_VERSION VERSION_GREATER 2.4) |
129 message(FATAL_ERROR "Freepascal ${FREEPASCAL_VERSION} is too old, minimum version required is ${required_fpc_version}") |
95 #enable INLINE only with a recent version of fpc |
|
96 add_flag_prepend(CMAKE_Pascal_FLAGS_RELEASE -Si) |
130 endif() |
97 endif() |
131 |
98 |
132 |
99 |
133 #DEPENDECIES AND EXECUTABLES SECTION |
100 #DEPENDECIES AND EXECUTABLES SECTION |
134 if(APPLE) |
101 if(APPLE) |
135 string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}") |
102 if(CMAKE_OSX_ARCHITECTURES) |
136 string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}") |
103 #parse this system variable and adjust only the powerpc syntax to be compatible with -P |
137 string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}") |
104 string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}") |
138 |
105 string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}") |
139 if(powerpc_build) |
106 string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}") |
140 set(powerpc_build "powerpc") |
107 if(x86_64_build) |
|
108 add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64) |
|
109 elseif(i386_build) |
|
110 add_flag_prepend(CMAKE_Pascal_FLAGS -Pi386) |
|
111 elseif(powerpc_build) |
|
112 add_flag_prepend(CMAKE_Pascal_FLAGS -Ppowerpc) |
|
113 else() |
|
114 message(FATAL_ERROR "Unknown architecture present in CMAKE_OSX_ARCHITECTURES (${CMAKE_OSX_ARCHITECTURES})") |
|
115 endif() |
|
116 list(LENGTH CMAKE_OSX_ARCHITECTURES num_of_archs) |
|
117 if(num_of_archs GREATER 1) |
|
118 message(${WARNING} "Only one architecture in CMAKE_OSX_ARCHITECTURES is currently supported, picking the first one") |
|
119 endif() |
|
120 elseif(CMAKE_SIZEOF_VOID_P MATCHES "8") |
|
121 #if that variable is not set check if we are on x86_64 and if so force it, else use default |
|
122 add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64) |
141 endif() |
123 endif() |
142 |
124 |
143 #on OSX we need to provide the SDL_main() function when building as executable |
125 #on OSX we need to provide the SDL_main() function when building as executable |
144 if(NOT ${BUILD_ENGINE_LIBRARY}) |
126 if(NOT BUILD_ENGINE_LIBRARY) |
145 #let's look for the installed sdlmain file; if it is not found, let's build our own |
127 add_subdirectory(sdlmain) |
146 find_package(SDL REQUIRED) |
128 list(APPEND HW_LINK_LIBS SDLmain) |
147 #remove the ";-framework Cocoa" from the SDL_LIBRARY variable |
129 add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH}) |
148 string(REGEX REPLACE "(.*);-.*" "\\1" sdl_library_only "${SDL_LIBRARY}") |
|
149 #find libsdmain.a |
|
150 find_file(SDLMAIN_LIB libSDLMain.a PATHS ${sdl_library_only}/Resources/) |
|
151 |
|
152 if(SDLMAIN_LIB MATCHES "SDLMAIN_LIB-NOTFOUND") |
|
153 include_directories(${SDL_INCLUDE_DIR}) |
|
154 add_library (SDLmain STATIC SDLMain.m) |
|
155 #add a dependency to the hwengine target |
|
156 list(APPEND engine_sources SDLmain) |
|
157 set(SDLMAIN_LIB "${LIBRARY_OUTPUT_PATH}/libSDLmain.a") |
|
158 endif() |
|
159 |
|
160 list(APPEND pascal_flags "-k${SDLMAIN_LIB}") |
|
161 endif() |
130 endif() |
162 |
131 |
163 #when you have multiple ld installation make sure you get the one bundled with the compiler |
132 #when sysroot is set, make sure that fpc picks it |
164 get_filename_component(compiler_dir ${CMAKE_C_COMPILER} PATH) |
133 if(CMAKE_OSX_SYSROOT) |
165 list(APPEND pascal_flags "-FD${compiler_dir}") |
134 set(add_flag_append "-XD${CMAKE_OSX_SYSROOT}") |
|
135 endif(CMAKE_OSX_SYSROOT) |
166 endif(APPLE) |
136 endif(APPLE) |
|
137 |
|
138 if(FFMPEG_FOUND) |
|
139 add_subdirectory(avwrapper) |
|
140 list(APPEND HW_LINK_LIBS avwrapper) |
|
141 add_definitions(-dUSE_VIDEO_RECORDING) |
|
142 add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH}) |
|
143 endif() |
167 |
144 |
168 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP") |
145 find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP") |
169 if(PNG_FOUND) |
146 if(PNG_FOUND) |
170 list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path |
147 list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path |
171 get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH) |
148 get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH) |
181 list(APPEND pascal_flags "-Fl${LUA_LIBRARY_DIR}" |
158 list(APPEND pascal_flags "-Fl${LUA_LIBRARY_DIR}" |
182 "-k-L${LUA_LIBRARY_DIR}" |
159 "-k-L${LUA_LIBRARY_DIR}" |
183 "-XLAlua=${LUA_LIBRARY_NAME}") |
160 "-XLAlua=${LUA_LIBRARY_NAME}") |
184 endif() |
161 endif() |
185 |
162 |
186 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6 |
163 |
187 if(FREEPASCAL_VERSION VERSION_LESS "2.6") |
164 if(NOT PHYSFS_FOUND) |
188 #under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation |
165 add_definitions(-dPHYSFS_INTERNAL) |
189 if(UNIX) |
166 list(APPEND HW_LINK_LIBS physfs) |
190 set(SAFE_BUILD_TOOL $(MAKE)) |
167 #-XLA is a beta fpc flag that renames libraries before passing them to the linker |
191 else() |
168 #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements |
192 set(SAFE_BUILD_TOOL ${CMAKE_BUILD_TOOL}) |
169 #(should be harmless on other platforms) |
|
170 add_flag_append(CMAKE_Pascal_FLAGS "-XLAphysfs=${physfs_output_name}") |
|
171 endif() |
|
172 list(APPEND HW_LINK_LIBS physlayer) |
|
173 |
|
174 #Mix_Init/Mix_Quit from SDL_mixer 1.2.10 |
|
175 check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT) |
|
176 if(HAVE_MIXINIT) |
|
177 add_definitions(-dSDL_MIXER_NEWER) |
|
178 endif(HAVE_MIXINIT) |
|
179 |
|
180 #IMG_Init/IMG_Quit from SDL_image 1.2.8 |
|
181 check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT) |
|
182 if(HAVE_IMGINIT) |
|
183 add_definitions(-dSDL_IMAGE_NEWER) |
|
184 endif(HAVE_IMGINIT) |
|
185 |
|
186 #needs to be last |
|
187 add_definitions(-dDEBUGFILE) |
|
188 |
|
189 #SOURCE AND PROGRAMS SECTION |
|
190 if(BUILD_ENGINE_LIBRARY) |
|
191 message(${WARNING} "Engine will be built as library (experimental)") |
|
192 if(APPLE AND current_macosx_version VERSION_GREATER "10.5") |
|
193 # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail |
|
194 add_flag_prepend(CMAKE_Pascal_FLAGS "-k-no_order_inits") |
193 endif() |
195 endif() |
194 add_custom_target(ENGINECLEAN COMMAND ${SAFE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") |
196 |
195 endif() |
197 #workaround for missing <TARGET> support during object generation |
196 |
198 set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}") |
197 |
199 set(destination_dir ${target_library_install_dir}) |
198 if(${FFMPEG_FOUND}) |
200 add_flag_prepend(CMAKE_Pascal_FLAGS "-o${LIBRARY_OUTPUT_PATH}/${engine_output_name}") |
199 list(APPEND pascal_flags "-dUSE_VIDEO_RECORDING") |
201 |
200 |
202 add_definitions(-dHWLIBRARY) |
201 # TODO: this check is only for SDL < 2 |
203 add_library(hwengine SHARED ${engine_sources} hwLibrary.pas) |
202 # fpc will take care of linking but we need to have this library installed |
|
203 find_package(GLUT REQUIRED) |
|
204 |
|
205 include_directories(${FFMPEG_INCLUDE_DIR}) |
|
206 add_library(avwrapper avwrapper.c) |
|
207 #TODO: find good VERSION and SOVERSION values |
|
208 target_link_libraries(avwrapper ${FFMPEG_LIBRARIES}) |
|
209 install(TARGETS avwrapper RUNTIME DESTINATION ${target_binary_install_dir} |
|
210 LIBRARY DESTINATION ${target_library_install_dir} |
|
211 ARCHIVE DESTINATION ${target_library_install_dir}) |
|
212 endif() |
|
213 |
|
214 |
|
215 set(fpc_flags ${pascal_flags} ${hwengine_project}) |
|
216 |
|
217 if(NOT APPLE) |
|
218 #here is the command for standard executables or for shared library |
|
219 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" |
|
220 COMMAND "${FREEPASCAL_EXECUTABLE}" |
|
221 ARGS ${fpc_flags} -o${engine_output_name} |
|
222 DEPENDS ${engine_sources} |
|
223 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
|
224 ) |
|
225 else() |
204 else() |
226 #these are the dependencies for building a universal binary on Mac OS X |
205 # no need to change name here because target has same name |
227 foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build}) |
206 set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}") |
228 list(APPEND lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}") |
207 set(destination_dir ${target_binary_install_dir}) |
229 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" |
208 add_executable(hwengine ${engine_sources}) |
230 COMMAND "${FREEPASCAL_EXECUTABLE}" |
209 endif() |
231 ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch} |
210 |
232 DEPENDS ${engine_sources} |
211 #even though not actually used, this will trigger relink if any lib changes |
233 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
212 target_link_libraries(hwengine ${HW_LINK_LIBS}) |
234 ) |
|
235 add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}") |
|
236 add_custom_command(TARGET hwengine.${build_arch} POST_BUILD |
|
237 COMMAND "install_name_tool" |
|
238 ARGS -id @executable_path/../Frameworks/${engine_output_name} |
|
239 ${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch} |
|
240 ) |
|
241 endforeach() |
|
242 |
|
243 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" |
|
244 COMMAND "lipo" |
|
245 ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/${engine_output_name} |
|
246 DEPENDS ${lipo_args_list} |
|
247 ) |
|
248 endif() |
|
249 |
|
250 |
|
251 add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}") |
|
252 |
|
253 #when system Lua is not found we need to compile it before engine |
|
254 if(NOT LUA_FOUND) |
|
255 add_dependencies(hwengine lua) |
|
256 endif() |
|
257 |
|
258 # same for physfs |
|
259 if(NOT PHYSFS_FOUND) |
|
260 add_dependencies(hwengine physfs) |
|
261 endif() |
|
262 |
|
263 add_dependencies(hwengine physlayer) |
|
264 |
|
265 #when ffmpeg/libav is found we need to compile it before engine |
|
266 #TODO: convert avwrapper to .pas unit so we can skip this step |
|
267 if(${FFMPEG_FOUND}) |
|
268 add_dependencies(hwengine avwrapper) |
|
269 endif() |
|
270 |
|
271 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6 |
|
272 if((FREEPASCAL_VERSION VERSION_LESS "2.6") AND (NOT ${FFMPEG_FOUND})) |
|
273 add_dependencies(hwengine ENGINECLEAN) |
|
274 endif() |
|
275 |
213 |
276 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir}) |
214 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir}) |