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