Skip to content

Commit 0da903d

Browse files
committed
Enable cross-compiling of HogMaker
1 parent e68f270 commit 0da903d

6 files changed

Lines changed: 93 additions & 59 deletions

File tree

CMakeLists.txt

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ if(UNIX)
9595
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${BITS}>")
9696
endif()
9797

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-
98+
if(NOT HOST_TOOLS_ONLY)
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+
endif()
102103

103104
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
104105
message("Building for Linux")
@@ -169,55 +170,57 @@ include_directories(
169170
${PLATFORM_INCLUDES}
170171
)
171172
172-
add_subdirectory(third_party)
173+
add_subdirectory(tools)
174+
if(NOT HOST_TOOLS_ONLY)
175+
add_subdirectory(third_party)
176+
177+
add_subdirectory(2dlib)
178+
add_subdirectory(AudioEncode)
179+
add_subdirectory(bitmap)
180+
add_subdirectory(cfile)
181+
add_subdirectory(czip)
182+
add_subdirectory(d3music)
183+
add_subdirectory(ddebug)
184+
185+
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
186+
add_subdirectory(dd_grwin32)
187+
add_subdirectory(win32)
188+
endif()
173189
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)
190+
add_subdirectory(linux)
191+
192+
add_subdirectory(ddio)
193+
add_subdirectory(dd_video)
194+
add_subdirectory(fix)
195+
add_subdirectory(manage)
196+
add_subdirectory(grtext)
197+
add_subdirectory(mem)
198+
add_subdirectory(misc)
199+
add_subdirectory(model)
200+
add_subdirectory(module)
201+
add_subdirectory(movie)
202+
add_subdirectory(music)
203+
add_subdirectory(networking)
204+
add_subdirectory(physics)
205+
add_subdirectory(renderer)
206+
add_subdirectory(rtperformance)
207+
add_subdirectory(sndlib)
208+
add_subdirectory(stream_audio)
209+
add_subdirectory(ui)
210+
add_subdirectory(unzip)
211+
add_subdirectory(vecmat)
212+
add_subdirectory(libmve)
213+
add_subdirectory(md5)
214+
add_subdirectory(libacm)
215+
216+
217+
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
218+
add_subdirectory(editor)
219+
endif()
181220
182-
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
183-
add_subdirectory(dd_grwin32)
184-
add_subdirectory(win32)
185-
endif()
221+
add_subdirectory(Descent3)
186222
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)
223+
add_subdirectory(netcon)
224+
add_subdirectory(netgames)
225+
add_subdirectory(scripts)
216226
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)