3 cmake_minimum_required(VERSION 3.5)
4 cmake_policy(SET CMP0004 OLD)
7 include(GNUInstallDirs)
12 set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source")
14 if(UNIX AND NOT APPLE)
21 if(NOT CMAKE_BUILD_TYPE)
22 set(CMAKE_BUILD_TYPE RelWithDebInfo)
23 endif(NOT CMAKE_BUILD_TYPE)
24 message("CMake build type: ${CMAKE_BUILD_TYPE}")
26 set(CMAKE_CXX_FLAGS "-Wall -Wno-parentheses -pedantic --std=c++11 ${CMAKE_CXX_FLAGS}")
29 set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX")
30 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.10" CACHE STRING
31 "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value")
32 set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.10.sdk" CACHE PATH
33 "The product will be built against the headers and libraries located inside the indicated SDK.")
37 option(SYSTEM_INSTALL "Enable system-wide installation, with hardcoded data directory defined with CMAKE_INSTALL_DATADIR" OFF)
40 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
47 ${SRCDIR}/Animation/Animation.cpp
48 ${SRCDIR}/Animation/Joint.cpp
49 ${SRCDIR}/Animation/Muscle.cpp
50 ${SRCDIR}/Animation/Skeleton.cpp
53 ${SRCDIR}/Campaign.cpp
54 ${SRCDIR}/ConsoleCmds.cpp
58 ${SRCDIR}/GameDraw.cpp
59 ${SRCDIR}/GameInitDispose.cpp
60 ${SRCDIR}/GameTick.cpp
69 ${SRCDIR}/Quaternions.cpp
78 ${SRCDIR}/openal_wrapper.cpp
80 ${SRCDIR}/Settings.cpp
84 ${SRCDIR}/Utils/Folders.cpp
88 ${SRCDIR}/Animation/Animation.h
89 ${SRCDIR}/Animation/Joint.h
90 ${SRCDIR}/Animation/Muscle.h
91 ${SRCDIR}/Animation/Skeleton.h
95 ${SRCDIR}/ConsoleCmds.h
104 ${SRCDIR}/PhysicsMath.h
105 ${SRCDIR}/Quaternions.h
116 ${SRCDIR}/openal_wrapper.h
117 ${SRCDIR}/optionparser.h
123 ${SRCDIR}/Utils/Folders.h
129 ${SRCDIR}/MacCompatibility.cpp
133 ${SRCDIR}/MacCompatibility.h
138 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
139 COMMAND ${CMAKE_RC_COMPILER}
141 -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
142 -i${SRCDIR}/win-res/Lugaru.rc
143 DEPENDS ${SRCDIR}/win-res/Lugaru.rc
146 # FIXME: get rid of this.
149 ${SRCDIR}/WinDefs.cpp)
154 ${SRCDIR}/win-res/resource.h)
158 set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL")
164 find_package(OpenGL REQUIRED)
166 # Windows is funky about OpenAL detection
168 pkg_check_modules(OPENAL openal REQUIRED)
169 set(OPENAL_LIBRARY ${OPENAL_LIBRARIES})
171 find_package(OpenAL REQUIRED)
174 find_package(sdl2 REQUIRED)
175 find_package(PNG REQUIRED)
176 find_package(JPEG REQUIRED)
177 find_package(ZLIB REQUIRED)
178 find_package(OggVorbis REQUIRED)
181 ${OPENAL_INCLUDE_DIR}
185 ${OPENGL_INCLUDE_DIR}
187 ${VORBISFILE_INCLUDE_DIR}
189 ${CMAKE_SOURCE_DIR}/Source
192 set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS})
198 add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj)
200 add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H})
203 target_link_libraries(lugaru ${LUGARU_LIBS})
206 add_definitions(-DBinIO_STDINT_HEADER=<stdint.h>)
208 # An alternative would be to use _WIN32 consistently instead of WIN32
209 add_definitions(-DWIN32)
212 add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=<stdint.h>)
218 if(NOT CMAKE_INSTALL_PREFIX AND WIN32)
219 set(CMAKE_INSTALL_PREFIX "C:/Lugaru")
220 endif(NOT CMAKE_INSTALL_PREFIX AND WIN32)
222 # OS-specific installation paths
224 set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX})
229 set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app)
230 set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS)
231 set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Resources)
234 # Actual installation instructions
237 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX})
238 install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
240 # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows
241 set(LIBGCC_S libgcc_s_sjlj-1.dll)
242 if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64
243 set(LIBGCC_S libgcc_s_seh-1.dll)
244 endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
245 # FIXME: Filter out unneeded DLLs when building against some internal deps
246 set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin)
247 install(FILES ${DLL_ROOT}/${LIBGCC_S}
248 ${DLL_ROOT}/libjpeg-62.dll
249 ${DLL_ROOT}/libogg-0.dll
250 ${DLL_ROOT}/libpng16-16.dll
251 ${DLL_ROOT}/libstdc++-6.dll
252 ${DLL_ROOT}/libvorbis-0.dll
253 ${DLL_ROOT}/libvorbisfile-3.dll
254 ${DLL_ROOT}/libwinpthread-1.dll
255 ${DLL_ROOT}/OpenAL32.dll
257 ${DLL_ROOT}/zlib1.dll
258 DESTINATION ${CMAKE_INSTALL_PREFIX})
264 add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
265 set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR})
266 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR})
267 # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder
268 install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
269 install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata)
270 install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
271 install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps)
272 install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6)
274 message("You are building Lugaru without having enabled the SYSTEM_INSTALL option. It will default to looking for the data in the 'Data' directory next to the binary.")
275 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX})
276 install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX})
277 endif(SYSTEM_INSTALL)
281 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR})
282 install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT})
283 install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/lugaru.icns DESTINATION ${LUGARU_RESDIR})
284 install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents)
289 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS
290 ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt
291 ${CMAKE_SOURCE_DIR}/COPYING.txt
292 ${CMAKE_SOURCE_DIR}/DEBUG-OPTIONS.txt
293 ${CMAKE_SOURCE_DIR}/README.md
294 DESTINATION ${LUGARU_DOCDIR})