diff options
author | FeRD (Frank Dana) <ferdnyc@gmail.com> | 2022-06-06 16:25:51 (GMT) |
---|---|---|
committer | FeRD (Frank Dana) <ferdnyc@gmail.com> | 2022-06-06 16:25:51 (GMT) |
commit | 2579503f450f99166408d25161d950450cda0544 (patch) | |
tree | 4b7efeda666ae793ccf23a5683e18fa56acf70fa /Modules | |
parent | 2a56c240391c59a0d78dbf90911f38a79f161f7d (diff) | |
download | CMake-2579503f450f99166408d25161d950450cda0544.zip CMake-2579503f450f99166408d25161d950450cda0544.tar.gz CMake-2579503f450f99166408d25161d950450cda0544.tar.bz2 |
PrintHelpers: Fix target SOURCES property
It's been a long-standing bug in CMakePrintHelpers that the
cmake_print_properties() function cannot print the SOURCES
property of a requested TARGET, confusing it with a request
to print properties of SOURCES.
We work around this by parsing the arguments in two stages,
so that a SOURCES that comes after the PROPERTIES keyword
is handled differently from a SOURCES that comes before it.
This adds the restriction that the "mode" keyword (TARGETS
SOURCES DIRECTORIES etc...) and its arguments **must** precede
the PROPERTIES keyword and its arguments. In other words:
1. Both of these are now valid and will be interpreted correctly,
whereas previously only the first was, and the second caused
a FATAL_ERROR:
cmake_print_properties(SOURCES foo.c PROPERTIES LANGUAGE)
cmake_print_properties(TARGETS foo PROPERTIES SOURCES)
2. This, OTOH, which used to be valid, no longer is, and will
trigger a FATAL_ERROR:
cmake_print_properties(PROPERTIES LANGUAGE SOURCES foo.c)
Fixes: #14883
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CMakePrintHelpers.cmake | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/Modules/CMakePrintHelpers.cmake b/Modules/CMakePrintHelpers.cmake index 8c25a73..0af2d3f 100644 --- a/Modules/CMakePrintHelpers.cmake +++ b/Modules/CMakePrintHelpers.cmake @@ -56,17 +56,34 @@ endfunction() function(cmake_print_properties) set(options ) set(oneValueArgs ) - set(multiValueArgs TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES ) + set(cpp_multiValueArgs PROPERTIES ) + set(cppmode_multiValueArgs TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES ) - cmake_parse_arguments(CPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + string(JOIN " " _mode_names ${cppmode_multiValueArgs}) + set(_missing_mode_message + "Mode keyword missing in cmake_print_properties() call, there must be exactly one of ${_mode_names}") - if(CPP_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown keywords given to cmake_print_properties(): \"${CPP_UNPARSED_ARGUMENTS}\"") + cmake_parse_arguments( + CPP "${options}" "${oneValueArgs}" "${cpp_multiValueArgs}" ${ARGN}) + + if(NOT CPP_PROPERTIES) + message(FATAL_ERROR + "Required argument PROPERTIES missing in cmake_print_properties() call") return() endif() - if(NOT CPP_PROPERTIES) - message(FATAL_ERROR "Required argument PROPERTIES missing in cmake_print_properties() call") + if(NOT CPP_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "${_missing_mode_message}") + return() + endif() + + cmake_parse_arguments( + CPPMODE "${options}" "${oneValueArgs}" "${cppmode_multiValueArgs}" + ${CPP_UNPARSED_ARGUMENTS}) + + if(CPPMODE_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "Unknown keywords given to cmake_print_properties(): \"${CPPMODE_UNPARSED_ARGUMENTS}\"") return() endif() @@ -74,32 +91,32 @@ function(cmake_print_properties) set(items) set(keyword) - if(CPP_TARGETS) - set(items ${CPP_TARGETS}) + if(CPPMODE_TARGETS) + set(items ${CPPMODE_TARGETS}) set(mode ${mode} TARGETS) set(keyword TARGET) endif() - if(CPP_SOURCES) - set(items ${CPP_SOURCES}) + if(CPPMODE_SOURCES) + set(items ${CPPMODE_SOURCES}) set(mode ${mode} SOURCES) set(keyword SOURCE) endif() - if(CPP_TESTS) - set(items ${CPP_TESTS}) + if(CPPMODE_TESTS) + set(items ${CPPMODE_TESTS}) set(mode ${mode} TESTS) set(keyword TEST) endif() - if(CPP_DIRECTORIES) - set(items ${CPP_DIRECTORIES}) + if(CPPMODE_DIRECTORIES) + set(items ${CPPMODE_DIRECTORIES}) set(mode ${mode} DIRECTORIES) set(keyword DIRECTORY) endif() - if(CPP_CACHE_ENTRIES) - set(items ${CPP_CACHE_ENTRIES}) + if(CPPMODE_CACHE_ENTRIES) + set(items ${CPPMODE_CACHE_ENTRIES}) set(mode ${mode} CACHE_ENTRIES) # This is a workaround for the fact that passing `CACHE` as an argument to # set() causes a cache variable to be set. |