[CMake] Erasing a compiler flags

Leopold Palomo Avellaneda leo at alaxarxa.net
Tue Mar 3 15:54:19 EST 2009


A Dimarts 03 Març 2009, Philip Lowman va escriure:
> On Mon, Mar 2, 2009 at 7:37 AM, Leopold Palomo Avellaneda
>
> <leo at alaxarxa.net>wrote:
> > Hi,
> >
> > I have a problem with one project. There's one file that doesn't accept a
> > some
> > compiler flags because g++ then has problems (templates, etc).
> >
> > So, I would like to set with another valuer the CMAKE_CXX_FLAGS_RELEASE
> > and CMAKE_CXX_FLAGS_RELWITHDEBINFO for an _specific_ target.
> >
> > I have looked in the documentation and I have found how to add
> > (COMPILE_FLAGS)
> > but not how to delete/remove flags. Someone hows how to do it?
>
> I'm not sure if CMake has a good way to remove definitions added to
> CMAKE_CXX_FLAGS or CMAKE_CXX_FLAGS_<FOO>.  I think generally you're
> supposed to avoid adding things to this unless you want it to be compiled
> on all targets.

Well I want to use it in all the targets excepts one. 

> You can use add_definitions() and remove_definitions() for this kind of
> thing provided you don't need it for a particular release type.
>
> if(CMAKE_COMPILER_IS_GNUCC)
>    add_definitions(-Wall)
> endif()
> add_subdirectory(foo)
>
> foo/CMakeLists.txt
> ==========
> if(CMAKE_COMPILER_IS_GNUCC)
>    remove_definitions(-Wall)
> endif()

Ok, you have given me some idea.

> If you do need this for a particular release type you could use
> STRING(REPLACE...) directly on CMAKE_CXX_FLAGS_RELEASE, for example.
> Toplevel:
> =====
> set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -funroll-loops")
> add_subdirectory(foo)
> add_subdirectory(bar)
>
> foo/CMakeLists.txt
> =====
> string(REPLACE "-funroll-loops" "" CMAKE_CXX_FLAGS_RELEASE
> ${CMAKE_CXX_FLAGS_RELEASE})
> add_executable(bar foo.cc)
>
> Hope that helps

Yes, sure. Thanks. It's not exactly what I wanted, but it will help me.

Thanks a lot.

Best regards,

Leo


More information about the CMake mailing list