[CMake] Erasing a compiler flags

Philip Lowman philip at yhbt.com
Mon Mar 2 23:17:12 EST 2009


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.

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()


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

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090302/7d044308/attachment-0001.htm>


More information about the CMake mailing list