Skip to content

Commit 139e04a

Browse files
committed
Enable cross-compiling of HogMaker
1 parent 1ed931f commit 139e04a

6 files changed

Lines changed: 93 additions & 58 deletions

File tree

CMakeLists.txt

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ if(UNIX)
9494
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-multichar;${BITS};${EXTRA_CXX_FLAGS}>")
9595
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${BITS}>")
9696

97-
find_package(SDL2 REQUIRED)
98-
# Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both.
99-
message("SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}")
97+
if(NOT HOST_TOOLS_ONLY)
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+
endif()
100102
endif()
101103

102104
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
@@ -168,55 +170,57 @@ include_directories(
168170
${PLATFORM_INCLUDES}
169171
)
170172
171-
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(CMAKE_SYSTEM_NAME STREQUAL "Windows")
186+
add_subdirectory(dd_grwin32)
187+
add_subdirectory(win32)
188+
else()
189+
add_subdirectory(linux)
190+
endif()
172191
173-
add_subdirectory(2dlib)
174-
add_subdirectory(AudioEncode)
175-
add_subdirectory(bitmap)
176-
add_subdirectory(cfile)
177-
add_subdirectory(czip)
178-
add_subdirectory(d3music)
179-
add_subdirectory(ddebug)
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()
180220
181-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
182-
add_subdirectory(dd_grwin32)
183-
add_subdirectory(win32)
184-
else()
185-
add_subdirectory(linux)
186-
endif()
221+
add_subdirectory(Descent3)
187222
188-
add_subdirectory(ddio)
189-
add_subdirectory(dd_video)
190-
add_subdirectory(fix)
191-
add_subdirectory(manage)
192-
add_subdirectory(grtext)
193-
add_subdirectory(mem)
194-
add_subdirectory(misc)
195-
add_subdirectory(model)
196-
add_subdirectory(module)
197-
add_subdirectory(movie)
198-
add_subdirectory(music)
199-
add_subdirectory(networking)
200-
add_subdirectory(physics)
201-
add_subdirectory(renderer)
202-
add_subdirectory(rtperformance)
203-
add_subdirectory(sndlib)
204-
add_subdirectory(stream_audio)
205-
add_subdirectory(ui)
206-
add_subdirectory(unzip)
207-
add_subdirectory(vecmat)
208-
add_subdirectory(libmve)
209-
add_subdirectory(md5)
210-
add_subdirectory(libacm)
211-
212-
213-
if(BUILD_EDITOR AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
214-
add_subdirectory(editor)
223+
add_subdirectory(netcon)
224+
add_subdirectory(netgames)
225+
add_subdirectory(scripts)
215226
endif()
216-
217-
add_subdirectory(Descent3)
218-
219-
add_subdirectory(tools)
220-
add_subdirectory(netcon)
221-
add_subdirectory(netgames)
222-
add_subdirectory(scripts)

README.md

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

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

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

13+
if (HogMaker_DIR)
14+
find_package(HogMaker REQUIRED)
15+
endif()
16+
1317
add_custom_target(Direct_TCP_IP_Hog
1418
COMMAND $<TARGET_FILE:HogMaker>
1519
"$<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
@@ -16,6 +16,10 @@ target_link_libraries(Parallax_Online PRIVATE
1616
$<$<PLATFORM_ID:Windows>:ws2_32>
1717
)
1818

19+
if (HogMaker_DIR)
20+
find_package(HogMaker REQUIRED)
21+
endif()
22+
1923
add_custom_target(Parallax_Online_Hog
2024
COMMAND $<TARGET_FILE:HogMaker>
2125
"$<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
@@ -86,6 +86,10 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
8686
set(HOG_NAME "win")
8787
endif()
8888

89+
if (HogMaker_DIR)
90+
find_package(HogMaker REQUIRED)
91+
endif()
92+
8993
add_custom_target(HogFull
9094
COMMAND $<TARGET_FILE:HogMaker>
9195
"$<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)