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