From 9c5b73da74907ac87d6f44723c75ae4b16aca92e Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 26 Apr 2025 16:41:33 +0100 Subject: [PATCH] Run cargo from CMake --- cxx/CMakeLists.txt | 19 +++++++++++++------ cxx/README.md | 5 +---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cxx/CMakeLists.txt b/cxx/CMakeLists.txt index f3653d58..424237c3 100644 --- a/cxx/CMakeLists.txt +++ b/cxx/CMakeLists.txt @@ -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 + $<$>:--release> + $<$,$>:--config> + $<$,$>:${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") diff --git a/cxx/README.md b/cxx/README.md index a02d9f1d..aa4a7dc1 100644 --- a/cxx/README.md +++ b/cxx/README.md @@ -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 ```