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