From 555cec17edc2cae91b3310ef8915acbeb3951cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Thu, 16 Mar 2023 22:47:38 +0000 Subject: [PATCH] Fix parsing of command-line arguments when already specified as a cmake list. --- CMakeLists.txt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5cba07fe..799cd7122 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,20 @@ macro(ei_add_cxx_compiler_flag FLAG) endif() endmacro() +function(ei_maybe_separate_arguments variable mode args) + # Use separate_arguments if the input is a single string containing a space. + # Otherwise, if it is already a list or doesn't have a space, just propagate + # the original value. This is to better support multi-argument lists. + list(LENGTH args list_length) + if (${list_length} EQUAL 1) + string(FIND "${args}" " " has_space) + if (${has_space} GREATER -1) + separate_arguments(args ${mode} "${args}") + endif() + endif() + set(${variable} ${args} PARENT_SCOPE) +endfunction(ei_maybe_separate_arguments) + # Determine if we should build shared libraries on this platform. get_cmake_property(EIGEN_BUILD_SHARED_LIBS TARGET_SUPPORTS_SHARED_LIBS) @@ -111,8 +125,11 @@ find_package(StandardMathLibrary) set(EIGEN_TEST_CUSTOM_LINKER_FLAGS "" CACHE STRING "Additional linker flags when linking unit tests.") set(EIGEN_TEST_CUSTOM_CXX_FLAGS "" CACHE STRING "Additional compiler flags when compiling unit tests.") -# convert space separated argument into CMake lists for downstream consumption -separate_arguments(EIGEN_TEST_CUSTOM_CXX_FLAGS NATIVE_COMMAND ${EIGEN_TEST_CUSTOM_CXX_FLAGS}) + +# Convert space-separated arguments into CMake lists for downstream consumption. +ei_maybe_separate_arguments(EIGEN_TEST_CUSTOM_LINKER_FLAGS NATIVE_COMMAND "${EIGEN_TEST_CUSTOM_LINKER_FLAGS}") +ei_maybe_separate_arguments(EIGEN_TEST_CUSTOM_CXX_FLAGS NATIVE_COMMAND "${EIGEN_TEST_CUSTOM_CXX_FLAGS}") + set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "")