Enable cross-compile environment for HogMaker

Add CMAKE_CROSSCOMPILING conditional for HogMaker that makes it "external" tool in cross-compile environment, so we can use native HogMaker for cross-compiled targets.
This commit is contained in:
Azamat H. Hackimov 2024-10-21 18:13:49 +03:00
parent 39b205b957
commit 46c6b55f5c
2 changed files with 36 additions and 8 deletions

View File

@ -40,7 +40,7 @@ The build process uses [**CMake**](https://cmake.org/) and, by default, [**Ninja
git clone --recurse-submodules https://github.com/DescentDevelopers/Descent3
```
4. **Build Descent3.**
3. **Build Descent3.**
```batch
cd Descent3
@ -149,6 +149,29 @@ Once CMake finishes, the built files will be put in `builds/mac/Descent3/Debug`
Once CMake finishes, the built files will be put in `builds/linux/Descent3/Debug` or `builds/linux/Descent3/Release`.
## Cross-compilation
In order to cross-compile Descent3 to another platform (for example, Linux ARM64), you'll need to build auxiliary
tools which needed to build data files. First create build-native directory and configure project in it:
```shell
mkdir build-native
cd build-native
cmake ..
make HogMaker
```
Now you ready for cross-compilation. Create cross-compile directory and configure project in it, but this time add
`-DCMAKE_TOOLCHAIN_FILE=MyToolchain.cmake` and `-DHogMaker_DIR=<path-to-Descent3/build-native/` options. This enables
cross-compilation environment.
```shell
mkdir build-cross
cd build-cross
cmake -DCMAKE_TOOLCHAIN_FILE=MyToolchain.cmake -DHogMaker_DIR=~/src/build-native/ ..
make
```
## Build Options
The Descent3 build can be customized by [setting CMake variables on the command line](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-D) during its "Configuration" phase (the command without the `--build` option). To set a variable, you prepend the variable name with `-D` and then append the value, all as one single parameter. For example:

View File

@ -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(CMAKE_CROSSCOMPILING)
find_package(HogMaker)
else()
add_executable(
HogMaker
HogMaker/HogFormat.cpp
HogMaker/HogMaker.cpp
)
add_dependencies(HogMaker get_git_hash)
target_include_directories(HogMaker PRIVATE ${PROJECT_BINARY_DIR}/lib)
export(TARGETS HogMaker FILE "${CMAKE_BINARY_DIR}/HogMakerConfig.cmake")
endif()