X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=CMakeLists.txt;h=3ebfe8657eecd8d5de1a8779e8a23639c59a65d7;hb=4d0ec1838440e55f24e8ec9501a62348cd9e2ec3;hp=ca13013ff324551c2cd349a648d866a933cff25b;hpb=2b8be4ae401153dad5448c3d5903692f5757aecd;p=lugaru.git diff --git a/CMakeLists.txt b/CMakeLists.txt index ca13013..ddcbd70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,280 @@ project(lugaru) -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.5) +cmake_policy(SET CMP0004 OLD) + +include(FindPkgConfig) +include(GNUInstallDirs) + +set(SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/Source") + + +### Helper + +if(UNIX AND NOT APPLE) + set(LINUX TRUE) +endif() + + +### CMake config + +set(CMAKE_CXX_FLAGS "-Wall -Wno-parentheses -pedantic --std=c++11 ${CMAKE_CXX_FLAGS}") + +if(APPLE) + set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX") + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.10" CACHE STRING + "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value") + set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.10.sdk" CACHE PATH + "The product will be built against the headers and libraries located inside the indicated SDK.") +endif(APPLE) + +if(LINUX) + option(SYSTEM_INSTALL "Enable system-wide installation, with hardcoded data directory defined with CMAKE_INSTALL_DATADIR" OFF) +endif(LINUX) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") -find_package(OpenAL REQUIRED) -find_package(BZip2 REQUIRED) + + +### Sources + +set(LUGARU_SRCS + ${SRCDIR}/main.cpp + ${SRCDIR}/Animation/Animation.cpp + ${SRCDIR}/Animation/Skeleton.cpp + ${SRCDIR}/Frustum.cpp + ${SRCDIR}/Account.cpp + ${SRCDIR}/ConsoleCmds.cpp + ${SRCDIR}/Dialog.cpp + ${SRCDIR}/Game.cpp + ${SRCDIR}/GameDraw.cpp + ${SRCDIR}/GameInitDispose.cpp + ${SRCDIR}/GameTick.cpp + ${SRCDIR}/Globals.cpp + ${SRCDIR}/Lights.cpp + ${SRCDIR}/Menu.cpp + ${SRCDIR}/Models.cpp + ${SRCDIR}/Objects.cpp + ${SRCDIR}/pack.c + ${SRCDIR}/Person.cpp + ${SRCDIR}/private.c + ${SRCDIR}/Quaternions.cpp + ${SRCDIR}/Skybox.cpp + ${SRCDIR}/Sprite.cpp + ${SRCDIR}/Terrain.cpp + ${SRCDIR}/Texture.cpp + ${SRCDIR}/Text.cpp + ${SRCDIR}/ImageIO.cpp + ${SRCDIR}/unpack.c + ${SRCDIR}/Weapons.cpp + ${SRCDIR}/openal_wrapper.cpp + ${SRCDIR}/Input.cpp + ${SRCDIR}/Settings.cpp + ${SRCDIR}/Stereo.cpp + ${SRCDIR}/Sounds.cpp + ${SRCDIR}/Awards.cpp + ${SRCDIR}/Utils/Folders.cpp +) + +set(LUGARU_H + ${SRCDIR}/Animation/Animation.h + ${SRCDIR}/Animation/Skeleton.h + ${SRCDIR}/Frustum.h + ${SRCDIR}/Account.h + ${SRCDIR}/ConsoleCmds.h + ${SRCDIR}/Dialog.h + ${SRCDIR}/Game.h + ${SRCDIR}/Lights.h + ${SRCDIR}/Menu.h + ${SRCDIR}/Models.h + ${SRCDIR}/Objects.h + ${SRCDIR}/Person.h + ${SRCDIR}/PhysicsMath.h + ${SRCDIR}/Quaternions.h + ${SRCDIR}/Random.h + ${SRCDIR}/Skybox.h + ${SRCDIR}/Sprite.h + ${SRCDIR}/ImageIO.h + ${SRCDIR}/Terrain.h + ${SRCDIR}/Texture.h + ${SRCDIR}/Text.h + ${SRCDIR}/Weapons.h + ${SRCDIR}/Input.h + ${SRCDIR}/binio.h + ${SRCDIR}/openal_wrapper.h + ${SRCDIR}/optionparser.h + ${SRCDIR}/gamegl.h + ${SRCDIR}/private.h + ${SRCDIR}/Settings.h + ${SRCDIR}/Stereo.h + ${SRCDIR}/Sounds.h + ${SRCDIR}/Utils/Folders.h +) + +if(UNIX) + set(LUGARU_SRCS + ${LUGARU_SRCS} + ${SRCDIR}/MacCompatibility.cpp + ) + set(LUGARU_H + ${LUGARU_H} + ${SRCDIR}/MacCompatibility.h + ) +endif(UNIX) + +if(WIN32) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj + COMMAND ${CMAKE_RC_COMPILER} + -I${SRCDIR}/win-res + -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj + -i${SRCDIR}/win-res/Lugaru.rc + DEPENDS ${SRCDIR}/win-res/Lugaru.rc + ) + + # FIXME: get rid of this. + set(LUGARU_SRCS + ${LUGARU_SRCS} + ${SRCDIR}/WinDefs.cpp) + + set(LUGARU_H + ${LUGARU_H} + ${SRCDIR}/WinDefs.h + ${SRCDIR}/win-res/resource.h) +endif(WIN32) + +if(APPLE) + set(PLATFORM_LIBS "-framework Carbon -framework Cocoa -framework OpenGL -framework OpenAL") +endif(APPLE) + + +### Dependencies + +find_package(OpenGL REQUIRED) + +# Windows is funky about OpenAL detection +if(WIN32) + pkg_check_modules(OPENAL openal REQUIRED) + set(OPENAL_LIBRARY ${OPENAL_LIBRARIES}) +else(WIN32) + find_package(OpenAL REQUIRED) +endif(WIN32) + +find_package(sdl2 REQUIRED) find_package(PNG REQUIRED) find_package(JPEG REQUIRED) find_package(ZLIB REQUIRED) -find_package(OpenGL REQUIRED) -find_package(GLU REQUIRED) -find_package(SDL REQUIRED) find_package(OggVorbis REQUIRED) include_directories( - ${OPENAL_INCLUDES} - ${BZIP2_INCLUDE_DIR} - ${JPEG_INCLUDE_DIR} - ${PNG_INCLUDE_DIR} - ${ZLIB_INCLUDE_DIR} - ${OPENGL_INCLUDE_DIR} - ${GLU_INCLUDE_DIR} - ${SDL_INCLUDE_DIR} - ${VORBISFILE_INCLUDE_DIR} - ${OGG_INCLUDE_DIR} - ${CMAKE_SOURCE_DIR}/Source) - -set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${BZIP2_LIBRARIES} ${ZLIB_LIBRARIES} ${SDL_LIBRARY} ${GLU_LIBRARY} ${OPENGL_LIBRARY} ${VORBISFILE_LIBS} ${OGG_LIBS}) - -add_subdirectory(Source) + ${OPENAL_INCLUDE_DIR} + ${JPEG_INCLUDE_DIR} + ${PNG_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIR} + ${OPENGL_INCLUDE_DIR} + ${SDL2_INCLUDE_DIRS} + ${VORBISFILE_INCLUDE_DIR} + ${OGG_INCLUDE_DIR} + ${CMAKE_SOURCE_DIR}/Source +) + +set(LUGARU_LIBS ${OPENAL_LIBRARY} ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARIES} ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} ${VORBISFILE_LIBRARY} ${OGG_LIBRARY} ${PLATFORM_LIBS}) + + +### Definitions + +if(WIN32) + add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H} lugaru_resource.obj) +else(WIN32) + add_executable(lugaru ${LUGARU_SRCS} ${LUGARU_H}) +endif(WIN32) + +target_link_libraries(lugaru ${LUGARU_LIBS}) + +if(WIN32) + add_definitions(-DBinIO_STDINT_HEADER=) + if(MINGW) + # An alternative would be to use _WIN32 consistently instead of WIN32 + add_definitions(-DWIN32) + endif(MINGW) +else(WIN32) + add_definitions(-DPLATFORM_LINUX=1 -DPLATFORM_UNIX=1 -DBinIO_STDINT_HEADER=) +endif(WIN32) + + +### Installation + +if(NOT CMAKE_INSTALL_PREFIX AND WIN32) + set(CMAKE_INSTALL_PREFIX "C:/Lugaru") +endif(NOT CMAKE_INSTALL_PREFIX AND WIN32) + +# OS-specific installation paths + +set(LUGARU_DOCDIR ${CMAKE_INSTALL_PREFIX}) +if(LINUX) +endif(LINUX) + +if(APPLE) + set(LUGARU_APP_ROOT ${CMAKE_INSTALL_PREFIX}/Lugaru.app) + set(LUGARU_BINDIR ${LUGARU_APP_ROOT}/Contents/MacOS) + set(LUGARU_RESDIR ${LUGARU_APP_ROOT}/Resources) +endif(APPLE) + +# Actual installation instructions + +if(WIN32) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru.exe DESTINATION ${CMAKE_INSTALL_PREFIX}) + if(MINGW) + # Based off Mageia/Fedora MinGW toolchain, might not work on other distros or Windows + set(LIBGCC_S libgcc_s_sjlj-1.dll) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") # MinGW64 + set(LIBGCC_S libgcc_s_seh-1.dll) + endif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + # FIXME: Filter out unneeded DLLs when building against some internal deps + set(DLL_ROOT ${CMAKE_FIND_ROOT_PATH}/bin) + install(FILES ${DLL_ROOT}/${LIBGCC_S} + ${DLL_ROOT}/libjpeg-62.dll + ${DLL_ROOT}/libogg-0.dll + ${DLL_ROOT}/libpng16-16.dll + ${DLL_ROOT}/libstdc++-6.dll + ${DLL_ROOT}/libvorbis-0.dll + ${DLL_ROOT}/libvorbisfile-3.dll + ${DLL_ROOT}/libwinpthread-1.dll + ${DLL_ROOT}/OpenAL32.dll + ${DLL_ROOT}/SDL2.dll + ${DLL_ROOT}/zlib1.dll + DESTINATION ${CMAKE_INSTALL_PREFIX}) + endif(MINGW) +endif(WIN32) + +if(LINUX) + if(SYSTEM_INSTALL) + add_definitions(-DDATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}") + set(LUGARU_DOCDIR ${CMAKE_INSTALL_DOCDIR}) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_BINDIR}) + # Trailing '/' is significant, it installs and _renames_ Data/ as the destination folder + install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}) + install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/appdata) + install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications) + install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps) + install(FILES ${CMAKE_SOURCE_DIR}/Dist/lugaru.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6) + else(SYSTEM_INSTALL) + 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.") + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${CMAKE_INSTALL_PREFIX}) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${CMAKE_INSTALL_PREFIX}) + endif(SYSTEM_INSTALL) +endif(LINUX) + +if(APPLE) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/lugaru DESTINATION ${LUGARU_BINDIR}) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/Data DESTINATION ${LUGARU_APP_ROOT}) + install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/lugaru.icns DESTINATION ${LUGARU_RESDIR}) + install(FILES ${CMAKE_SOURCE_DIR}/Dist/OSX/Info.plist DESTINATION ${LUGARU_APP_ROOT}/Contents) +endif(APPLE) + +# Documentation + +install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS + ${CMAKE_SOURCE_DIR}/CONTENT-LICENSE.txt + ${CMAKE_SOURCE_DIR}/COPYING.txt + ${CMAKE_SOURCE_DIR}/DEBUG-OPTIONS.txt + ${CMAKE_SOURCE_DIR}/README.md + DESTINATION ${LUGARU_DOCDIR})