target_compile_flags and PUBLIC

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

target_compile_flags and PUBLIC

Biddiscombe, John A.
<script type="text/javascript">window["_gaUserPrefs"] = { ioo : function() { return true; } }</script><script type="text/javascript">window["_gaUserPrefs"] = { ioo : function() { return true; } }</script>
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
Reply | Threaded
Open this post in threaded view
|

Re: target_compile_flags and PUBLIC

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

Le mar. 9 oct. 2018 à 09:48, Biddiscombe, John A. <[hidden email]> 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

--

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
Reply | Threaded
Open this post in threaded view
|

Re: target_compile_flags and PUBLIC

Petr Kmoch
In reply to this post by Biddiscombe, John A.
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. <[hidden email]> 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

--

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
Reply | Threaded
Open this post in threaded view
|

Re: target_compile_flags and PUBLIC

Biddiscombe, John A.
In reply to this post by Marc CHEVRIER
<script type="text/javascript">window["_gaUserPrefs"] = { ioo : function() { return true; } }</script>
Marc

Thank you. That fixes it.

JB

From: Marc CHEVRIER [[hidden email]]
Sent: 09 October 2018 09:52
To: Biddiscombe, John A.
Cc: [hidden email]
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. <[hidden email]> 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

--

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