Discussion:
[CMake] target_compile_flags and PUBLIC
Biddiscombe, John A.
2018-10-09 07:40:51 UTC
Permalink
I have a problem with exported flags from a project.

If I use `target_compile_options(hpx PUBLIC ${flags})` hpx is compiled with the flags, and all 500+ tests within the project that depend on hpx inherit the flags too, so they get built correctly. However, the `HPXTargets.cmake` file that is generated with the exported targets, also inherits these flags and lists them in INTERFACE_COMPILE_OPTIONS, so now users are complaining that flags used to compile hpx are being passed onto their project and some of the stuff we use like `-Werror=sign-compare` causes a build fail in their project. If I use `target_compile_options(hpx PRIVATE ${flags})` then the flags are not passed on to the user projects, but also not passed on to the tests either. Is there an easy way of saying, pass these flags to all my projects within this 'PROJECT' but don't export them via the PUBLIC/INTERFACE to 3rd party users?

Thanks

JB
Marc CHEVRIER
2018-10-09 07:52:35 UTC
Permalink
Have a look at '$<BUILD_INTERFACE:...>' and '$<INSTALL_INTERFACE:...>'
generator expressions.

Le mar. 9 oct. 2018 à 09:48, Biddiscombe, John A. <***@cscs.ch> a
écrit :

> I have a problem with exported flags from a project.
>
> If I use `target_compile_options(hpx PUBLIC ${flags})` hpx is compiled
> with the flags, and all 500+ tests within the project that depend on hpx
> inherit the flags too, so they get built correctly. However, the
> `HPXTargets.cmake` file that is generated with the exported targets, also
> inherits these flags and lists them in INTERFACE_COMPILE_OPTIONS, so now
> users are complaining that flags used to compile hpx are being passed onto
> their project and some of the stuff we use like `-Werror=sign-compare`
> causes a build fail in their project. If I use `target_compile_options(hpx
> PRIVATE ${flags})` then the flags are not passed on to the user projects,
> but also not passed on to the tests either. Is there an easy way of saying,
> pass these flags to all my projects within this 'PROJECT' but don't export
> them via the PUBLIC/INTERFACE to 3rd party users?
>
> Thanks
>
> JB
> --
>
> 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:
> https://cmake.org/mailman/listinfo/cmake
>
Biddiscombe, John A.
2018-10-09 08:41:25 UTC
Permalink
Marc

Thank you. That fixes it.

JB
________________________________
From: Marc CHEVRIER [***@gmail.com]
Sent: 09 October 2018 09:52
To: Biddiscombe, John A.
Cc: ***@cmake.org
Subject: Re: [CMake] target_compile_flags and PUBLIC

Have a look at '$<BUILD_INTERFACE:...>' and '$<INSTALL_INTERFACE:...>' generator expressions.

Le mar. 9 oct. 2018 à 09:48, Biddiscombe, John A. <***@cscs.ch<mailto:***@cscs.ch>> a écrit :
I have a problem with exported flags from a project.

If I use `target_compile_options(hpx PUBLIC ${flags})` hpx is compiled with the flags, and all 500+ tests within the project that depend on hpx inherit the flags too, so they get built correctly. However, the `HPXTargets.cmake` file that is generated with the exported targets, also inherits these flags and lists them in INTERFACE_COMPILE_OPTIONS, so now users are complaining that flags used to compile hpx are being passed onto their project and some of the stuff we use like `-Werror=sign-compare` causes a build fail in their project. If I use `target_compile_options(hpx PRIVATE ${flags})` then the flags are not passed on to the user projects, but also not passed on to the tests either. Is there an easy way of saying, pass these flags to all my projects within this 'PROJECT' but don't export them via the PUBLIC/INTERFACE to 3rd party users?

Thanks

JB
--

Powered by www.kitware.com<http://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:
https://cmake.org/mailman/listinfo/cmake
Petr Kmoch
2018-10-09 08:41:04 UTC
Permalink
Hi John,

you could put those flags as PUBLIC into a separate INTERFACE target (let's
call it hpxFlags) and then do

target_libraries(hpx PRIVATE hpxFlags)

Then create another interface target hpxForTests to combine those two
targets:

target_link_libraries(hpxForTests PUBLIC hpx hpxFlags)

And then link all the tests to hpxForTests instead of to hpx.

Petr


On Tue, 9 Oct 2018 at 09:48, Biddiscombe, John A. <***@cscs.ch> wrote:

> I have a problem with exported flags from a project.
>
> If I use `target_compile_options(hpx PUBLIC ${flags})` hpx is compiled
> with the flags, and all 500+ tests within the project that depend on hpx
> inherit the flags too, so they get built correctly. However, the
> `HPXTargets.cmake` file that is generated with the exported targets, also
> inherits these flags and lists them in INTERFACE_COMPILE_OPTIONS, so now
> users are complaining that flags used to compile hpx are being passed onto
> their project and some of the stuff we use like `-Werror=sign-compare`
> causes a build fail in their project. If I use `target_compile_options(hpx
> PRIVATE ${flags})` then the flags are not passed on to the user projects,
> but also not passed on to the tests either. Is there an easy way of saying,
> pass these flags to all my projects within this 'PROJECT' but don't export
> them via the PUBLIC/INTERFACE to 3rd party users?
>
> Thanks
>
> JB
> --
>
> 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:
> https://cmake.org/mailman/listinfo/cmake
>
Loading...