]> git.jsancho.org Git - lugaru.git/blob - CMakeLists.txt
Switch to using «The Lean Mean C++ Option Parser»
[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
8 set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source")
9
10
11 ### CMake config
12
13 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 --std=c++11")
14 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wno-parentheses -g -pg --std=c++11")
15 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -Wno-parentheses -O2 -std=c++11")
16
17 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
18     set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
19 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
20
21 if(APPLE)
22     set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX")
23     set(CMAKE_OSX_DEPLOYMENT_TARGET "10.10" CACHE STRING
24         "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value")
25     set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.10.sdk" CACHE PATH
26         "The product will be built against the headers and libraries located inside the indicated SDK.")
27 endif(APPLE)
28
29 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
30
31
32 ### Sources
33
34 set(LUGARU_SRCS
35     ${SRCDIR}/main.cpp
36     ${SRCDIR}/Frustum.cpp
37     ${SRCDIR}/Account.cpp
38     ${SRCDIR}/ConsoleCmds.cpp
39     ${SRCDIR}/Game.cpp
40     ${SRCDIR}/GameDraw.cpp
41     ${SRCDIR}/GameInitDispose.cpp
42     ${SRCDIR}/GameTick.cpp
43     ${SRCDIR}/Globals.cpp
44     ${SRCDIR}/Lights.cpp
45     ${SRCDIR}/Menu.cpp
46     ${SRCDIR}/Models.cpp
47     ${SRCDIR}/Objects.cpp
48     ${SRCDIR}/pack.c
49     ${SRCDIR}/Person.cpp
50     ${SRCDIR}/private.c
51     ${SRCDIR}/Quaternions.cpp
52     ${SRCDIR}/Skeleton.cpp
53     ${SRCDIR}/Skybox.cpp
54     ${SRCDIR}/Sprite.cpp
55     ${SRCDIR}/Terrain.cpp
56     ${SRCDIR}/Texture.cpp
57     ${SRCDIR}/Text.cpp
58     ${SRCDIR}/ImageIO.cpp
59     ${SRCDIR}/unpack.c
60     ${SRCDIR}/Weapons.cpp
61     ${SRCDIR}/openal_wrapper.cpp
62     ${SRCDIR}/Input.cpp
63     ${SRCDIR}/Settings.cpp
64     ${SRCDIR}/Stereo.cpp
65     ${SRCDIR}/Animation.cpp
66     ${SRCDIR}/Sounds.cpp
67     ${SRCDIR}/Awards.cpp
68 )
69
70 set(LUGARU_H
71     ${SRCDIR}/Frustum.h
72     ${SRCDIR}/Account.h
73     ${SRCDIR}/ConsoleCmds.h
74     ${SRCDIR}/Game.h
75     ${SRCDIR}/Lights.h
76     ${SRCDIR}/Menu.h
77     ${SRCDIR}/Models.h
78     ${SRCDIR}/Objects.h
79     ${SRCDIR}/Person.h
80     ${SRCDIR}/PhysicsMath.h
81     ${SRCDIR}/Quaternions.h
82     ${SRCDIR}/Random.h
83     ${SRCDIR}/Skeleton.h
84     ${SRCDIR}/Skybox.h
85     ${SRCDIR}/Sprite.h
86     ${SRCDIR}/ImageIO.h
87     ${SRCDIR}/Terrain.h
88     ${SRCDIR}/Texture.h
89     ${SRCDIR}/Text.h
90     ${SRCDIR}/Weapons.h
91     ${SRCDIR}/Input.h
92     ${SRCDIR}/binio.h
93     ${SRCDIR}/openal_wrapper.h
94     ${SRCDIR}/optionparser.h
95     ${SRCDIR}/gamegl.h
96     ${SRCDIR}/glstubs.h
97     ${SRCDIR}/private.h
98     ${SRCDIR}/Settings.h
99     ${SRCDIR}/Stereo.h
100     ${SRCDIR}/Animation.h
101     ${SRCDIR}/Sounds.h
102 )
103
104 if(UNIX)
105     set(LUGARU_SRCS
106         ${LUGARU_SRCS}
107         ${SRCDIR}/MacCompatibility.cpp
108     )
109     set(LUGARU_H
110         ${LUGARU_H}
111         ${SRCDIR}/MacCompatibility.h
112     )
113 endif(UNIX)
114
115 if(WIN32)
116     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
117                        COMMAND ${CMAKE_RC_COMPILER}
118                        -I${SRCDIR}/win-res
119                        -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
120                        -i${SRCDIR}/win-res/Lugaru.rc
121                        DEPENDS ${SRCDIR}/win-res/Lugaru.rc
122     )
123
124     # FIXME: get rid of this.
125     set(LUGARU_SRCS
126         ${LUGARU_SRCS}
127         ${SRCDIR}/WinDefs.cpp)
128
129     set(LUGARU_H
130         ${LUGARU_H}
131         ${SRCDIR}/WinDefs.h
132         ${SRCDIR}/win-res/resource.h)
133 endif(WIN32)
134
135 if(APPLE)
136     set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
137 endif(APPLE)
138
139
140 ### Dependencies
141
142 find_package(OpenGL REQUIRED)
143
144 # Windows is funky about OpenAL detection
145 if(WIN32)
146     pkg_check_modules(OPENAL openal REQUIRED)
147     set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
148 else(WIN32)
149     find_package(OpenAL REQUIRED)
150 endif(WIN32)
151
152 find_package(sdl2 REQUIRED)
153 find_package(PNG REQUIRED)
154 find_package(JPEG REQUIRED)
155 find_package(ZLIB REQUIRED)
156 find_package(OggVorbis REQUIRED)
157
158 include_directories(
159     ${OPENAL_INCLUDE_DIR}
160     ${JPEG_INCLUDE_DIR}
161     ${PNG_INCLUDE_DIR}
162     ${ZLIB_INCLUDE_DIR}
163     ${OPENGL_INCLUDE_DIR}
164     ${SDL2_INCLUDE_DIRS}
165     ${VORBISFILE_INCLUDE_DIR}
166     ${OGG_INCLUDE_DIR}
167     ${CMAKE_SOURCE_DIR}/Source
168 )
169
170 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
171
172
173 ### Definitions
174
175 if(WIN32)
176     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj)
177 else(WIN32)
178     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
179 endif(WIN32)
180
181 target_link_libraries(lugaru ${LUGARU_LIBS})
182
183 if(WIN32)
184     add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
185     if(MINGW)
186         # An alternative would be to use _WIN32 consistently instead of WIN32
187         add_definitions(-DWIN32)
188     endif(MINGW)
189 else(WIN32)
190     add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
191 endif(WIN32)
192
193
194 ### Installation
195
196 if(APPLE)
197     set(APPS_ROOT "${CMAKE_INSTALL_PREFIX}/Lugaru.app")
198     set(APPS_BIN "${APPS_ROOT}/Contents/MacOS")
199     set(APPS_DATA "${APPS_ROOT}/Contents/Resources")
200 endif(APPLE)
201
202 if(WIN32)
203     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
204     if(MINGW)
205         # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
206         set(LIBGCC_S libgcc_s_sjlj-1.dll)
207         if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
208             set(LIBGCC_S libgcc_s_seh-1.dll)
209         endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
210         # FIXME: Filter out unneeded DLLs when building against some internal deps
211         set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
212         install(FILES ${DLL_ROOT}/${LIBGCC_S}
213                       ${DLL_ROOT}/libjpeg-62.dll
214                       ${DLL_ROOT}/libogg-0.dll
215                       ${DLL_ROOT}/libpng16-16.dll
216                       ${DLL_ROOT}/libstdc++-6.dll
217                       ${DLL_ROOT}/libvorbis-0.dll
218                       ${DLL_ROOT}/libvorbisfile-3.dll
219                       ${DLL_ROOT}/libwinpthread-1.dll
220                       ${DLL_ROOT}/OpenAL32.dll
221                       ${DLL_ROOT}/SDL2.dll
222                       ${DLL_ROOT}/zlib1.dll
223                 DESTINATION ${CMAKE_INSTALL_PREFIX})
224     endif(MINGW)
225 else(WIN32)
226     if(APPLE)
227         set(CMAKE_INSTALL_PREFIX "${APPS_BIN}")
228         install(FILES ${SRCDIR}/mac-res/lugaru.icns DESTINATION ${APPS_DATA})
229         install(FILES ${SRCDIR}/mac-res/Info.plist DESTINATION ${APPS_ROOT}/Contents)
230     endif(APPLE)
231     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
232 endif(WIN32)
233
234 if(NOT APPLE)
235     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
236     install(FILES ${CMAKE_SOURCE_DIR}/README.md
237                   ${CMAKE_SOURCE_DIR}/COPYING.txt
238                   ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
239             DESTINATION ${CMAKE_INSTALL_PREFIX})
240 endif(NOT APPLE)
241
242 if(APPLE)
243     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${APPS_ROOT})
244 endif(APPLE)