cmake: Get SD_DATADIR from speed-dreams-data package

So far, the game assets were located in the same repository as the game
engine. Since data and engine are split into different repositories, now
this project requires users to assign the CMAKE_PREFIX_PATH variable [1]
to indicate the location, only in the case of non-standard locations.

[1]: https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html
This commit is contained in:
Xavier Del Campo Romero 2024-12-28 14:13:38 +01:00
parent f593eee939
commit cf18241a16
Signed by: xavi
GPG key ID: 84FF3612A9BF43F2
9 changed files with 33 additions and 58 deletions

View file

@ -28,6 +28,20 @@ IF(APPLE)
SET(CMAKE_CXX_STANDARD_REQUIRED True)
ENDIF(APPLE)
set(data_version 2.4.0)
find_package(speed-dreams-data ${data_version})
if(NOT SD_DATADIR)
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.")
else()
message(STATUS "Data directory: ${SD_DATADIR}")
endif()
IF(NOT ${CMAKE_VERSION} VERSION_LESS "3.0.2")
# Speed Dreams project
PROJECT(speed-dreams-2 VERSION 2.4.0)

View file

@ -30,6 +30,22 @@ cmake -B build
cmake --build build/ # Optionally, add -j8 or any other number for faster builds
```
This assumes the
[`speed-dreams-data`](https://forge.a-lec.org/speed-dreams/speed-dreams-data/)
package is already installed on a well-known location. If not, use the
[`CMAKE_PREFIX_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html)
variable to indicate CMake where to locate an **installed** version of the
`speed-dreams-data` package:
```
cmake -B build -DCMAKE_PREFIX_PATH=<path-to-speed-dreams-data>
```
And then build the project as usual.
> If the `speed-dreams-data` package is not found, the game should still be
> able to build, but it would not be able to run.
### Dependencies
#### Debian/Ubuntu

View file

@ -1,11 +0,0 @@
#This file can be distributed with packages such as cars, robots, tracks
#It tries to locate a installed SD version and includes the distributed macro's
SET(SD_PREFIX CACHE PATH "Prefix where Speed Dreams is installed")
SET(SD_DATADIR CACHE PATH "Place where the data is installed")
FIND_FILE(SD_CMAKE_MACROS speed-dreams.cmake PATHS ${SD_PREFIX} ${SD_PREFIX}/${SD_DATADIR} ${SD_DATADIR} /usr /usr/local PATH_SUFFIXES cmake share/cmake share/games/speed-dreams/cmake DOC "Place where Speed Dreams is installed")
IF(NOT SD_CMAKE_MACROS)
MESSAGE(FATAL_ERROR "Didn't find Speed Dreams. Please specify the location with the SD_PREFIX or SD_DATADIR path.")
ENDIF(NOT SD_CMAKE_MACROS)
INCLUDE(${SD_CMAKE_MACROS})

View file

@ -179,7 +179,6 @@
/* Run-time directories */
#define SD_DATADIR "${SD_DATADIR}/"
#define SD_DATADIR_SRC "${PROJECT_SOURCE_DIR}/data/"
#define SD_LIBDIR "${SD_LIBDIR}/"
#define SD_BINDIR "${SD_BINDIR}/"
#define SD_LOCALDIR "${SD_LOCALDIR}/"

View file

