diff --git a/CMakeLists.txt b/CMakeLists.txt index 529a76051..93a6c6578 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ option(FORCE_PORTABLE_INSTALL "Install all files into local directory defined by option(ENABLE_LOGGER "Enable logging to the terminal" OFF) option(ENABLE_MEM_RTL "Enable Real-time library memory management functions (disable to verbose memory allocations)" ON) option(BUILD_TESTING "Enable testing. Requires GTest." OFF) +option(HOST_TOOLS_ONLY "Build only the tools a build host needs, for cross-compilation to a non-native target." OFF) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") option(BUILD_EDITOR "Build internal editor" OFF) @@ -95,10 +96,11 @@ if(UNIX) add_compile_options("$<$:${BITS}>") endif() -find_package(SDL2 REQUIRED) -# Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both. -message("SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}") - +if(NOT HOST_TOOLS_ONLY) + find_package(SDL2 REQUIRED) + # Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both. + message("SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}") +endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") message("Building for Linux") @@ -169,55 +171,57 @@ include_directories( ${PLATFORM_INCLUDES} ) -add_subdirectory(third_party) +add_subdirectory(tools) +if(NOT HOST_TOOLS_ONLY) + add_subdirectory(third_party) + + add_subdirectory(2dlib) + add_subdirectory(AudioEncode) + add_subdirectory(bitmap) + add_subdirectory(cfile) + add_subdirectory(czip) + add_subdirectory(d3music) + add_subdirectory(ddebug) + + if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_subdirectory(dd_grwin32) + add_subdirectory(win32) + endif() -add_subdirectory(2dlib) -add_subdirectory(AudioEncode) -add_subdirectory(bitmap) -add_subdirectory(cfile) -add_subdirectory(czip) -add_subdirectory(d3music) -add_subdirectory(ddebug) + add_subdirectory(linux) + + add_subdirectory(ddio) + add_subdirectory(dd_video) + add_subdirectory(fix) + add_subdirectory(manage) + add_subdirectory(grtext) + add_subdirectory(mem) + add_subdirectory(misc) + add_subdirectory(model) + add_subdirectory(module) + add_subdirectory(movie) + add_subdirectory(music) + add_subdirectory(networking) + add_subdirectory(physics) + add_subdirectory(renderer) + add_subdirectory(rtperformance) + add_subdirectory(sndlib) + add_subdirectory(stream_audio) + add_subdirectory(ui) + add_subdirectory(unzip) + add_subdirectory(vecmat) + add_subdirectory(libmve) + add_subdirectory(md5) + add_subdirectory(libacm) + + + if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_subdirectory(editor) + endif() -if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows") - add_subdirectory(dd_grwin32) - add_subdirectory(win32) -endif() + add_subdirectory(Descent3) -add_subdirectory(linux) - -add_subdirectory(ddio) -add_subdirectory(dd_video) -add_subdirectory(fix) -add_subdirectory(manage) -add_subdirectory(grtext) -add_subdirectory(mem) -add_subdirectory(misc) -add_subdirectory(model) -add_subdirectory(module) -add_subdirectory(movie) -add_subdirectory(music) -add_subdirectory(networking) -add_subdirectory(physics) -add_subdirectory(renderer) -add_subdirectory(rtperformance) -add_subdirectory(sndlib) -add_subdirectory(stream_audio) -add_subdirectory(ui) -add_subdirectory(unzip) -add_subdirectory(vecmat) -add_subdirectory(libmve) -add_subdirectory(md5) -add_subdirectory(libacm) - - -if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows") - add_subdirectory(editor) + add_subdirectory(netcon) + add_subdirectory(netgames) + add_subdirectory(scripts) endif() - -add_subdirectory(Descent3) - -add_subdirectory(tools) -add_subdirectory(netcon) -add_subdirectory(netgames) -add_subdirectory(scripts) diff --git a/README.md b/README.md index 080de55d9..1b2f443fd 100644 --- a/README.md +++ b/README.md @@ -170,5 +170,19 @@ cmake --build --preset linux --config [Debug|Release] Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`. +#### Note - Cross-Compiling +A tool called `HogMaker` is built from source and then used during the Descent3 build in order to create HOG files containing level data. As a result, `HogMaker` must be built as an executable for the architecture _performing_ the build - not the architecture for which you're building. CMake does not support more than one build toolchain in a single build invocation, so if are cross-compiling Descent3 then you will need to configure and build HogMaker individually first: +```sh +# configure a "host" build into its own directory, and set HOST_TOOLS_ONLY to 1 +cmake -B builds/host -DHOST_TOOLS_ONLY=1 +# perform the host build +cmake --build builds/host + +# now, configure your real target build, pointing to the existing host tools build +cmake -B builds/target -DCMAKE_TOOLCHAIN_FILE=/path/to/your/toolchain.cmake -DHogMaker_DIR=$(pwd)/builds/host +# perform your real build. CMake will not build HogMaker in this invocation, and instead use the previously-built one +cmake --build builds/target +``` + ## Contributing Anyone can contribute! We have an active Discord presence at [Descent Developer Network](https://discord.gg/GNy5CUQ). If you are interested in maintaining the project on a regular basis, please contact Kevin Bentley. diff --git a/netcon/lanclient/CMakeLists.txt b/netcon/lanclient/CMakeLists.txt index 95f928e53..678ab830e 100644 --- a/netcon/lanclient/CMakeLists.txt +++ b/netcon/lanclient/CMakeLists.txt @@ -11,6 +11,10 @@ target_link_libraries(Direct_TCP_IP PRIVATE $<$:ws2_32> ) +if (HogMaker_DIR) + find_package(HogMaker REQUIRED) +endif() + add_custom_target(Direct_TCP_IP_Hog COMMAND $ "$/online/Direct TCP~IP.d3c" diff --git a/netcon/mtclient/CMakeLists.txt b/netcon/mtclient/CMakeLists.txt index 523fd9163..d1a879fa2 100644 --- a/netcon/mtclient/CMakeLists.txt +++ b/netcon/mtclient/CMakeLists.txt @@ -17,6 +17,10 @@ target_link_libraries(Parallax_Online PRIVATE $<$:ws2_32> ) +if (HogMaker_DIR) + find_package(HogMaker REQUIRED) +endif() + add_custom_target(Parallax_Online_Hog COMMAND $ "$/online/Parallax Online.d3c" diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 936115f06..be42427bb 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -89,6 +89,10 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(HOG_NAME "win") endif() +if (HogMaker_DIR) + find_package(HogMaker REQUIRED) +endif() + add_custom_target(HogFull COMMAND $ "$/d3-${HOG_NAME}.hog" diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 52e93a7da..52bc4d450 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,7 +1,12 @@ -add_executable( - HogMaker - HogMaker/HogFormat.cpp - HogMaker/HogMaker.cpp -) -add_dependencies(HogMaker get_git_hash) -target_include_directories(HogMaker PRIVATE ${PROJECT_BINARY_DIR}/lib) +if (HogMaker_DIR) + find_package(HogMaker REQUIRED) +else() + add_executable( + HogMaker + HogMaker/HogFormat.cpp + HogMaker/HogMaker.cpp + ) + export(TARGETS HogMaker FILE "${CMAKE_BINARY_DIR}/HogMakerConfig.cmake") + add_dependencies(HogMaker get_git_hash) + target_include_directories(HogMaker PRIVATE ${PROJECT_BINARY_DIR}/lib) +endif()