]> git.jsancho.org Git - lugaru.git/blob - CMakeLists.txt
CMake: Use correct path for Resources in app root for macOS
[lugaru.git] / CMakeLists.txt
1 project(lugaru)
2
3 cmake_minimum_required(VERSION 3.0)
4 cmake_policy(SET CMP0004 OLD)
5
6 include(FindPkgConfig)
7 include(GNUInstallDirs)
8
9
10 ### Helpers
11
12 set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source")
13
14 if(UNIX AND NOT APPLE)
15     set(LINUX TRUE)
16 endif()
17
18
19 ### CMake config
20
21 if(NOT CMAKE_BUILD_TYPE)
22     set(CMAKE_BUILD_TYPE RelWithDebInfo)
23 endif(NOT CMAKE_BUILD_TYPE)
24 message("CMake build type: ${CMAKE_BUILD_TYPE}")
25
26 set(CMAKE_CXX_FLAGS "-Wall -Wno-parentheses -pedantic --std=c++11 ${CMAKE_CXX_FLAGS}")
27
28 if(APPLE)
29     set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX")
30     set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING
31         "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value")
32     set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.11.sdk" CACHE PATH
33         "The product will be built against the headers and libraries located inside the indicated SDK.")
34 endif(APPLE)
35
36 if(LINUX)
37     option(SYSTEM_INSTALL "Enable system-wide installation, with hardcoded data directory defined with CMAKE_INSTALL_DATADIR" OFF)
38 endif(LINUX)
39
40 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake/Modules/")
41
42
43 ### Sources
44
45 set(LUGARU_SRCS
46     ${SRCDIR}/main.cpp
47     ${SRCDIR}/Animation/Animation.cpp
48     ${SRCDIR}/Animation/Joint.cpp
49     ${SRCDIR}/Animation/Muscle.cpp
50     ${SRCDIR}/Animation/Skeleton.cpp
51     ${SRCDIR}/Audio/openal_wrapper.cpp
52     ${SRCDIR}/Audio/Sounds.cpp
53     ${SRCDIR}/Devtools/ConsoleCmds.cpp
54     ${SRCDIR}/Environment/Lights.cpp
55     ${SRCDIR}/Environment/Skybox.cpp
56     ${SRCDIR}/Environment/Terrain.cpp
57     ${SRCDIR}/Graphic/Models.cpp
58     ${SRCDIR}/Graphic/Sprite.cpp
59     ${SRCDIR}/Graphic/Stereo.cpp
60     ${SRCDIR}/Graphic/Text.cpp
61     ${SRCDIR}/Graphic/Texture.cpp
62     ${SRCDIR}/Level/Awards.cpp
63     ${SRCDIR}/Level/Campaign.cpp
64     ${SRCDIR}/Level/Dialog.cpp
65     ${SRCDIR}/Level/Hotspot.cpp
66     ${SRCDIR}/Math/Frustum.cpp
67     ${SRCDIR}/Math/Quaternions.cpp
68     ${SRCDIR}/Menu/Menu.cpp
69     ${SRCDIR}/Objects/Objects.cpp
70     ${SRCDIR}/Objects/Person.cpp
71     ${SRCDIR}/Objects/Weapons.cpp
72     ${SRCDIR}/User/Account.cpp
73     ${SRCDIR}/User/Settings.cpp
74     ${SRCDIR}/Utils/Folders.cpp
75     ${SRCDIR}/Utils/ImageIO.cpp
76     ${SRCDIR}/Utils/Input.cpp
77     ${SRCDIR}/Utils/pack.c
78     ${SRCDIR}/Utils/private.c
79     ${SRCDIR}/Utils/unpack.c
80     ${SRCDIR}/Game.cpp
81     ${SRCDIR}/GameDraw.cpp
82     ${SRCDIR}/GameInitDispose.cpp
83     ${SRCDIR}/GameTick.cpp
84     ${SRCDIR}/Globals.cpp
85
86 )
87
88 set(LUGARU_H
89     ${SRCDIR}/Animation/Animation.hpp
90     ${SRCDIR}/Animation/Joint.hpp
91     ${SRCDIR}/Animation/Muscle.hpp
92     ${SRCDIR}/Animation/Skeleton.hpp
93     ${SRCDIR}/Audio/openal_wrapper.hpp
94     ${SRCDIR}/Audio/Sounds.hpp
95     ${SRCDIR}/Devtools/ConsoleCmds.hpp
96     ${SRCDIR}/Environment/Lights.hpp
97     ${SRCDIR}/Environment/Skybox.hpp
98     ${SRCDIR}/Environment/Terrain.hpp
99     ${SRCDIR}/Graphic/gamegl.hpp
100     ${SRCDIR}/Graphic/Models.hpp
101     ${SRCDIR}/Graphic/Sprite.hpp
102     ${SRCDIR}/Graphic/Stereo.hpp
103     ${SRCDIR}/Graphic/Text.hpp
104     ${SRCDIR}/Graphic/Texture.hpp
105     ${SRCDIR}/Level/Campaign.hpp
106     ${SRCDIR}/Level/Dialog.hpp
107     ${SRCDIR}/Level/Hotspot.hpp
108     ${SRCDIR}/Math/Frustum.hpp
109     ${SRCDIR}/Math/PhysicsMath.hpp
110     ${SRCDIR}/Math/Quaternions.hpp
111     ${SRCDIR}/Math/Random.hpp
112     ${SRCDIR}/Menu/Menu.hpp
113     ${SRCDIR}/Objects/Objects.hpp
114     ${SRCDIR}/Objects/Person.hpp
115     ${SRCDIR}/Objects/Weapons.hpp
116     ${SRCDIR}/Thirdparty/optionparser.h
117     ${SRCDIR}/User/Account.hpp
118     ${SRCDIR}/User/Settings.hpp
119     ${SRCDIR}/Utils/binio.h
120     ${SRCDIR}/Utils/Folders.hpp
121     ${SRCDIR}/Utils/ImageIO.hpp
122     ${SRCDIR}/Utils/Input.hpp
123     ${SRCDIR}/Utils/private.h
124     ${SRCDIR}/Game.hpp
125
126 )
127
128 if(UNIX)
129     set(LUGARU_SRCS
130         ${LUGARU_SRCS}
131         ${SRCDIR}/MacCompatibility.cpp
132     )
133     set(LUGARU_H
134         ${LUGARU_H}
135         ${SRCDIR}/MacCompatibility.hpp
136     )
137 endif(UNIX)
138
139 if(WIN32)
140     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
141                        COMMAND ${CMAKE_RC_COMPILER}
142                        -I${SRCDIR}/win-res
143                        -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
144                        -i${SRCDIR}/win-res/Lugaru.rc
145                        DEPENDS ${SRCDIR}/win-res/Lugaru.rc
146     )
147
148     # FIXME: get rid of this.
149     set(LUGARU_SRCS
150         ${LUGARU_SRCS}
151         ${SRCDIR}/WinDefs.cpp)
152
153     set(LUGARU_H
154         ${LUGARU_H}
155         ${SRCDIR}/WinDefs.hpp
156         ${SRCDIR}/win-res/resource.hpp)
157 endif(WIN32)
158
159 if(APPLE)
160     set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
161 endif(APPLE)
162
163
164 ### Dependencies
165
166 find_package(OpenGL REQUIRED)
167
168 # Windows is funky about OpenAL detection
169 if(WIN32)
170     pkg_check_modules(OPENAL openal REQUIRED)
171     set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
172 else(WIN32)
173     find_package(OpenAL REQUIRED)
174 endif(WIN32)
175
176 # macOS has problems with using pkgconfig to find SDL2
177 if(APPLE)
178     find_package(sdl2 REQUIRED)
179 else(APPLE)
180     pkg_check_modules(SDL2 sdl2 REQUIRED)
181 endif(APPLE)
182
183 find_package(PNG REQUIRED)
184 find_package(JPEG REQUIRED)
185 find_package(ZLIB REQUIRED)
186 find_package(OggVorbis REQUIRED)
187
188 include_directories(
189     ${OPENAL_INCLUDE_DIR}
190     ${JPEG_INCLUDE_DIR}
191     ${PNG_INCLUDE_DIR}
192     ${ZLIB_INCLUDE_DIR}
193     ${OPENGL_INCLUDE_DIR}
194     ${SDL2_INCLUDE_DIRS}
195     ${VORBISFILE_INCLUDE_DIR}
196     ${OGG_INCLUDE_DIR}
197     ${CMAKE_SOURCE_DIR}/Source
198 )
199
200 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
201
202
203 ### Definitions
204
205 if(WIN32)
206     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj)
207 else(WIN32)
208     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
209 endif(WIN32)
210
211 target_link_libraries(lugaru ${LUGARU_LIBS})
212
213 if(WIN32)
214     add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
215     if(MINGW)
216         # An alternative would be to use _WIN32 consistently instead of WIN32
217         add_definitions(-DWIN32)
218     endif(MINGW)
219 else(WIN32)
220     add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
221 endif(WIN32)
222
223
224 ### Installation
225
226 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
227     set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
228 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
229
230 # OS-specific installation paths
231
232 set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
233 if(LINUX)
234 endif(LINUX)
235
236 if(APPLE)
237     set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app)
238     set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS)
239     set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Contents/Resources)
240 endif(APPLE)
241
242 # Actual installation instructions
243
244 if(WIN32)
245     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
246     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
247     if(MINGW)
248         # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
249         set(LIBGCC_S libgcc_s_sjlj-1.dll)
250         if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
251             set(LIBGCC_S libgcc_s_seh-1.dll)
252         endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
253         # FIXME: Filter out unneeded DLLs when building against some internal deps
254         set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
255         install(FILES ${DLL_ROOT}/${LIBGCC_S}
256                       ${DLL_ROOT}/libjpeg-62.dll
257                       ${DLL_ROOT}/libogg-0.dll
258                       ${DLL_ROOT}/libpng16-16.dll
259                       ${DLL_ROOT}/libstdc++-6.dll
260                       ${DLL_ROOT}/libvorbis-0.dll
261                       ${DLL_ROOT}/libvorbisfile-3.dll
262                       ${DLL_ROOT}/libwinpthread-1.dll
263                       ${DLL_ROOT}/OpenAL32.dll
264                       ${DLL_ROOT}/SDL2.dll
265                       ${DLL_ROOT}/zlib1.dll
266                 DESTINATION ${CMAKE_INSTALL_PREFIX})
267     endif(MINGW)
268 endif(WIN32)
269
270 if(LINUX)
271     if(SYSTEM_INSTALL)
272         add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
273         set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR})
274         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR})
275         # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder
276         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
277         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata)
278         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
279         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
280         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
281     else(SYSTEM_INSTALL)
282         message("You are building Lugaru without having enabled the SYSTEM_INSTALL option. It will default to looking for the data in the 'Data' directory next to the binary.")
283         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
284         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
285     endif(SYSTEM_INSTALL)
286 endif(LINUX)
287
288 if(APPLE)
289     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
290     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT})
291     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Lugaru.icns DESTINATION ${LUGARU_RESDIR})
292     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents)
293 endif(APPLE)
294
295 # Documentation
296
297 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
298               ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
299               ${CMAKE_SOURCE_DIR}/COPYING.txt
300               ${CMAKE_SOURCE_DIR}/README.md
301               ${CMAKE_SOURCE_DIR}/RELEASE-NOTES.md
302               ${CMAKE_SOURCE_DIR}/Docs/DEVTOOLS.txt
303               ${CMAKE_SOURCE_DIR}/Docs/README.Empire.txt
304               ${CMAKE_SOURCE_DIR}/Docs/README.SevenTasks.txt
305               ${CMAKE_SOURCE_DIR}/Docs/README.Temple.txt
306         DESTINATION ${LUGARU_DOCDIR})