From 114331b4540116d66156a8c5e1c59855a7a93819 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Thu, 9 May 2024 00:55:38 -0700 Subject: [PATCH] Support more generator expressions in output directories --- cmake/Corrosion.cmake | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cmake/Corrosion.cmake b/cmake/Corrosion.cmake index 00d3d47b..2d0c0ea7 100644 --- a/cmake/Corrosion.cmake +++ b/cmake/Corrosion.cmake @@ -89,6 +89,35 @@ function(_corrosion_bin_target_suffix target_name out_var_suffix) set(${out_var_suffix} "${_suffix}" PARENT_SCOPE) endfunction() +function(_corrosion_genex_expand config_type genex_out genex) + string(GENEX_STRIP "${genex}" stripped) + while(NOT "${genex}" STREQUAL stripped) + set(genex_last "${genex}") + + # NOTE: in all of the following examples, assume config_type is Debug. + # $ -> Debug + string(REPLACE "\$" "${config_type}" genex "${genex}") + # $ -> 1 + string(REPLACE "\$" "1" genex "${genex}") + # $ -> 0 + string(REGEX REPLACE "\\\$]*>" "0" genex "${genex}") + # $<1:true-string> -> true-string + string(REGEX REPLACE "\\\$<1:([^>]*)>" "\\1" genex "${genex}") + # $<0:true-string> -> + string(REGEX REPLACE "\\\$<0:([^>]*)>" "" genex "${genex}") + # $ -> true-string + string(REGEX REPLACE "\\\$,]*),([^>]*)>" "\\1" genex "${genex}") + # $ -> false-string + string(REGEX REPLACE "\\\$,]*),([^>]*)>" "\\2" genex "${genex}") + + # no forward progress? stop trying. + if("${genex_last}" STREQUAL "${genex}") + break() + endif() + endwhile() + set("${genex_out}" "${genex}" PARENT_SCOPE) +endfunction() + # Do not call this function directly! # # This function should be called deferred to evaluate target properties late in the configure stage. @@ -127,7 +156,7 @@ function(_corrosion_set_imported_location_deferred target_name base_property out else() set(curr_out_dir "${CMAKE_CURRENT_BINARY_DIR}") endif() - string(REPLACE "\$" "${config_type}" curr_out_dir "${curr_out_dir}") + _corrosion_genex_expand("${config_type}" curr_out_dir "${curr_out_dir}") message(DEBUG "Setting ${base_property}_${config_type_upper} for target ${target_name}" " to `${curr_out_dir}/${filename}`.") @@ -153,7 +182,7 @@ function(_corrosion_set_imported_location_deferred target_name base_property out else() set(base_output_directory "${CMAKE_CURRENT_BINARY_DIR}") endif() - string(REPLACE "\$" "${CMAKE_BUILD_TYPE}" base_output_directory "${base_output_directory}") + _corrosion_genex_expand("${CMAKE_BUILD_TYPE}" base_output_directory "${base_output_directory}") string(GENEX_STRIP "${base_output_directory}" stripped_out_dir) if(NOT ("${stripped_out_dir}" STREQUAL "${base_output_directory}")) message(FATAL_ERROR "${output_dir_prop_target_name} for target ${output_dir_prop_target_name} "