speed-dreams-code/CMakeLists.txt
Xavier Del Campo Romero 2e250d0b91
Revamp Debian and NSIS packaging
The existing scripts for Debian and NSIS packaging were too complex and
dealt unnecessarily with lower level details that should be already
handled by CMake and CPack.

- Packaging-related scripts have been moved to the new cpack/ directory.
There, CPack variables common to all generators are defined in
cpack/common.cmake, and then generator-specific variables are defined
independently (e.g.: cpack/debian.cmake and cpack/nsis.cmake).

- Packaging is now optionally done at a second stage, by running
`cpack -G <generator>` on the build directory. This removes the
requirement to branch based on the system name, and instead all CPack
variables are assigned unconditionally.

- Since now only one version of the game is packaged, there is no need
to maintain the complex scripts in packaging/ and packaging/windows that
used to deal with all variants (e.g.: "wip-cars-and-tracks",
"hq-cars-and-tracks", etc.).

- The use of CPACK_NSIS_EXTRA_INSTALL_COMMANDS,
CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS and CPACK_NSIS_CREATE_ICONS_EXTRA
should not be required, let alone modifying the HKLM registry manually,
since CPack already provides everything required to set up the
installer, the uninstaller and shortcuts.

- $INSTDIR is not required, since NSIS would already prepend the
target installation directory.

- PROJECT_VERSION_METADATA is not a standard CMake variable.
CMAKE_PROJECT_VERSION_TWEAK is instead meant for this purpose. [1]

- OPTION_PACKAGING and OPTION_ALL_IN_ONE_PACKAGING were removed since
packaging will always be available, yet optional. Packagers must then
run CPack on a second stage, as described above.

- Outdated comments were removed to avoid confusion.

TODO:

- Add shortcut to track editor on NSIS.

- dmg packaging was not revamped because of lacking compatible
hardware, but still it has been moved to cpack/dmg.cmake.

- Windows portable packaging (OPTION_PORTABLE_PACKAGING) has been left
out since it required 7z and relied on several hacks to work.
Furthermore, portable versions of the game were already not released on
the latest release, either. [2]

[1]: https://cmake.org/cmake/help/latest/variable/CMAKE_PROJECT_VERSION_TWEAK.html
[2]: https://sourceforge.net/projects/speed-dreams/files/2.3.0/
2025-01-12 22:47:36 +01:00

148 lines
4.6 KiB
CMake

#CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
CMAKE_MINIMUM_REQUIRED(VERSION 3.12 FATAL_ERROR)
# Speed Dreams project
PROJECT(speed-dreams-2 VERSION 2.3.0
HOMEPAGE_URL "https://www.speed-dreams.net/"
)
MESSAGE(STATUS CMAKE_VERSION = "${CMAKE_VERSION}")
IF(POLICY CMP0003)
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(POLICY CMP0003)
IF(POLICY CMP0048)
CMAKE_POLICY(SET CMP0048 NEW)
ENDIF(POLICY CMP0048)
IF(POLICY CMP0056)
CMAKE_POLICY(SET CMP0056 NEW)
ENDIF(POLICY CMP0056)
IF(POLICY CMP0066)
CMAKE_POLICY(SET CMP0066 NEW)
ENDIF(POLICY CMP0066)
IF(POLICY CMP0072)
CMAKE_POLICY(SET CMP0072 NEW)
ENDIF(POLICY CMP0072)
IF(APPLE)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED True)
ENDIF(APPLE)
option(SD_ASSUME_DATADIR "Assume default directory for speed-dreams-data if not found")
set(data_version 2.3.0)
find_package(speed-dreams-data ${data_version})
if(NOT SD_DATADIR)
if(SD_ASSUME_DATADIR)
include(GNUInstallDirs)
set(SD_DATADIR ${CMAKE_INSTALL_DATADIR}/games/speed-dreams-2)
set(SD_DATADIR_ABS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/games/speed-dreams-2)
message(STATUS "Data directory: ${SD_DATADIR_ABS} (assumed)")
set(SD_HAS_DATADIR true)
else()
message(WARNING "Data directory not found or incompatible with version "
"${data_version}. Speed Dreams should still "
"be able to build, but it might not run successfully. "
"If speed-dreams-data has been installed to a non-standard location, "
"please add -DCMAKE_PREFIX_PATH=<data-dir> to the command line to "
"find it.")
endif()
else()
message(STATUS "Data directory: ${SD_DATADIR_ABS}")
set(SD_HAS_DATADIR true)
endif()
INCLUDE(cmake/macros.cmake)
INCLUDE(cmake/checks.cmake)
CHECK_HEADERS_H()
CHECK_FUNCTIONS()
CHECK_LIBRARIES()
execute_process(
COMMAND git describe --tags --dirty
RESULT_VARIABLE result
OUTPUT_VARIABLE VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT result EQUAL 0)
set(VERSION "undefined-version")
endif()
set(VERSION_LONG ${VERSION})
# CMAKE_PROJECT_VERSION_TWEAK is used by NSIS packagers
# its what comes after the '-' sign (if anything)
# ie: in tag '2.2.2-rc1' CMAKE_PROJECT_VERSION_TWEAK should be '-rc1'
STRING(FIND "${VERSION}" "-" _METADATA_INDEX)
IF(NOT ${_METADATA_INDEX} EQUAL -1)
STRING(SUBSTRING ${VERSION} ${_METADATA_INDEX} -1 CMAKE_PROJECT_VERSION_TWEAK)
ELSE()
SET(CMAKE_PROJECT_VERSION_TWEAK)
ENDIF()
#MESSAGE(STATUS "CMAKE_PROJECT_VERSION_TWEAK ${CMAKE_PROJECT_VERSION_TWEAK}")
# Generate config.h
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in.cmake
${CMAKE_CURRENT_BINARY_DIR}/config.h)
# Generate DOxygen configuration file
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/doxygenconfig.in.cmake
${CMAKE_CURRENT_BINARY_DIR}/doxygen_config @ONLY)
# Setup empty GLOBAL lists for robots and modules
SET_PROPERTY(GLOBAL PROPERTY SD_MODULE_LIST "")
SET_PROPERTY(GLOBAL PROPERTY SD_CAR_LIST "")
SET_PROPERTY(GLOBAL PROPERTY SD_TRACK_LIST "")
SET_PROPERTY(GLOBAL PROPERTY SD_ROBOT_LIST "")
SET_PROPERTY(GLOBAL PROPERTY SD_OSG_PLUGIN_LIST "")
SET_PROPERTY(GLOBAL PROPERTY SD_EXE_LIST "")
# Sub-dirs to build ...
ADD_SUBDIRECTORY(src)
IF(MSVC)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/faq/faq.html DESTINATION ./doc)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/userman/how_to_drive.html DESTINATION ./doc)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/userman/images/ DESTINATION ./doc/images/)
ENDIF(MSVC)
# Useful for using an installation of SD as a robot development framework without building it.
# Only do for an in source tree build as INSTALL_SD_CMAKE() doesn't seem to use CMAKE_INSTALL_PREFIX
IF("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
INSTALL_SD_CMAKE()
ENDIF("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
# Must be the last ADD_SUBDIRECTORY for FIXUP_BUNDLE to work
ADD_SUBDIRECTORY(packaging)
# Generate a 'make clobber'-like clobber.sh/.bat script in case of an in-source build.
IF("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
SD_GENERATE_CLOBBER_SCRIPT()
ENDIF("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
# Add an unistall target.
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake" IMMEDIATE @ONLY)
IF(MSVC)
SET(_UNINST_TGT_NAME "UNINSTALL")
ELSE(MSVC)
SET(_UNINST_TGT_NAME "uninstall")
ENDIF(MSVC)
ADD_CUSTOM_TARGET(${_UNINST_TGT_NAME} "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake" )
IF(OPTION_CHECK_CONTENTS)
INCLUDE(cmake/prerelease.cmake)
ENDIF(OPTION_CHECK_CONTENTS)
INCLUDE(cpack/common.cmake)
INCLUDE(CPack)