Skip to content

Commit 90224b4

Browse files
committed
Enable cross-compiling of HogMaker
1 parent e68f270 commit 90224b4

File tree

6 files changed

+94
-59
lines changed

6 files changed

+94
-59
lines changed

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)
@@ -95,10 +96,11 @@ if(UNIX)
9596
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${BITS}>")
9697
endif()
9798

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

103105
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
104106
message("Building for Linux")
@@ -169,55 +171,57 @@ include_directories(
169171
${PLATFORM_INCLUDES}
170172
)
171173

172-
add_subdirectory(third_party)
174+
add_subdirectory(tools)
175+
if(NOT HOST_TOOLS_ONLY)
176+
add_subdirectory(third_party)
177+
178+
add_subdirectory(2dlib)
179+
add_subdirectory(AudioEncode)
180+
add_subdirectory(bitmap)
181+
add_subdirectory(cfile)
182+
add_subdirectory(czip)
183+
add_subdirectory(d3music)
184+
add_subdirectory(ddebug)
185+
186+
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
187+
add_subdirectory(dd_grwin32)
188+
add_subdirectory(win32)
189+
endif()
173190

174-
add_subdirectory(2dlib)
175-
add_subdirectory(AudioEncode)
176-
add_subdirectory(bitmap)
177-
add_subdirectory(cfile)
178-
add_subdirectory(czip)
179-
add_subdirectory(d3music)
180-
add_subdirectory(ddebug)
191+
add_subdirectory(linux)
192+
193+
add_subdirectory(ddio)
194+
add_subdirectory(dd_video)
195+
add_subdirectory(fix)
196+
add_subdirectory(manage)
197+
add_subdirectory(grtext)
198+
add_subdirectory(mem)
199+
add_subdirectory(misc)
200+
add_subdirectory(model)
201+
add_subdirectory(module)
202+
add_subdirectory(movie)
203+
add_subdirectory(music)
204+
add_subdirectory(networking)
205+
add_subdirectory(physics)
206+
add_subdirectory(renderer)
207+
add_subdirectory(rtperformance)
208+
add_subdirectory(sndlib)
209+
add_subdirectory(stream_audio)
210+
add_subdirectory(ui)
211+
add_subdirectory(unzip)
212+
add_subdirectory(vecmat)
213+
add_subdirectory(libmve)
214+
add_subdirectory(md5)
215+
add_subdirectory(libacm)
216+
217+
218+
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
219+
add_subdirectory(editor)
220+
endif()
181221

182-
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
183-
add_subdirectory(dd_grwin32)
184-
add_subdirectory(win32)
185-
endif()
222+
add_subdirectory(Descent3)
186223

187-
add_subdirectory(linux)
188-
189-
add_subdirectory(ddio)
190-
add_subdirectory(dd_video)
191-
add_subdirectory(fix)
192-
add_subdirectory(manage)
193-
add_subdirectory(grtext)
194-
add_subdirectory(mem)
195-
add_subdirectory(misc)
196-
add_subdirectory(model)
197-
add_subdirectory(module)
198-
add_subdirectory(movie)
199-
add_subdirectory(music)
200-
add_subdirectory(networking)
201-
add_subdirectory(physics)
202-
add_subdirectory(renderer)
203-
add_subdirectory(rtperformance)
204-
add_subdirectory(sndlib)
205-
add_subdirectory(stream_audio)
206-
add_subdirectory(ui)
207-
add_subdirectory(unzip)
208-
add_subdirectory(vecmat)
209-
add_subdirectory(libmve)
210-
add_subdirectory(md5)
211-
add_subdirectory(libacm)
212-
213-
214-
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
215-
add_subdirectory(editor)
224+
add_subdirectory(netcon)
225+
add_subdirectory(netgames)
226+
add_subdirectory(scripts)
216227
endif()
217-
218-
add_subdirectory(Descent3)
219-
220-
add_subdirectory(tools)
221-
add_subdirectory(netcon)
222-
add_subdirectory(netgames)
223-
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)