]> git.jsancho.org Git - lugaru.git/blob - CMakeLists.txt
Moved Joint and Muscle classes to their own files
[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}/Game.cpp
51     ${SRCDIR}/GameDraw.cpp
52     ${SRCDIR}/GameInitDispose.cpp
53     ${SRCDIR}/GameTick.cpp
54     ${SRCDIR}/Globals.cpp
55     ${SRCDIR}/Lights.cpp
56     ${SRCDIR}/Menu.cpp
57     ${SRCDIR}/Models.cpp
58     ${SRCDIR}/Objects.cpp
59     ${SRCDIR}/pack.c
60     ${SRCDIR}/Person.cpp
61     ${SRCDIR}/private.c
62     ${SRCDIR}/Quaternions.cpp
63     ${SRCDIR}/Skybox.cpp
64     ${SRCDIR}/Sprite.cpp
65     ${SRCDIR}/Terrain.cpp
66     ${SRCDIR}/Texture.cpp
67     ${SRCDIR}/Text.cpp
68     ${SRCDIR}/ImageIO.cpp
69     ${SRCDIR}/unpack.c
70     ${SRCDIR}/Weapons.cpp
71     ${SRCDIR}/openal_wrapper.cpp
72     ${SRCDIR}/Input.cpp
73     ${SRCDIR}/Settings.cpp
74     ${SRCDIR}/Stereo.cpp
75     ${SRCDIR}/Sounds.cpp
76     ${SRCDIR}/Awards.cpp
77     ${SRCDIR}/Utils/Folders.cpp
78 )
79
80 set(LUGARU_H
81     ${SRCDIR}/Animation/Animation.h
82     ${SRCDIR}/Animation/Joint.h
83     ${SRCDIR}/Animation/Muscle.h
84     ${SRCDIR}/Animation/Skeleton.h
85     ${SRCDIR}/Frustum.h
86     ${SRCDIR}/Account.h
87     ${SRCDIR}/ConsoleCmds.h
88     ${SRCDIR}/Dialog.h
89     ${SRCDIR}/Game.h
90     ${SRCDIR}/Lights.h
91     ${SRCDIR}/Menu.h
92     ${SRCDIR}/Models.h
93     ${SRCDIR}/Objects.h
94     ${SRCDIR}/Person.h
95     ${SRCDIR}/PhysicsMath.h
96     ${SRCDIR}/Quaternions.h
97     ${SRCDIR}/Random.h
98     ${SRCDIR}/Skybox.h
99     ${SRCDIR}/Sprite.h
100     ${SRCDIR}/ImageIO.h
101     ${SRCDIR}/Terrain.h
102     ${SRCDIR}/Texture.h
103     ${SRCDIR}/Text.h
104     ${SRCDIR}/Weapons.h
105     ${SRCDIR}/Input.h
106     ${SRCDIR}/binio.h
107     ${SRCDIR}/openal_wrapper.h
108     ${SRCDIR}/optionparser.h
109     ${SRCDIR}/gamegl.h
110     ${SRCDIR}/private.h
111     ${SRCDIR}/Settings.h
112     ${SRCDIR}/Stereo.h
113     ${SRCDIR}/Sounds.h
114     ${SRCDIR}/Utils/Folders.h
115 )
116
117 if(UNIX)
118     set(LUGARU_SRCS
119         ${LUGARU_SRCS}
120         ${SRCDIR}/MacCompatibility.cpp
121     )
122     set(LUGARU_H
123         ${LUGARU_H}
124         ${SRCDIR}/MacCompatibility.h
125     )
126 endif(UNIX)
127
128 if(WIN32)
129     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
130                        COMMAND ${CMAKE_RC_COMPILER}
131                        -I${SRCDIR}/win-res
132                        -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
133                        -i${SRCDIR}/win-res/Lugaru.rc
134                        DEPENDS ${SRCDIR}/win-res/Lugaru.rc
135     )
136
137     # FIXME: get rid of this.
138     set(LUGARU_SRCS
139         ${LUGARU_SRCS}
140         ${SRCDIR}/WinDefs.cpp)
141
142     set(LUGARU_H
143         ${LUGARU_H}
144         ${SRCDIR}/WinDefs.h
145         ${SRCDIR}/win-res/resource.h)
146 endif(WIN32)
147
148 if(APPLE)
149     set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
150 endif(APPLE)
151
152
153 ### Dependencies
154
155 find_package(OpenGL REQUIRED)
156
157 # Windows is funky about OpenAL detection
158 if(WIN32)
159     pkg_check_modules(OPENAL openal REQUIRED)
160     set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
161 else(WIN32)
162     find_package(OpenAL REQUIRED)
163 endif(WIN32)
164
165 find_package(sdl2 REQUIRED)
166 find_package(PNG REQUIRED)
167 find_package(JPEG REQUIRED)
168 find_package(ZLIB REQUIRED)
169 find_package(OggVorbis REQUIRED)
170
171 include_directories(
172     ${OPENAL_INCLUDE_DIR}
173     ${JPEG_INCLUDE_DIR}
174     ${PNG_INCLUDE_DIR}
175     ${ZLIB_INCLUDE_DIR}
176     ${OPENGL_INCLUDE_DIR}
177     ${SDL2_INCLUDE_DIRS}
178     ${VORBISFILE_INCLUDE_DIR}
179     ${OGG_INCLUDE_DIR}
180     ${CMAKE_SOURCE_DIR}/Source
181 )
182
183 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
184
185
186 ### Definitions
187
188 if(WIN32)
189     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj)
190 else(WIN32)
191     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
192 endif(WIN32)
193
194 target_link_libraries(lugaru ${LUGARU_LIBS})
195
196 if(WIN32)
197     add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
198     if(MINGW)
199         # An alternative would be to use _WIN32 consistently instead of WIN32
200         add_definitions(-DWIN32)
201     endif(MINGW)
202 else(WIN32)
203     add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
204 endif(WIN32)
205
206
207 ### Installation
208
209 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
210     set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
211 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
212
213 # OS-specific installation paths
214
215 set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
216 if(LINUX)
217 endif(LINUX)
218
219 if(APPLE)
220     set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app)
221     set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS)
222     set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Resources)
223 endif(APPLE)
224
225 # Actual installation instructions
226
227 if(WIN32)
228     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
229     if(MINGW)
230         # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
231         set(LIBGCC_S libgcc_s_sjlj-1.dll)
232         if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
233             set(LIBGCC_S libgcc_s_seh-1.dll)
234         endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
235         # FIXME: Filter out unneeded DLLs when building against some internal deps
236         set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
237         install(FILES ${DLL_ROOT}/${LIBGCC_S}
238                       ${DLL_ROOT}/libjpeg-62.dll
239                       ${DLL_ROOT}/libogg-0.dll
240                       ${DLL_ROOT}/libpng16-16.dll
241                       ${DLL_ROOT}/libstdc++-6.dll
242                       ${DLL_ROOT}/libvorbis-0.dll
243                       ${DLL_ROOT}/libvorbisfile-3.dll
244                       ${DLL_ROOT}/libwinpthread-1.dll
245                       ${DLL_ROOT}/OpenAL32.dll
246                       ${DLL_ROOT}/SDL2.dll
247                       ${DLL_ROOT}/zlib1.dll
248                 DESTINATION ${CMAKE_INSTALL_PREFIX})
249     endif(MINGW)
250 endif(WIN32)
251
252 if(LINUX)
253     if(SYSTEM_INSTALL)
254         add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
255         set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR})
256         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR})
257         # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder
258         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
259         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata)
260         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
261         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
262         install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
263     else(SYSTEM_INSTALL)
264         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.")
265         install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
266         install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
267     endif(SYSTEM_INSTALL)
268 endif(LINUX)
269
270 if(APPLE)
271     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
272     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT})
273     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/lugaru.icns DESTINATION ${LUGARU_RESDIR})
274     install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents)
275 endif(APPLE)
276
277 # Documentation
278
279 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
280               ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
281               ${CMAKE_SOURCE_DIR}/COPYING.txt
282               ${CMAKE_SOURCE_DIR}/DEBUG-OPTIONS.txt
283               ${CMAKE_SOURCE_DIR}/README.md
284         DESTINATION ${LUGARU_DOCDIR})