summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-07 14:55:21 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-06-07 14:55:29 (GMT)
commitbdd44eca9b5a458b981caff1010a84ca2aa70819 (patch)
treee0b63f8d760cb4e885fc5664901ca043683ce0b7 /Modules
parent4a7bb7b2550905efc20424490b293934f91e072d (diff)
parentd8dcfa7776002756efbc30e45be305e425103e31 (diff)
downloadCMake-bdd44eca9b5a458b981caff1010a84ca2aa70819.zip
CMake-bdd44eca9b5a458b981caff1010a84ca2aa70819.tar.gz
CMake-bdd44eca9b5a458b981caff1010a84ca2aa70819.tar.bz2
Merge topic 'print-sources'
d8dcfa7776 Tests: Add tests for CMakePrintHelpers b7ddfcfe08 cmake_print_properties(): Update grammar docs e52b9e1270 PrintHelpers: Document argument order restriction d87ed4d88f PrintHelpers: Fix indentation 5fa70e1738 PrintHelpers: Rewrite a few more error messages 2579503f45 PrintHelpers: Fix target SOURCES property Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7331
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakePrintHelpers.cmake75
1 files changed, 48 insertions, 27 deletions
diff --git a/Modules/CMakePrintHelpers.cmake b/Modules/CMakePrintHelpers.cmake
index 8c25a73..fb201dc 100644
--- a/Modules/CMakePrintHelpers.cmake
+++ b/Modules/CMakePrintHelpers.cmake
@@ -10,16 +10,19 @@ e.g. for debugging.
::
- cmake_print_properties([TARGETS target1 .. targetN]
- [SOURCES source1 .. sourceN]
- [DIRECTORIES dir1 .. dirN]
- [TESTS test1 .. testN]
- [CACHE_ENTRIES entry1 .. entryN]
- PROPERTIES prop1 .. propN )
+ cmake_print_properties(<TARGETS [<target1> ...] |
+ SOURCES [<source1> ...] |
+ DIRECTORIES [<dir1> ...] |
+ TESTS [<test1> ...] |
+ CACHE_ENTRIES [<entry1> ...] >
+ PROPERTIES [<prop1> ...] )
This function prints the values of the properties of the given targets,
source files, directories, tests or cache entries. Exactly one of the
-scope keywords must be used. Example::
+scope keywords must be used. The scope keyword and its arguments must
+come before the ``PROPERTIES`` keyword, in the arguments list.
+
+Example::
cmake_print_properties(TARGETS foo bar PROPERTIES
LOCATION INTERFACE_INCLUDE_DIRECTORIES)
@@ -56,17 +59,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 )
+
+ 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}")
- cmake_parse_arguments(CPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ cmake_parse_arguments(
+ CPP "${options}" "${oneValueArgs}" "${cpp_multiValueArgs}" ${ARGN})
- if(CPP_UNPARSED_ARGUMENTS)
- message(FATAL_ERROR "Unknown keywords given to cmake_print_properties(): \"${CPP_UNPARSED_ARGUMENTS}\"")
+ 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 +94,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.
@@ -108,13 +128,14 @@ function(cmake_print_properties)
endif()
if(NOT mode)
- message(FATAL_ERROR "Mode keyword missing in cmake_print_properties() call, must be one of TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES")
+ message(FATAL_ERROR "${_missing_mode_message}")
return()
endif()
list(LENGTH mode modeLength)
if("${modeLength}" GREATER 1)
- message(FATAL_ERROR "Multiple mode keyword used in cmake_print_properties() call, it must be exactly one of TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES")
+ message(FATAL_ERROR
+ "Multiple mode keywords used in cmake_print_properties() call, there must be exactly one of ${_mode_names}.")
return()
endif()
@@ -124,8 +145,8 @@ function(cmake_print_properties)
set(itemExists TRUE)
if(keyword STREQUAL "TARGET")
if(NOT TARGET ${item})
- set(itemExists FALSE)
- string(APPEND msg "\n No such TARGET \"${item}\" !\n\n")
+ set(itemExists FALSE)
+ string(APPEND msg "\n No such TARGET \"${item}\" !\n\n")
endif()
endif()