Remove compilation flags for a given target

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

Remove compilation flags for a given target

Benjamin Orgogozo
Hello,

in our code base we would like to add a warning compilation flags.
Nevertheless, this flag prevents us from compiling a few targets so we
would like to remove this flag for the given targets.

If I'm right (I'm far from being a cmake expert) there are two ways to
define "global" compilation flags:
1- set the CXX_COMPILE_FLAGS variable;
2- use add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-WMyFavouriteWarning).

Since I don't want to *add* a compilation flags but remove one, I would
like to retrieve the properties of the target
(get_target_property(my_compilation_flags TARGET COMPILE_FLAGS)), and
then modify those and use it to set the properties of the target.

Two questions for me remain:
1- How do I get *all* the compilation flags used for a target?
get_target_property doesn't return flags is CXX_COMPILE_FLAGS nor those
added by add_compile_options.
2- How do I *replace* compilation flags and don't *add* compilation
flags? Both target_compile_options and set_target_properties seems to
*add* flags and don't replace.

Everything is tested under linux and cmake 3.13.3.

Thanks for you help, any pointer to a ressource that might contain
useful information for this problem would be really appreciated.

Regards,

--
 Benjamin Orgogozo
--

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: Remove compilation flags for a given target

Mateusz Loskot
On Thu, 4 Apr 2019 at 14:47, Benjamin Orgogozo <[hidden email]> wrote:
>
> If I'm right (I'm far from being a cmake expert) there are two ways to
> define "global" compilation flags:
> 1- set the CXX_COMPILE_FLAGS variable;
> 2- use add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-WMyFavouriteWarning).

The list should rather be, in preference/priority order

1. https://cmake.org/cmake/help/latest/command/target_compile_options.html
2. add_compile_options

And, if you really, really need
3. append to CMAKE_CXX_FLAGS

> Since I don't want to *add* a compilation flags but remove one, I would
> like to retrieve the properties of the target
> (get_target_property(my_compilation_flags TARGET COMPILE_FLAGS)), and
> then modify those and use it to set the properties of the target.
>
> Two questions for me remain:
> 1- How do I get *all* the compilation flags used for a target?
> get_target_property doesn't return flags is CXX_COMPILE_FLAGS nor those
> added by add_compile_options.

Are you certain you've got the variable name right?
https://cmake.org/cmake/help/latest/search.html?q=CXX_COMPILE_FLAGS

> 2- How do I *replace* compilation flags and don't *add* compilation
> flags? Both target_compile_options and set_target_properties seems to
> *add* flags and don't replace.

See  https://cmake.org/pipermail/cmake/2018-December/068716.html

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--

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
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: Remove compilation flags for a given target

Marc Herbert
In reply to this post by Benjamin Orgogozo

in our code base we would like to add a warning compilation flags.
Nevertheless, this flag prevents us from compiling a few targets so we
would like to remove this flag for the given targets.

Since I don't want to *add* a compilation flags but remove one, I would
like to retrieve the properties of the target
(get_target_property(my_compilation_flags TARGET COMPILE_FLAGS)), and
then modify those and use it to set the properties of the target.

Instead of removing, have you tried appending the -Wno-fubar flag that turns back off these
specific warnings for these specific files?

With gcc for instance: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
"Each of these specific warning options also has a negative form beginning ‘-Wno-’
to turn off warnings; for example, -Wno-implicit. [...] For options of the same specificity,
the last one takes effect"


--

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: Remove compilation flags for a given target

Benjamin Orgogozo
In reply to this post by Mateusz Loskot
On Thu, Apr 04, 2019 at 06:00:43PM +0200, Mateusz Loskot wrote:
> The list should rather be, in preference/priority order
>
> 1. https://cmake.org/cmake/help/latest/command/target_compile_options.html
> 2. add_compile_options

Yes, it's what I understood from documentation.

> Are you certain you've got the variable name right?
> https://cmake.org/cmake/help/latest/search.html?q=CXX_COMPILE_FLAGS

Yes yes, I triple checked it. But I would have preferred to have made an
error here. :)

> See  https://cmake.org/pipermail/cmake/2018-December/068716.html

Thanks for the link and your time.

--
 Benjamin Orgogozo
--

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: Remove compilation flags for a given target

Benjamin Orgogozo
In reply to this post by Marc Herbert
On Fri, Apr 05, 2019 at 07:56:25PM -0700, Marc Herbert wrote:
>    Instead of removing, have you tried appending the -Wno-fubar flag that
>    turns back off these
>    specific warnings for these specific files?

Ah, yes, it will actually work... Not the answer that I was expecting
but clearly a solution for this particular problem.
I find it strange that there is no way to remove properties from a
target but it seems that it is really not possible...

Thanks for you help!

--
 Benjamin Orgogozo
--

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: Remove compilation flags for a given target

Florent Castelli
I believe that your targets should be using something like:
target_compile_options(yourlib PRIVATE -Wwhatever)

They will be built with said warnings, but it won't be propagated to consumers of the library. So you shouldn't have to remove anything.

On Tue, Apr 9, 2019 at 8:47 AM Benjamin Orgogozo <[hidden email]> wrote:
On Fri, Apr 05, 2019 at 07:56:25PM -0700, Marc Herbert wrote:
>    Instead of removing, have you tried appending the -Wno-fubar flag that
>    turns back off these
>    specific warnings for these specific files?

Ah, yes, it will actually work... Not the answer that I was expecting
but clearly a solution for this particular problem.
I find it strange that there is no way to remove properties from a
target but it seems that it is really not possible...

Thanks for you help!

--
 Benjamin Orgogozo
--

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