Run cargo from CMake

This commit is contained in:
Oliver Hamlet
2025-04-26 16:41:33 +01:00
parent 4cd9b37471
commit 9c5b73da74
2 changed files with 14 additions and 10 deletions
+13 -6
View File
@@ -24,8 +24,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# External Projects
##############################
add_library(libloot-cxx STATIC IMPORTED)
if(MSVC)
set(LIBLOOT_CXX_FILENAME "libloot_cxx.lib")
else()
@@ -38,10 +36,19 @@ else()
set(TARGET_PATH "${CMAKE_SOURCE_DIR}/../target")
endif()
set_target_properties(libloot-cxx PROPERTIES
IMPORTED_CONFIGURATIONS "Release;Debug"
IMPORTED_LOCATION "${TARGET_PATH}/release/${LIBLOOT_CXX_FILENAME}"
IMPORTED_LOCATION_DEBUG "${TARGET_PATH}/debug/${LIBLOOT_CXX_FILENAME}")
add_custom_target(libloot-cxx-build
COMMAND cargo build
$<$<NOT:$<CONFIG:Debug>>:--release>
$<$<AND:$<CONFIG:Debug>,$<PLATFORM_ID:Windows>>:--config>
$<$<AND:$<CONFIG:Debug>,$<PLATFORM_ID:Windows>>:${CMAKE_SOURCE_DIR}/../.cargo/msvcd-config.toml>
)
add_library(libloot-cxx INTERFACE)
add_dependencies(libloot-cxx libloot-cxx-build)
target_link_libraries(libloot-cxx INTERFACE
optimized "${TARGET_PATH}/release/${LIBLOOT_CXX_FILENAME}"
debug "${TARGET_PATH}/debug/${LIBLOOT_CXX_FILENAME}")
target_include_directories(libloot-cxx INTERFACE "${TARGET_PATH}/cxxbridge")
+1 -4
View File
@@ -14,15 +14,13 @@ The wrapper has two layers:
To build a release build with debug info:
```
cargo build --release
cmake -B build .
cmake --build build --parallel --config RelWithDebInfo
```
Debug builds need a little extra config to get the static and shared libraries to use the same C runtime library on Windows:
To build a debug build:
```
cargo build --config ../.cargo/msvcd-config.toml
cmake -B build .
cmake --build build --parallel --config Debug
```
@@ -32,7 +30,6 @@ cmake --build build --parallel --config Debug
To build a release build with debug info:
```
cargo build --release
cmake -B build . -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build --parallel
```