diff --git a/cmake/cupcake_add_executables.cmake b/cmake/cupcake_add_executables.cmake index cc34897..f362ae4 100644 --- a/cmake/cupcake_add_executables.cmake +++ b/cmake/cupcake_add_executables.cmake @@ -29,7 +29,8 @@ function(cupcake_add_executables) # | { target :: string, scope? :: PUBLIC | PRIVATE | INTERFACE } string(JSON type TYPE "${link}") if(type STREQUAL STRING) - set(target "${link}") + # A JSON string is already quoted. + set(target ${link}) set(scope "PRIVATE") else() string(JSON target GET "${link}" target) diff --git a/cmake/cupcake_add_libraries.cmake b/cmake/cupcake_add_libraries.cmake index 8a513b5..00880b4 100644 --- a/cmake/cupcake_add_libraries.cmake +++ b/cmake/cupcake_add_libraries.cmake @@ -29,7 +29,8 @@ function(cupcake_add_libraries) # | { target :: string, scope? :: PUBLIC | PRIVATE | INTERFACE } string(JSON type TYPE "${link}") if(type STREQUAL STRING) - set(target "${link}") + # A JSON string is already quoted. + set(target ${link}) set(scope "PUBLIC") else() string(JSON target GET "${link}" target) diff --git a/cmake/cupcake_add_tests.cmake b/cmake/cupcake_add_tests.cmake index 1d3532b..55a101e 100644 --- a/cmake/cupcake_add_tests.cmake +++ b/cmake/cupcake_add_tests.cmake @@ -21,7 +21,8 @@ function(cupcake_add_tests) # | { target :: string, scope? :: PUBLIC | PRIVATE | INTERFACE } string(JSON type TYPE "${link}") if(type STREQUAL STRING) - set(target "${link}") + # A JSON string is already quoted. + set(target ${link}) set(scope "PRIVATE") else() string(JSON target GET "${link}" target) diff --git a/cmake/cupcake_find_packages.cmake b/cmake/cupcake_find_packages.cmake index 45f89d3..fe8fcb9 100644 --- a/cmake/cupcake_find_packages.cmake +++ b/cmake/cupcake_find_packages.cmake @@ -14,7 +14,8 @@ function(cupcake_find_packages group) # Select only imports whose `groups` (default: `["main"]`) contain `group`. cupcake_json_get(groups ARRAY "[\"main\"]" "${import}" groups) cupcake_json_to_list(groups "${groups}") - list(FIND groups "${group}" i) + # Group names are quoted JSON strings in the list. + list(FIND groups "\"${group}\"" i) if(i LESS 0) continue() endif() diff --git a/cmake/cupcake_json.cmake b/cmake/cupcake_json.cmake index 9b59603..a15ff53 100644 --- a/cmake/cupcake_json.cmake +++ b/cmake/cupcake_json.cmake @@ -26,6 +26,11 @@ function(cupcake_json_to_list variable array) math(EXPR stop "${count} - 1") foreach(i RANGE ${stop}) string(JSON item GET "${array}" ${i}) + string(JSON type TYPE "${array}" ${i}) + if(type STREQUAL STRING) + # CMake automatically unquotes JSON strings. Re-quote them here. + set(item "\"${item}\"") + endif() list(APPEND list "${item}") endforeach() endif() @@ -37,3 +42,15 @@ function(cupcake_json_get_list variable json) cupcake_json_to_list(list "${list}") set(${variable} "${list}" PARENT_SCOPE) endfunction() + +# Unquote all strings in a list. +# unquote(variable [string...]) +function(cupcake_unquote variable) + foreach(string ${ARGN}) + if(string MATCHES "^\"(.*)\"$") + set(string "${CMAKE_MATCH_1}") + endif() + string(APPEND list "${string}") + endforeach() + set(${variable} "${list}" PARENT_SCOPE) +endfunction() diff --git a/cmake/cupcake_link_libraries.cmake b/cmake/cupcake_link_libraries.cmake index c98fa92..3873bcd 100644 --- a/cmake/cupcake_link_libraries.cmake +++ b/cmake/cupcake_link_libraries.cmake @@ -14,13 +14,15 @@ function(cupcake_link_libraries target scope group) # Select only imports whose `groups` (default: `["main"]`) contain `group`. cupcake_json_get(groups ARRAY "[\"main\"]" "${import}" groups) cupcake_json_to_list(groups "${groups}") - list(FIND groups "${group}" i) + # Group names are quoted JSON strings in the list. + list(FIND groups "\"${group}\"" i) if(i LESS 0) continue() endif() string(JSON name GET "${import}" name) cupcake_json_get(targets ARRAY "[\"${name}::${name}\"]" "${import}" targets) cupcake_json_to_list(targets "${targets}") + cupcake_unquote(targets "${targets}") target_link_libraries(${target} ${scope} ${targets}) endforeach() endfunction()