voxelands/CMakeLists.txt

205 lines
8.0 KiB
CMake

cmake_minimum_required(VERSION 3.5)
# Set policies up to 3.9 since we want to enable the IPO option
if(${CMAKE_VERSION} VERSION_LESS 3.9)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.9)
endif()
# This can be read from ${PROJECT_NAME} after project() is called
project(voxelands)
set(PROJECT_NAME_CAPITALIZED "Voxelands")
# Also remember to set PROTOCOL_VERSION in clientserver.h when releasing
set(VERSION_MAJOR 2404)
set(VERSION_MINOR 00)
set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
# Change to false for releases
set(DEVELOPMENT_BUILD TRUE)
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}")
if(VERSION_EXTRA)
set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}")
elseif(DEVELOPMENT_BUILD)
set(VERSION_STRING "${VERSION_STRING}-dev")
endif()
if (CMAKE_BUILD_TYPE STREQUAL Debug)
# Append "-debug" to version string
set(VERSION_STRING "${VERSION_STRING}-debug")
endif()
MESSAGE(STATUS "*** Will build version ${VERSION_STRING} ***")
# Configuration options
set(DEFAULT_RUN_IN_PLACE FALSE)
if(WIN32)
set(DEFAULT_RUN_IN_PLACE TRUE)
endif()
set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL
"Run directly in source directory structure")
set(BUILD_CLIENT TRUE CACHE BOOL "Build client")
set(BUILD_SERVER FALSE CACHE BOOL "Build server")
# set(BUILD_UNITTESTS TRUE CACHE BOOL "Build unittests")
# set(BUILD_BENCHMARKS FALSE CACHE BOOL "Build benchmarks")
# conf options for building fresh voxelands.icns from voxelands.svg if a new icon is made.
set(REBUILD_ICNS FALSE CACHE BOOL "Rebuild icns from voxelands.svg .")
set(CPU_OPTS FALSE CACHE BOOL "Enable CPU optimizations")
set(CPUTYPE native CACHE STRING "CPU to optimize for")
set(ENABLE_SSP TRUE CACHE BOOL "Enable stack smashing protection")
set(ENABLE_SAFESTACK TRUE CACHE BOOL "Enable SafeStack if supported (LLVM only)")
set(ENABLE_PIE FALSE CACHE BOOL "Produce a Position Independent Executable")
if(NOT CMAKE_BUILD_TYPE)
# Default to release
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
endif()
# Included stuff
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
include(${CMAKE_SOURCE_DIR}/cmake/Modules/misc.cmake)
# This is done here so that relative search paths are more reasnable
find_package(Irrlicht)
#
# Installation
#
if(WIN32)
set(SHAREDIR "data")
set(BINDIR "bin")
set(DOCDIR "doc")
set(EXAMPLE_CONF_DIR ".")
elseif(APPLE)
# random placeholders
set(SHAREDIR "share/${PROJECT_NAME}")
set(BINDIR "bin")
set(DOCDIR "share/doc/${PROJECT_NAME}")
set(EXAMPLE_CONF_DIR ${DOCDIR})
elseif(UNIX) # Linux, BSD etc
if(RUN_IN_PLACE)
set(SHAREDIR "share/${PROJECT_NAME}")
set(BINDIR "bin")
set(DOCDIR "share/doc/${PROJECT_NAME}")
set(MANDIR "share/man")
set(EXAMPLE_CONF_DIR ${DOCDIR})
set(XDG_APPS_DIR "share/applications")
set(APPDATADIR "share/appdata")
set(ICONDIR "share/icons")
set(LOCALEDIR "share/${PROJECT_NAME}/locale")
else()
set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}")
set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
set(EXAMPLE_CONF_DIR ${DOCDIR})
set(XDG_APPS_DIR "${CMAKE_INSTALL_PREFIX}/share/applications")
set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/appdata")
set(ICONDIR "${CMAKE_INSTALL_PREFIX}/share/icons")
set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/locale")
endif()
endif()
install(FILES "README.txt" DESTINATION "${DOCDIR}")
install(FILES "doc/changelog.txt" DESTINATION "${DOCDIR}")
install(FILES "doc/example.cfg" DESTINATION "${DOCDIR}")
if (APPLE)
install(DIRECTORY "libs/" DESTINATION "libs")
endif()
if (UNIX AND NOT APPLE)
install(FILES "doc/voxelands.6" "doc/voxelands-server.6" DESTINATION "${MANDIR}/man6")
install(FILES "misc/freedesktop/voxelands.desktop" DESTINATION "${XDG_APPS_DIR}")
install(FILES "misc/voxelands.appdata.xml" DESTINATION "${APPDATADIR}")
install(FILES "misc/freedesktop/icons/scalable/apps/voxelands.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
install(FILES "misc/freedesktop/icons/192x192/apps/voxelands.png" DESTINATION "${ICONDIR}/hicolor/192x192/apps")
install(FILES "misc/freedesktop/icons/128x128/apps/voxelands.png" DESTINATION "${ICONDIR}/hicolor/128x128/apps")
install(FILES "misc/freedesktop/icons/64x64/apps/voxelands.png" DESTINATION "${ICONDIR}/hicolor/64x64/apps")
install(FILES "misc/freedesktop/icons/48x48/apps/voxelands.png" DESTINATION "${ICONDIR}/hicolor/48x48/apps")
install(FILES "misc/freedesktop/icons/32x32/apps/voxelands.png" DESTINATION "${ICONDIR}/hicolor/32x32/apps")
install(FILES "misc/freedesktop/icons/24x24/apps/voxelands.png" DESTINATION "${ICONDIR}/hicolor/24x24/apps")
install(FILES "misc/freedesktop/icons/22x22/apps/voxelands.png" DESTINATION "${ICONDIR}/hicolor/22x22/apps")
install(FILES "misc/freedesktop/icons/16x16/apps/voxelands.png" DESTINATION "${ICONDIR}/hicolor/16x16/apps")
endif()
#
# Subdirectories
# Be sure to add all relevant definitions above this
#
add_subdirectory(src)
# CPack
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Fun-Focused Free Software Voxel World Game")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VENDOR "rudzik8")
set(CPACK_PACKAGE_CONTACT "Mikita Wisniewski <rudzik8@protonmail.com>")
if(WIN32)
# Include all dynamically linked runtime libaries such as MSVCRxxx.dll
include(InstallRequiredSystemLibraries)
if(RUN_IN_PLACE)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win64")
else()
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
endif()
set(CPACK_GENERATOR ZIP)
else()
set(CPACK_GENERATOR WIX)
set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY ".")
set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}")
set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME})
set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}")
set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/voxelands-icon.ico")
# Supported languages can be found at
# http://wixtoolset.org/documentation/manual/v3/wixui/wixui_localization.html
#set(CPACK_WIX_CULTURES "ar-SA,bg-BG,ca-ES,hr-HR,cs-CZ,da-DK,nl-NL,en-US,et-EE,fi-FI,fr-FR,de-DE")
set(CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_BANNER.BMP")
set(CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/misc/CPACK_WIX_UI_DIALOG.BMP")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/doc/gpl-3.0.txt")
# The correct way would be to include both x32 and x64 into one installer
# and install the appropriate one.
# CMake does not support that, so there are two separate GUID's
#if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# set(CPACK_WIX_UPGRADE_GUID "745A0FB3-5552-44CA-A587-A91C397CCC56")
#else()
# set(CPACK_WIX_UPGRADE_GUID "814A2E2D-2779-4BBD-9ACD-FC3BD51FBBA2")
#endif()
endif()
elseif(APPLE)
# TODO
# see http://cmake.org/Wiki/CMake:CPackPackageGenerators#Bundle_.28OSX_only.29
#
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-osx-${CMAKE_OSX_ARCHITECTURES}")
set(CPACK_PACKAGE_ICON ${CMAKE_CURRENT_SOURCE_DIR}/misc/mac/voxelands.icns)
set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
set(CPACK_BUNDLE_ICON ${CPACK_PACKAGE_ICON})
set(CPACK_BUNDLE_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/misc/mac/Info.plist)
set(CPACK_BUNDLE_STARTUP_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin/Debug/voxelands)
set(CPACK_GENERATOR "Bundle")
else()
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux")
set(CPACK_GENERATOR TGZ)
set(CPACK_SOURCE_GENERATOR TGZ)
SET ( CPACK_DEBIAN_PACKAGE_SECTION "other" )
SET ( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" )
SET ( CPACK_DEBIAN_PACKAGE_MAINTAINER "Mikita Wisniewski <rudzik8@protonmail.com>" )
SET ( CPACK_GENERATOR "DEB;RPM" )
endif()
include(CPack)