get complete list of compile definitions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

get complete list of compile definitions

Robert Schwarzelt
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


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: get complete list of compile definitions

Magnus Therning

Robert Schwarzelt <[hidden email]> writes:

> 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?
Not to discourage you, but *every time* I've asked a question along the
lines of "how can I get a list of foo for a source file / target at
cmake configuration time" the answer has been "oh, that's not easy", or
even "oh, that's not possible". In every case I've resorted to trying to
find a way to push what I want to do until build time.

If you *can* find a way to do it post-configuration time I believe you will have
access to everything you need if you set "CMAKE_EXPORT_COMPILE_COMMANDS"
and then look at the resulting `compile_commands.json`.

/M

--
Magnus Therning              OpenPGP: 0x927912051716CE39
email: [hidden email]   jabber: [hidden email]
twitter: magthe               http://therning.org/magnus

Finagle's Second Law:
Always keep a record of data — it indicates you've been working.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

signature.asc (847 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: get complete list of compile definitions

Volker Enderlein
Am 04/04/2017 um 11:17 schrieb Magnus Therning:

> Robert Schwarzelt <[hidden email]> writes:
>
>> 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?
> Not to discourage you, but *every time* I've asked a question along the
> lines of "how can I get a list of foo for a source file / target at
> cmake configuration time" the answer has been "oh, that's not easy", or
> even "oh, that's not possible". In every case I've resorted to trying to
> find a way to push what I want to do until build time.
>
> If you *can* find a way to do it post-configuration time I believe you will have
> access to everything you need if you set "CMAKE_EXPORT_COMPILE_COMMANDS"
> and then look at the resulting `compile_commands.json`.
>
> /M
>
> --
> Magnus Therning              OpenPGP: 0x927912051716CE39
> email: [hidden email]   jabber: [hidden email]
> twitter: magthe               http://therning.org/magnus
>
> Finagle's Second Law:
> Always keep a record of data — it indicates you've been working.
>
>

I successfully used the following commands to get the
INTERFACE_COMPILE_DEFINITIONS and the COMPILE_DEFINITIONS of a target
(yes, both of them may exist). And because the OP has specified
INTERFACE_COMPILE_DEFINITIONS he should evaluate that property of the
target.

get_target_property(_if_compile_defs YourTargetNameHere
INTERFACE_COMPILE_DEFINITIONS)

get_target_property(_compile_defs YourTargetNameHere COMPILE_DEFINITIONS)

Cheers Volker


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Loading...