diff options
Diffstat (limited to 'project/cmake/scripts/common/CMakeHelpers.cmake')
| -rw-r--r-- | project/cmake/scripts/common/CMakeHelpers.cmake | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/project/cmake/scripts/common/CMakeHelpers.cmake b/project/cmake/scripts/common/CMakeHelpers.cmake new file mode 100644 index 0000000..995c38a --- /dev/null +++ b/project/cmake/scripts/common/CMakeHelpers.cmake | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | # This file contains functions that support the debugging of the CMake files. | ||
| 2 | |||
| 3 | # This file shouldn't be included per default in any CMake file. It should be | ||
| 4 | # included and used only on demand. All functions are prefixed with "debug_". | ||
| 5 | # | ||
| 6 | # Usage: | ||
| 7 | # include(scripts/common/CMakeHelpers.cmake) | ||
| 8 | # debug_print_variables() | ||
| 9 | |||
| 10 | # Print all CMake variables. | ||
| 11 | macro(debug_print_variables) | ||
| 12 | get_cmake_property(_variableNames VARIABLES) | ||
| 13 | foreach(_variableName ${_variableNames}) | ||
| 14 | message(STATUS "${_variableName} = ${${_variableName}}") | ||
| 15 | endforeach() | ||
| 16 | endmacro() | ||
| 17 | |||
| 18 | # Get all properties that CMake supports and convert them to a list. | ||
| 19 | function(debug_get_properties VAR) | ||
| 20 | execute_process(COMMAND cmake --help-property-list | ||
| 21 | OUTPUT_VARIABLE _properties) | ||
| 22 | string(REGEX REPLACE ";" "\\\\;" _properties "${_properties}") | ||
| 23 | string(REGEX REPLACE "\n" ";" _properties "${_properties}") | ||
| 24 | list(REMOVE_DUPLICATES _properties) | ||
| 25 | list(REMOVE_ITEM _properties LOCATION) | ||
| 26 | set(${VAR} ${_properties} PARENT_SCOPE) | ||
| 27 | endfunction() | ||
| 28 | |||
| 29 | # List all properties. | ||
| 30 | function(debug_list_properties) | ||
| 31 | debug_get_properties(_properties) | ||
| 32 | message("CMake properties = ${_properties}") | ||
| 33 | endfunction() | ||
| 34 | |||
| 35 | # Print all set properties of a specified target. | ||
| 36 | function(debug_print_target_properties target) | ||
| 37 | if(NOT TARGET ${target}) | ||
| 38 | message(FATAL_ERROR "There is no target named '${target}'") | ||
| 39 | endif() | ||
| 40 | |||
| 41 | debug_get_properties(_properties) | ||
| 42 | |||
| 43 | # Reading LOCATION property is deprecated and triggers a fatal error. | ||
| 44 | string(REGEX REPLACE ";LOCATION;|LOCATION" "" _properties "${_properties}") | ||
| 45 | string(REGEX REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" _properties | ||
| 46 | "${_properties}") | ||
| 47 | foreach(_property ${_properties}) | ||
| 48 | get_property(_value TARGET ${target} PROPERTY ${_property} SET) | ||
| 49 | if(_value) | ||
| 50 | get_target_property(_value ${target} ${_property}) | ||
| 51 | message("${target} ${_property} = ${_value}") | ||
| 52 | endif() | ||
| 53 | endforeach() | ||
| 54 | endfunction() | ||
