From e6b7576e4d457963c55b806433d2040b1a517fb4 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Mon, 20 Nov 2023 17:02:06 +0000 Subject: [PATCH] fix for ZENOHC_CARGO_FLAGS passing --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 524c593ae..2477ecd37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,7 +170,15 @@ set_genexpr_condition(libs DEBUG $ "${libsd}" "${libsr}") # Build rust sources # set_genexpr_condition(cargo_release_flag DEBUG $ "" "--release") -set(cargo_flags ${ZENOHC_CARGO_FLAGS} ${cargo_release_flag}) +# cargo_flags is a list of command line arguments for cargo. It should be represented as a list in CMake, +# i.e. if ZENOHC_CARGO_FLAGS constains space, it shoudl be replaced to list separator ";". This is important for further "add_custom_command" call +# where each list element is passed as separate argument to system exec call. +# This makes impossible to use ";" in ZENOHC_CARGO_FLAGS, let's hope it's not a problem for now. +if (ZENOHC_CARGO_FLAGS MATCHES ";") + message(FATAL_ERROR "ZENOHC_CARGO_FLAGS contains ';' which is not allowed (see comment in CMakeLists.txt))") +endif() +string(REPLACE " " ";" cargo_flags "${ZENOHC_CARGO_FLAGS}") +set(cargo_flags ${cargo_flags} ${cargo_release_flag}) set(cargo_flags ${cargo_flags} --manifest-path=${cargo_toml_dir}/Cargo.toml) if(ZENOHC_BUILD_WITH_LOGGER_AUTOINIT) @@ -192,6 +200,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E echo \"RUSTFLAGS = $$RUSTFLAGS\" COMMAND ${CMAKE_COMMAND} -E echo \"cargo +${ZENOHC_CARGO_CHANNEL} build ${cargo_flags}\" COMMAND cargo +${ZENOHC_CARGO_CHANNEL} build ${cargo_flags} + VERBATIM ) add_custom_target(cargo ALL DEPENDS "${libs}")