Target Property Macros

blt_add_target_compile_flags

blt_add_target_compile_flags( TO    <target>
                              SCOPE <PUBLIC (Default)| INTERFACE | PRIVATE>
                              FLAGS [FOO [BAR ...]])

Appends compiler flags to a CMake target by appending to the target’s existing flags.

TO

Name of CMake target

SCOPE

Defines the scope of the given flags. Defaults to PUBLIC and is case insensitive.

FLAGS

List of compile flags

This macro provides very similar functionality to CMake’s native add_compile_options() and target_compile_options() commands, but provides more fine-grained scoping for the compile flags on a per target basis.

The given target must be added via CMake’s add_executable() or add_library() commands or with the corresponding blt_add_executable and blt_add_library macros.

PRIVATE flags are used for the given target. INTERFACE flags are inherited by any target that depends on this target. PUBLIC flags are both INTERFACE and PRIVATE.

Note

This macro will strip away leading and trailing whitespace from each flag.

blt_add_target_definitions

blt_add_target_definitions( TO    <target>
                            SCOPE <PUBLIC (Default)| INTERFACE | PRIVATE>
                            TARGET_DEFINITIONS [FOO [BAR ...]])

Appends pre-processor definitions to the given target’s existing flags.

TO

Name of CMake target

SCOPE

Defines the scope of the given definitions. Defaults to PUBLIC and is case insensitive.

TARGET_DEFINITIONS

List of definitions flags

This macro provides very similar functionality to CMake’s native add_definitions() and target_add_definitions() commands, but provides more fine-grained scoping for the compile definitions on a per target basis. Given a list of definitions, e.g., FOO and BAR, this macro adds compiler definitions to the compiler command for the given target, i.e., it will pass -DFOO and -DBAR.

The given target must be added via CMake’s add_executable() or add_library() commands or with the corresponding blt_add_executable and blt_add_library macros.

PRIVATE flags are used for the given target. INTERFACE flags are inherited by any target that depends on this target. PUBLIC flags are both INTERFACE and PRIVATE.

Note

The target definitions can either include or omit the “-D” characters. E.g. the following are all valid ways to add two compile definitions (A=1 and B) to target foo.

Note

This macro will strip away leading and trailing whitespace from each definition.

Example
1blt_add_target_definitions(TO foo TARGET_DEFINITIONS A=1 B)
2blt_add_target_definitions(TO foo TARGET_DEFINITIONS -DA=1 -DB)
3blt_add_target_definitions(TO foo TARGET_DEFINITIONS "A=1;-DB")
4blt_add_target_definitions(TO foo TARGET_DEFINITIONS " " -DA=1;B)

blt_print_target_properties

blt_print_target_properties(TARGET               <target name>
                            CHILDREN             <TRUE|FALSE>
                            PROPERTY_NAME_REGEX  <regular_expression_string>
                            PROPERTY_VALUE_REGEX <regular_expression_string>)

Prints all (or filtered) properties of a given target and optionally its dependencies as well.

TARGET

Name of CMake target (required)

CHILDREN

Whether or not to print the properties of the target’s children recursively (false by default)

PROPERTY_NAME_REGEX

Limit the properties to print by name (all by default)

PROPERTY_VALUE_REGEX

Limit the properties to print by value (all by default)

The given target must be added via add_executable() or add_library() or with the corresponding blt_add_executable, blt_add_library, blt_import_library, or blt_register_library macros.

Output is of the form for each property:
[<target> property] <property>: <value>
Example
1blt_print_target_properties(TARGET foo)
2blt_print_target_properties(TARGET foo CHILDREN TRUE)
3blt_print_target_properties(TARGET foo CHILDREN TRUE PROPERTY_NAME_REGEX "CXX")
4blt_print_target_properties(TARGET foo PROPERTY_NAME_REGEX "CXX" PROPERTY_VALUE_REGEX "ON")

blt_print_variables

blt_print_variables(NAME_REGEX  <regular_expression_string>
                    VALUE_REGEX <regular_expression_string>
                    [IGNORE_CASE])

Prints variables and their values in the current scope, with optional regex filtering on the variable names and values.

NAME_REGEX

Regular expression to apply to variable names (all by default)

VALUE_REGEX

Regular expression to apply to variable values (all by default)

IGNORE_CASE

Optionally ignore case of variable names and values when filtering

Output is of the following form for each variable:
[blt_print_variables] <decorated_name>: <value>

Cache variables are marked as CACHE and will list their type, e.g. CACHE{<name>}:TYPE

Example
1blt_print_variables()
2blt_print_variables( NAME_REGEX "blt" IGNORE_CASE)
3blt_print_variables( NAME_REGEX "_FOUND" VALUE_REGEX "^on$|^true$|^1$" IGNORE_CASE)
4blt_print_variables( NAME_REGEX "LIB|LIBS|LIBRARY|LIBRARIES")

blt_set_target_folder

blt_set_target_folder( TARGET <target>
                       FOLDER <folder>)

Sets the FOLDER property of the given CMake target.

TARGET

Name of CMake target

FOLDER

Name of the folder

This is used to organize properties in an IDE.

This feature is only available when BLT’s ENABLE_FOLDERS option is ON and in CMake generators that support folders (but is safe to call regardless of the generator or value of ENABLE_FOLDERS).

Note

Do not use this macro on header-only, INTERFACE library targets, since this will generate a CMake configuration error.