cmakepp_lang/types/target

cmakepp_lang/types/target.cpp_is_target(return str2check)

Determines if a string is the name of a target.

CMake maintains an internal list of targets and allows us to query whether a particular identifier is a target via CMake’s native if statement. This function simply wraps a call to if(TARGET ...).

Parameters:
  • return (desc) – Name to use for the resulting identifier.

  • str2check (str) – The string whose targety-ness is in question

Returns:

return will be set to TRUE if str2check is a target and FALSE otherwise.

Return type:

bool

Example Usage

The following is an example showcasing how one would check if the identifier my_target is a target:

include(cmakepp_lang/types/target)
add_library(my_target STATIC IMPORTED)
cpp_is_target(return ${my_target})
message("my_target is a target: ${return}")  # prints TRUE

Error Checking

cpp_is_target will assert that the caller has provided exactly two arguments. If this is not the case an error will be raised.