]> git.jsancho.org Git - lugaru.git/blob - CMakeLists.txt
Drop unnecessary USE_OPENAL and USE_SDL defines
[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}/Frustum.cpp
36     ${SRCDIR}/Account.cpp
37     ${SRCDIR}/Game.cpp
38     ${SRCDIR}/GameDraw.cpp
39     ${SRCDIR}/GameInitDispose.cpp
40     ${SRCDIR}/GameTick.cpp
41     ${SRCDIR}/Globals.cpp
42     ${SRCDIR}/Lights.cpp
43     ${SRCDIR}/Menu.cpp
44     ${SRCDIR}/Models.cpp
45     ${SRCDIR}/Objects.cpp
46     ${SRCDIR}/pack.c
47     ${SRCDIR}/Person.cpp
48     ${SRCDIR}/private.c
49     ${SRCDIR}/Quaternions.cpp
50     ${SRCDIR}/Skeleton.cpp
51     ${SRCDIR}/Skybox.cpp
52     ${SRCDIR}/Sprite.cpp
53     ${SRCDIR}/Terrain.cpp
54     ${SRCDIR}/Texture.cpp
55     ${SRCDIR}/Text.cpp
56     ${SRCDIR}/TGALoader.cpp
57     ${SRCDIR}/unpack.c
58     ${SRCDIR}/Weapons.cpp
59     ${SRCDIR}/OpenGL_Windows.cpp
60     ${SRCDIR}/openal_wrapper.cpp
61     ${SRCDIR}/Input.cpp
62     ${SRCDIR}/Settings.cpp
63     ${SRCDIR}/Stereo.cpp
64     ${SRCDIR}/Animation.cpp
65     ${SRCDIR}/Sounds.cpp
66     ${SRCDIR}/Awards.cpp
67 )
68
69 set(LUGARU_H
70     ${SRCDIR}/Frustum.h
71     ${SRCDIR}/Account.h
72     ${SRCDIR}/Game.h
73     ${SRCDIR}/Lights.h
74     ${SRCDIR}/Menu.h
75     ${SRCDIR}/Models.h
76     ${SRCDIR}/Objects.h
77     ${SRCDIR}/Person.h
78     ${SRCDIR}/PhysicsMath.h
79     ${SRCDIR}/Quaternions.h
80     ${SRCDIR}/Random.h
81     ${SRCDIR}/Skeleton.h
82     ${SRCDIR}/Skybox.h
83     ${SRCDIR}/Sprite.h
84     ${SRCDIR}/TGALoader.h
85     ${SRCDIR}/Terrain.h
86     ${SRCDIR}/Texture.h
87     ${SRCDIR}/Text.h
88     ${SRCDIR}/Weapons.h
89     ${SRCDIR}/Input.h
90     ${SRCDIR}/alstubs.h
91     ${SRCDIR}/binio.h
92     ${SRCDIR}/openal_wrapper.h
93     ${SRCDIR}/gamegl.h
94     ${SRCDIR}/glstubs.h
95     ${SRCDIR}/private.h
96     ${SRCDIR}/Settings.h
97     ${SRCDIR}/Stereo.h
98     ${SRCDIR}/Animation.h
99     ${SRCDIR}/Sounds.h
100 )
101
102 if(UNIX)
103     set(LUGARU_SRCS
104         ${LUGARU_SRCS}
105         ${SRCDIR}/MacCompatibility.cpp
106     )
107     set(LUGARU_H
108         ${LUGARU_H}
109         ${SRCDIR}/MacCompatibility.h
110     )
111 endif(UNIX)
112
113 if(WIN32)
114     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
115                        COMMAND ${CMAKE_RC_COMPILER}
116                        -I${SRCDIR}/win-res
117                        -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
118                        -i${SRCDIR}/win-res/Lugaru.rc
119                        DEPENDS ${SRCDIR}/win-res/Lugaru.rc
120     )
121
122     # FIXME: get rid of this.
123     set(LUGARU_SRCS
124         ${LUGARU_SRCS}
125         ${SRCDIR}/WinDefs.cpp)
126
127     set(LUGARU_H
128         ${LUGARU_H}
129         ${SRCDIR}/WinDefs.h
130         ${SRCDIR}/win-res/resource.h)
131 endif(WIN32)
132
133 if(APPLE)
134     set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
135 endif(APPLE)
136
137
138 ### Dependencies
139
140 find_package(OpenGL REQUIRED)
141
142 # Windows is funky about OpenAL detection
143 if(WIN32)
144     pkg_check_modules(OPENAL openal REQUIRED)
145     set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
146 else(WIN32)
147     find_package(OpenAL REQUIRED)
148 endif(WIN32)
149
150 find_package(sdl2 REQUIRED)
151 find_package(PNG REQUIRED)
152 find_package(JPEG REQUIRED)
153 find_package(ZLIB REQUIRED)
154 find_package(OggVorbis REQUIRED)
155
156 include_directories(
157     ${OPENAL_INCLUDE_DIR}
158     ${JPEG_INCLUDE_DIR}
159     ${PNG_INCLUDE_DIR}
160     ${ZLIB_INCLUDE_DIR}
161     ${OPENGL_INCLUDE_DIR}
162     ${SDL2_INCLUDE_DIRS}
163     ${VORBISFILE_INCLUDE_DIR}
164     ${OGG_INCLUDE_DIR}
165     ${CMAKE_SOURCE_DIR}/Source
166 )
167
168 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
169
170
171 ### Definitions
172
173 if(WIN32)
174     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj)
175 else(WIN32)
176     add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
177 endif(WIN32)
178
179 target_link_libraries(lugaru ${LUGARU_LIBS})
180
181 if(WIN32)
182     add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
183     if(MINGW)
184         # An alternative would be to use _WIN32 consistently instead of WIN32
185         add_definitions(-DWIN32)
186     endif(MINGW)
187 else(WIN32)
188     add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
189 endif(WIN32)
190
191
192 ### Installation
193
194 if(APPLE)
195     set(APPS_ROOT "${CMAKE_INSTALL_PREFIX}/Lugaru.app")
196     set(APPS_BIN "${APPS_ROOT}/Contents/MacOS")
197     set(APPS_DATA "${APPS_ROOT}/Contents/Resources")
198 endif(APPLE)
199
200 if(WIN32)
201     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
202     if(MINGW)
203         # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
204         set(LIBGCC_S libgcc_s_sjlj-1.dll)
205         if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
206             set(LIBGCC_S libgcc_s_seh-1.dll)
207         endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
208         # FIXME: Filter out unneeded DLLs when building against some internal deps
209         set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
210         install(FILES ${DLL_ROOT}/${LIBGCC_S}
211                       ${DLL_ROOT}/libjpeg-62.dll
212                       ${DLL_ROOT}/libogg-0.dll
213                       ${DLL_ROOT}/libpng16-16.dll
214                       ${DLL_ROOT}/libstdc++-6.dll
215                       ${DLL_ROOT}/libvorbis-0.dll
216                       ${DLL_ROOT}/libvorbisfile-3.dll
217                       ${DLL_ROOT}/libwinpthread-1.dll
218                       ${DLL_ROOT}/OpenAL32.dll
219                       ${DLL_ROOT}/SDL2.dll
220                       ${DLL_ROOT}/zlib1.dll
221                 DESTINATION ${CMAKE_INSTALL_PREFIX})
222     endif(MINGW)
223 else(WIN32)
224     if(APPLE)
225         set(CMAKE_INSTALL_PREFIX "${APPS_BIN}")
226         install(FILES ${SRCDIR}/mac-res/lugaru.icns DESTINATION ${APPS_DATA})
227         install(FILES ${SRCDIR}/mac-res/Info.plist DESTINATION ${APPS_ROOT}/Contents)
228     endif(APPLE)
229     install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
230 endif(WIN32)
231
232 if(NOT APPLE)
233     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
234     install(FILES ${CMAKE_SOURCE_DIR}/README.md
235                   ${CMAKE_SOURCE_DIR}/COPYING.txt
236                   ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
237             DESTINATION ${CMAKE_INSTALL_PREFIX})
238 endif(NOT APPLE)
239
240 if(APPLE)
241     install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${APPS_ROOT})
242 endif(APPLE)