@ -454,29 +454,6 @@ MACRO(SD_INSTALL_DIRECTORIES)
ENDMACRO(SD_INSTALL_DIRECTORIES)
# Macro to install CMake config files for SD if in-source build.
IF(IN_SOURCETREE)
MACRO(INSTALL_SD_CMAKE)
INSTALL(CODE
"SET(CUR_DESTDIR \"\$ENV{DESTDIR}\")
IF(CUR_DESTDIR MATCHES \"[^/]\")
STRING(REGEX REPLACE \"^(.*[^/])/*$\" \"\\\\1\" CUR_DESTDIR_CORR \"\${CUR_DESTDIR}\")
ELSE(CUR_DESTDIR MATCHES \"[^/]\")
SET(CUR_DESTDIR_CORR \"\")
ENDIF(CUR_DESTDIR MATCHES \"[^/]\")
FILE(MAKE_DIRECTORY \"\${CUR_DESTDIR_CORR}${SD_DATADIR_ABS}/cmake\")
FILE(WRITE \"\${CUR_DESTDIR_CORR}${SD_DATADIR_ABS}/cmake/speed-dreams.cmake\"
\"SET(SD_DATADIR_ABS \\\"${SD_DATADIR_ABS}\\\")
SET(SD_LOCALDIR \\\"${SD_LOCALDIR}\\\")
SET(SD_LIBDIR_ABS \\\"${SD_LIBDIR_ABS}\\\")
SET(SD_BINDIR_ABS \\\"${SD_BINDIR_ABS}\\\")
SET(SD_INCLUDEDIR_ABS \\\"${SD_INCLUDEDIR_ABS}\\\")
SET(IN_SOURCETREE FALSE)\\n\\n\")
FILE(READ \"${SOURCE_DIR}/cmake/macros.cmake\" SD_MACRO_CONTENT)
FILE(APPEND \"\${CUR_DESTDIR_CORR}${SD_DATADIR_ABS}/cmake/speed-dreams.cmake\" \${SD_MACRO_CONTENT})")
ENDMACRO(INSTALL_SD_CMAKE)
ENDIF(IN_SOURCETREE)
MACRO(SD_INSTALL_CAR CARNAME)
SET(SDIC_FILES ${ARGN})

View file

@ -86,25 +86,21 @@ IF(IN_SOURCETREE)
ENDIF()
IF(WIN32)
SET(SD_BINDIR bin CACHE PATH "Place where the executables should go")
SET(SD_DATADIR data CACHE PATH "Place where all the static data files should go")
SET(SD_LIBDIR ${_DEFLIBDIR} CACHE PATH "Place where the libraries should go")
SET(SD_INCLUDEDIR include CACHE PATH "Place where the include files should go")
ELSE(WIN32) #UNIX
SET(SD_BINDIR games CACHE PATH "Place where the executables should go")
SET(SD_DATADIR share/games/speed-dreams-2 CACHE PATH "Place where all the static data files should go")
SET(SD_LIBDIR ${_DEFLIBDIR}/games/speed-dreams-2 CACHE PATH "Place where the libraries should go")
SET(SD_INCLUDEDIR include/speed-dreams-2 CACHE PATH "Place where the include files should go")
SET(SD_MANDIR share/man CACHE PATH "Place where the manual pages should go")
ENDIF(WIN32)
MARK_AS_ADVANCED(SD_BINDIR)
MARK_AS_ADVANCED(SD_DATADIR)
MARK_AS_ADVANCED(SD_LIBDIR)
MARK_AS_ADVANCED(SD_INCLUDEDIR)
IF(UNIX)
MARK_AS_ADVANCED(SD_MANDIR)
ENDIF(UNIX)
ELSE(IN_SOURCETREE)
SET(SD_DATADIR ${SD_DATADIR_ABS})
SET(SD_LIBDIR ${SD_LIBDIR_ABS})
SET(SD_BINDIR ${SD_BINDIR_ABS})
SET(SD_INCLUDEDIR ${SD_INCLUDEDIR_ABS})
@ -114,11 +110,6 @@ ELSE(IN_SOURCETREE)
ENDIF(IN_SOURCETREE)
# Determine the aboslute paths of the data, bin and lib (and man) folders.
IF(IS_ABSOLUTE ${SD_DATADIR})
GET_FILENAME_COMPONENT(SD_DATADIR_ABS ${SD_DATADIR} ABSOLUTE)
ELSE(IS_ABSOLUTE ${SD_DATADIR})
GET_FILENAME_COMPONENT(SD_DATADIR_ABS ${CMAKE_INSTALL_PREFIX}/${SD_DATADIR} ABSOLUTE)
ENDIF(IS_ABSOLUTE ${SD_DATADIR})
IF(IS_ABSOLUTE ${SD_LIBDIR})
GET_FILENAME_COMPONENT(SD_LIBDIR_ABS ${SD_LIBDIR} ABSOLUTE)

View file

@ -67,7 +67,7 @@ MACRO(GENERATE_ROBOT_DEF_FILE ROBOTNAME DEF_FILE)
IF(IN_SOURCETREE)
CONFIGURE_FILE(${SOURCE_DIR}/cmake/robot.def.in.cmake ${DEF_FILE})
ELSE(IN_SOURCETREE)
CONFIGURE_FILE(${SD_DATADIR_ABS}/cmake/robot.def.in.cmake ${DEF_FILE})
CONFIGURE_FILE(${SD_DATADIR}/cmake/robot.def.in.cmake ${DEF_FILE})
ENDIF(IN_SOURCETREE)
ENDMACRO(GENERATE_ROBOT_DEF_FILE ROBOTNAME DEF_FILE)

View file

@ -447,18 +447,6 @@ bool GfApplication::parseOptions()
if (strDataDir.empty())
strDataDir = GfSetDataDir(SD_DATADIR);
// If the data dir. is not a run-time usable one, may be it's because we are running
// without installing : try and use the _source_ data dir (it _is_ run-time usable).
std::string strDataDirProof(strDataDir);
// A run-time usable data dir has a "config/logging.xml" file inside.
strDataDirProof += LOGGING_CFG;
if (!strDataDir.empty() && !GfFileExists(strDataDirProof.c_str()))
{
GfLogTrace("Data dir. '%s' not run-time usable, trying source data dir.\n",
strDataDir.c_str());
strDataDir = GfSetDataDir(SD_DATADIR_SRC);
}
// Check if ALL the Speed-dreams dirs have a usable value, and exit if not.
if (strLocalDir.empty() || strLibDir.empty() || strBinDir.empty() || strDataDir.empty())
{

View file

@ -17,7 +17,8 @@ ExternalProject_Add(xmlversion
-D CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
-D CMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
-D TOPLEVEL_DIR=${CMAKE_SOURCE_DIR}
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-D SD_DATADIR=${SD_DATADIR})
IF(NOT OPTION_OFFICIAL_ONLY)
SD_ADD_SUBDIRECTORY(menuview)