Skip to content

Commit 715a4e9

Browse files
committed
Enable cross-compiling of HogMaker
1 parent 5641ba4 commit 715a4e9

6 files changed

Lines changed: 94 additions & 59 deletions

File tree

CMakeLists.txt

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ option(FORCE_PORTABLE_INSTALL "Install all files into local directory defined by
1515
option(ENABLE_LOGGER "Enable logging to the terminal" OFF)
1616
option(ENABLE_MEM_RTL "Enable Real-time library memory management functions (disable to verbose memory allocations)" ON)
1717
option(BUILD_TESTING "Enable testing. Requires GTest." OFF)
18+
option(HOST_TOOLS_ONLY "Build only the tools a build host needs, for cross-compilation to a non-native target." OFF)
1819

1920
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
2021
option(BUILD_EDITOR "Build internal editor" OFF)
@@ -96,10 +97,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
9697
add_compile_options("-Wno-multichar;-Wall")
9798
endif()
9899

99-
find_package(SDL2 REQUIRED)
100-
# Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both.
101-
message("SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}")
102-
100+
if(NOT HOST_TOOLS_ONLY)
101+
find_package(SDL2 REQUIRED)
102+
# Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both.
103+
message("SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}")
104+
endif()
103105

104106
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
105107
message("Building for Linux")
@@ -170,55 +172,57 @@ include_directories(
170172
${PLATFORM_INCLUDES}
171173
)
172174
173-
add_subdirectory(third_party)
175+
add_subdirectory(tools)
176+
if(NOT HOST_TOOLS_ONLY)
177+
add_subdirectory(third_party)
178+
179+
add_subdirectory(2dlib)
180+
add_subdirectory(AudioEncode)
181+
add_subdirectory(bitmap)
182+
add_subdirectory(cfile)
183+
add_subdirectory(czip)
184+
add_subdirectory(d3music)
185+
add_subdirectory(ddebug)
186+
187+
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
188+
add_subdirectory(dd_grwin32)
189+
add_subdirectory(win32)
190+
endif()
174191
175-
add_subdirectory(2dlib)
176-
add_subdirectory(AudioEncode)
177-
add_subdirectory(bitmap)
178-
add_subdirectory(cfile)
179-
add_subdirectory(czip)
180-
add_subdirectory(d3music)
181-
add_subdirectory(ddebug)
192+
add_subdirectory(linux)
193+
194+
add_subdirectory(ddio)
195+
add_subdirectory(dd_video)
196+
add_subdirectory(fix)
197+
add_subdirectory(manage)
198+
add_subdirectory(grtext)
199+
add_subdirectory(mem)
200+
add_subdirectory(misc)
201+
add_subdirectory(model)
202+
add_subdirectory(module)
203+
add_subdirectory(movie)
204+
add_subdirectory(music)
205+
add_subdirectory(networking)
206+
add_subdirectory(physics)
207+
add_subdirectory(renderer)
208+
add_subdirectory(rtperformance)
209+
add_subdirectory(sndlib)
210+
add_subdirectory(stream_audio)
211+
add_subdirectory(ui)
212+
add_subdirectory(unzip)
213+
add_subdirectory(vecmat)
214+
add_subdirectory(libmve)
215+
add_subdirectory(md5)
216+
add_subdirectory(libacm)
217+
218+
219+
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
220+
add_subdirectory(editor)
221+
endif()
182222
183-
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
184-
add_subdirectory(dd_grwin32)
185-
add_subdirectory(win32)
186-
endif()
223+
add_subdirectory(Descent3)
187224
188-
add_subdirectory(linux)
189-
190-
add_subdirectory(ddio)
191-
add_subdirectory(dd_video)
192-
add_subdirectory(fix)
193-
add_subdirectory(manage)
194-
add_subdirectory(grtext)
195-
add_subdirectory(mem)
196-
add_subdirectory(misc)
197-
add_subdirectory(model)
198-
add_subdirectory(module)
199-
add_subdirectory(movie)
200-
add_subdirectory(music)
201-
add_subdirectory(networking)
202-
add_subdirectory(physics)
203-
add_subdirectory(renderer)
204-
add_subdirectory(rtperformance)
205-
add_subdirectory(sndlib)
206-
add_subdirectory(stream_audio)
207-
add_subdirectory(ui)
208-
add_subdirectory(unzip)
209-
add_subdirectory(vecmat)
210-
add_subdirectory(libmve)
211-
add_subdirectory(md5)
212-
add_subdirectory(libacm)
213-
214-
215-
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
216-
add_subdirectory(editor)
225+
add_subdirectory(netcon)
226+
add_subdirectory(netgames)
227+
add_subdirectory(scripts)
217228
endif()
218-
219-
add_subdirectory(Descent3)
220-
221-
add_subdirectory(tools)
222-
add_subdirectory(netcon)
223-
add_subdirectory(netgames)
224-
add_subdirectory(scripts)

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,19 @@ cmake --build --preset linux --config [Debug|Release]
170170

171171
Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`.
172172

173+
#### Note - Cross-Compiling
174+
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:
175+
```sh
176+
# configure a "host" build into its own directory, and set HOST_TOOLS_ONLY to 1
177+
cmake -B builds/host -DHOST_TOOLS_ONLY=1
178+
# perform the host build
179+
cmake --build builds/host
180+
181+
# now, configure your real target build, pointing to the existing host tools build
182+
cmake -B builds/target -DCMAKE_TOOLCHAIN_FILE=/path/to/your/toolchain.cmake -DHogMaker_DIR=$(pwd)/builds/host
183+
# perform your real build. CMake will not build HogMaker in this invocation, and instead use the previously-built one
184+
cmake --build builds/target
185+
```
186+
173187
## Contributing
174188
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.

netcon/lanclient/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ target_link_libraries(Direct_TCP_IP PRIVATE
1111
$<$<PLATFORM_ID:Windows>:ws2_32>
1212
)
1313

14+
if (HogMaker_DIR)
15+
find_package(HogMaker REQUIRED)
16+
endif()
17+
1418
add_custom_target(Direct_TCP_IP_Hog
1519
COMMAND $<TARGET_FILE:HogMaker>
1620
"$<TARGET_FILE_DIR:Descent3>/online/Direct TCP~IP.d3c"

netcon/mtclient/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ target_link_libraries(Parallax_Online PRIVATE
1717
$<$<PLATFORM_ID:Windows>:ws2_32>
1818
)
1919

20+
if (HogMaker_DIR)
21+
find_package(HogMaker REQUIRED)
22+
endif()
23+
2024
add_custom_target(Parallax_Online_Hog
2125
COMMAND $<TARGET_FILE:HogMaker>
2226
"$<TARGET_FILE_DIR:Descent3>/online/Parallax Online.d3c"

scripts/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
8989
set(HOG_NAME "win")
9090
endif()
9191

92+
if (HogMaker_DIR)
93+
find_package(HogMaker REQUIRED)
94+
endif()
95+
9296
add_custom_target(HogFull
9397
COMMAND $<TARGET_FILE:HogMaker>
9498
"$<TARGET_FILE_DIR:Descent3>/d3-${HOG_NAME}.hog"

tools/CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
add_executable(
2-
HogMaker
3-
HogMaker/HogFormat.cpp
4-
HogMaker/HogMaker.cpp
5-
)
6-
add_dependencies(HogMaker get_git_hash)
7-
target_include_directories(HogMaker PRIVATE ${PROJECT_BINARY_DIR}/lib)
1+
if (HogMaker_DIR)
2+
find_package(HogMaker REQUIRED)
3+
else()
4+
add_executable(
5+
HogMaker
6+
HogMaker/HogFormat.cpp
7+
HogMaker/HogMaker.cpp
8+
)
9+
export(TARGETS HogMaker FILE "${CMAKE_BINARY_DIR}/HogMakerConfig.cmake")
10+
add_dependencies(HogMaker get_git_hash)
11+
target_include_directories(HogMaker PRIVATE ${PROJECT_BINARY_DIR}/lib)
12+
endif()

0 commit comments

Comments
 (0)