Skip to content

Commit

Permalink
Enable cross-compiling of HogMaker
Browse files Browse the repository at this point in the history
  • Loading branch information
tophyr committed Jun 30, 2024
1 parent e68f270 commit 90224b4
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 59 deletions.
108 changes: 56 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -95,10 +96,11 @@ if(UNIX)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${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")
Expand Down Expand Up @@ -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)
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 4 additions & 0 deletions netcon/lanclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ target_link_libraries(Direct_TCP_IP PRIVATE
$<$<PLATFORM_ID:Windows>:ws2_32>
)

if (HogMaker_DIR)
find_package(HogMaker REQUIRED)
endif()

add_custom_target(Direct_TCP_IP_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Direct TCP~IP.d3c"
Expand Down
4 changes: 4 additions & 0 deletions netcon/mtclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ target_link_libraries(Parallax_Online PRIVATE
$<$<PLATFORM_ID:Windows>:ws2_32>
)

if (HogMaker_DIR)
find_package(HogMaker REQUIRED)
endif()

add_custom_target(Parallax_Online_Hog
COMMAND $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/online/Parallax Online.d3c"
Expand Down
4 changes: 4 additions & 0 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE:HogMaker>
"$<TARGET_FILE_DIR:Descent3>/d3-${HOG_NAME}.hog"
Expand Down
19 changes: 12 additions & 7 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 90224b4

Please sign in to comment.