From 5c9ab44ff6e3c2cda7738cfba5ab32f4be174ef2 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 7 Apr 2020 12:15:10 +0200 Subject: CMake: Simplify semicolon escaping in qt_config_compile_test list(JOIN) removes a layer of escaping, which force doubling up on the backslashes. Instead use string(REPLACE) thus making the escaping a bit saner. Change-Id: Ie3daf0112dd09fbcbaf8798552949470952611c9 Reviewed-by: Leander Beernaert Reviewed-by: Alexandru Croitor --- cmake/QtFeature.cmake | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'cmake') diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index 9e88ceac91..b2d993647f 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -657,7 +657,6 @@ function(qt_config_compile_test name) endif() # Pass which packages need to be found. - # Very scary / ugly escaping incoming. if(arg_PACKAGES) set(packages_list "") @@ -667,9 +666,8 @@ function(qt_config_compile_test name) foreach(p ${arg_PACKAGES}) if(p STREQUAL PACKAGE) if(package_entry) - # Use 6 backslashes + ; which will be collapsed when doing variable - # expansion at multiple stages. - list(JOIN package_entry "\\\\\\;" package_entry_string) + # Encode the ";" into "\;" to separate the arguments of a find_package call. + string(REPLACE ";" "\\;" package_entry_string "${package_entry}") list(APPEND packages_list "${package_entry_string}") endif() @@ -680,18 +678,15 @@ function(qt_config_compile_test name) endforeach() # Parse final entry. if(package_entry) - list(JOIN package_entry "\\\\\\;" package_entry_string) + string(REPLACE ";" "\\;" package_entry_string "${package_entry}") list(APPEND packages_list "${package_entry_string}") endif() - # Before the join, packages_list has 3 backslashes + ; for each package part - # (name, component) if you display them. - # After the join, packages_list has 2 backslashes + ; for each package part, and a - # '\;' to separate package entries. - list(JOIN packages_list "\;" packages_list) + # Encode the ";" again. + string(REPLACE ";" "\\;" packages_list "${packages_list}") - # Finally when appending the joined string to the flags, the flags are separated by - # ';', the package entries by '\;', and the packages parts of an entry by '\\;'. + # The flags are separated by ';', the find_package entries by '\;', + # and the package parts of an entry by '\\;'. # Example: # WrapFoo\\;6\\;COMPONENTS\\;bar\;WrapBaz\\;5 list(APPEND flags "-DQT_CONFIG_COMPILE_TEST_PACKAGES:STRING=${packages_list}") -- cgit v1.2.3