[CMake] get complete list of compile definitions

Robert Schwarzelt rschwarzelt at gmail.com
Wed Mar 29 06:33:28 EDT 2017


Hi all,
I need to implement a code export function, that will only export code used
in a specific project configuration.
For this purpose I want to use unifdef (http://dotat.at/prog/unifdef/),
which is capable of removing unused #ifdef blocks.

The project uses static libraries like in following example:

add_library(
    foo STATIC
    foo.c
)

add_library(
    bar STATIC
    bar.c
)

target_compile_definitions(bar INTERFACE HAVE_BAR)
target_link_libraries(foo LINK_PUBLIC bar)


Now foo.c will be compiled with -DHAVE_BAR at build time.
To create a custom target using unifdef i need this information at cmake
configure time. I expected to find this in the property COMPILE_DEFINITIONS
of either the source file foo.c or target foo, but both are empty.

Does anyone know, how to get a list of definitions (that will be used at
build time) for targets or files?

Regards,
Robert Schwarzelt




More information about the CMake mailing list