# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
C M a k e P r i n t H e l p e r s
- - - - - - - - - - - - - - - - -
C o n v e n i e n c e f u n c t i o n s f o r p r i n t i n g p r o p e r t i e s a n d v a r i a b l e s , u s e f u l
e . g . f o r d e b u g g i n g .
: :
cmake_print_properties ( [TARGETS target1 .. targetN]
[ S O U R C E S s o u r c e 1 . . s o u r c e N ]
[ D I R E C T O R I E S d i r 1 . . d i r N ]
[ T E S T S t e s t 1 . . t e s t N ]
[ C A C H E _ E N T R I E S e n t r y 1 . . e n t r y N ]
P R O P E R T I E S p r o p 1 . . p r o p N )
T h i s f u n c t i o n p r i n t s t h e v a l u e s o f t h e p r o p e r t i e s o f t h e g i v e n t a r g e t s ,
s o u r c e f i l e s , d i r e c t o r i e s , t e s t s o r c a c h e e n t r i e s . E x a c t l y o n e o f t h e
s c o p e k e y w o r d s m u s t b e u s e d . E x a m p l e : :
cmake_print_properties ( TARGETS foo bar PROPERTIES
L O C A T I O N I N T E R F A C E _ I N C L U D E _ D I R E C T O R I E S )
T h i s w i l l p r i n t t h e L O C A T I O N a n d I N T E R F A C E _ I N C L U D E _ D I R E C T O R I E S p r o p e r t i e s f o r
b o t h t a r g e t s f o o a n d b a r .
: :
cmake_print_variables ( var1 var2 .. varN )
T h i s f u n c t i o n w i l l p r i n t t h e n a m e o f e a c h v a r i a b l e f o l l o w e d b y i t s v a l u e .
E x a m p l e : :
cmake_print_variables ( CMAKE_C_COMPILER CMAKE_MAJOR_VERSION DOES_NOT_EXIST )
G i v e s : :
- - C M A K E _ C _ C O M P I L E R = " / u s r / b i n / g c c " ; C M A K E _ M A J O R _ V E R S I O N = " 2 " ; D O E S _ N O T _ E X I S T = " "
#]=======================================================================]
function ( cmake_print_variables )
set ( msg "" )
foreach ( var ${ ARGN } )
if ( msg )
string ( APPEND msg " ; " )
endif ( )
string ( APPEND msg "${var}=\" ${ ${var } }\ "" )
endforeach ( )
message ( STATUS "${msg}" )
endfunction ( )
function ( cmake_print_properties )
set ( options )
set ( oneValueArgs )
set ( multiValueArgs TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES )
cmake_parse_arguments ( CPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
if ( CPP_UNPARSED_ARGUMENTS )
message ( FATAL_ERROR "Unknown keywords given to cmake_print_properties(): \" ${ CPP_UNPARSED_ARGUMENTS } \"")
return ( )
endif ( )
if ( NOT CPP_PROPERTIES )
message ( FATAL_ERROR "Required argument PROPERTIES missing in cmake_print_properties() call" )
return ( )
endif ( )
set ( mode )
set ( items )
set ( keyword )
if ( CPP_TARGETS )
set ( items ${ CPP_TARGETS } )
set ( mode ${ mode } TARGETS )
set ( keyword TARGET )
endif ( )
if ( CPP_SOURCES )
set ( items ${ CPP_SOURCES } )
set ( mode ${ mode } SOURCES )
set ( keyword SOURCE )
endif ( )
if ( CPP_TESTS )
set ( items ${ CPP_TESTS } )
set ( mode ${ mode } TESTS )
set ( keyword TEST )
endif ( )
if ( CPP_DIRECTORIES )
set ( items ${ CPP_DIRECTORIES } )
set ( mode ${ mode } DIRECTORIES )
set ( keyword DIRECTORY )
endif ( )
if ( CPP_CACHE_ENTRIES )
set ( items ${ CPP_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.
set ( keyword "" )
string ( APPEND keyword CACHE )
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" )
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" )
return ( )
endif ( )
set ( msg "\n" )
foreach ( item ${ items } )
set ( itemExists TRUE )
if ( keyword STREQUAL "TARGET" )
if ( NOT TARGET ${ item } )
set ( itemExists FALSE )
string ( APPEND msg "\n No such TARGET \" ${ item } \" !\n\n " )
endif ( )
endif ( )
if ( itemExists )
string ( APPEND msg " Properties for ${keyword} ${item}:\n" )
foreach ( prop ${ CPP_PROPERTIES } )
get_property ( propertySet ${ keyword } ${ item } PROPERTY "${prop}" SET )
if ( propertySet )
get_property ( property ${ keyword } ${ item } PROPERTY "${prop}" )
string ( APPEND msg " ${item}.${prop} = \" ${ property } \"\n")
else ( )
string ( APPEND msg " ${item}.${prop} = <NOTFOUND>\n" )
endif ( )
endforeach ( )
endif ( )
endforeach ( )
message ( STATUS "${msg}" )
endfunction ( )