@@ -11,9 +11,41 @@ set(COSE_RS_CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo/build")
1111find_program (CARGO NAMES cargo REQUIRED )
1212find_program (RUSTC NAMES rustc REQUIRED )
1313
14- # This path depends on Cargo's default host-layout target/release path. CMake
14+ # Multi-config generators (Visual Studio, Xcode, Ninja Multi-Config) choose the
15+ # build type at build time, but Cargo profile selection happens at configure
16+ # time. Reject them so the Rust library is never silently built with the wrong
17+ # profile.
18+ if (CMAKE_CONFIGURATION_TYPES )
19+ message (
20+ FATAL_ERROR
21+ "Multi-config generators are not supported for the Rust cose-rs build. "
22+ "Use a single-config generator (e.g. -GNinja) and set CMAKE_BUILD_TYPE instead."
23+ )
24+ endif ()
25+
26+ # Map CMAKE_BUILD_TYPE to a Cargo profile. Debug uses the Cargo dev profile for
27+ # faster compilation; all other build types use the release profile with LTO.
28+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
29+ set (COSE_RS_CARGO_PROFILE_FLAG "" )
30+ set (COSE_RS_CARGO_PROFILE_DIR "debug" )
31+ set (COSE_RS_CARGO_PROFILE_NAME "dev" )
32+ else ()
33+ set (COSE_RS_CARGO_PROFILE_FLAG "--release" )
34+ set (COSE_RS_CARGO_PROFILE_DIR "release" )
35+ set (COSE_RS_CARGO_PROFILE_NAME "release" )
36+ endif ()
37+
38+ message (
39+ STATUS
40+ "Rust cose-rs: CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -> Cargo profile '${COSE_RS_CARGO_PROFILE_NAME} '"
41+ )
42+
43+ # This path depends on Cargo's default host-layout target/<profile> path. CMake
1544# intentionally reruns Cargo and lets Cargo decide whether the Rust inputs are dirty.
16- set (COSE_RS_CARGO_LIB_PATH "${COSE_RS_CARGO_TARGET_DIR} /release/${COSE_RS_LIB} " )
45+ set (
46+ COSE_RS_CARGO_LIB_PATH
47+ "${COSE_RS_CARGO_TARGET_DIR} /${COSE_RS_CARGO_PROFILE_DIR} /${COSE_RS_LIB} "
48+ )
1749
1850# Reproducible builds: remap absolute paths in the binary. RUSTFLAGS applies to
1951# all crates, including dependencies.
@@ -32,7 +64,7 @@ add_custom_target(
3264 "CXX=${CMAKE_CXX_COMPILER} " "AR=${CMAKE_AR} " "CARGO_BUILD_RUSTC=${RUSTC} "
3365 "${CARGO} " build --lib --package "${COSE_RS_PACKAGE} " --manifest-path
3466 "${COSE_RS_MANIFEST_PATH} " --target-dir "${COSE_RS_CARGO_TARGET_DIR} "
35- --release --locked
67+ ${COSE_RS_CARGO_PROFILE_FLAG} --locked
3668 COMMAND
3769 "${CMAKE_COMMAND} " -E copy_if_different "${COSE_RS_CARGO_LIB_PATH} "
3870 "${CMAKE_BINARY_DIR} "
@@ -42,7 +74,8 @@ add_custom_target(
4274 "${COSE_RS_DIR} /Cargo.lock"
4375 "${COSE_RS_DIR} /rust-toolchain.toml"
4476 "${CCF_DIR} /3rdparty/internal/cose-openssl/Cargo.toml"
45- COMMENT "Building ${COSE_RS_PACKAGE} Rust static library via Cargo"
77+ COMMENT
78+ "Building ${COSE_RS_PACKAGE} Rust static library (Cargo profile: ${COSE_RS_CARGO_PROFILE_NAME} )"
4679 USES_TERMINAL
4780 VERBATIM
4881)
0 commit comments