[CMake] Removing compiler flags for GCC for specific target (3 methods that don't work right)
Ryan Pavlik
rpavlik at iastate.edu
Tue May 11 18:08:14 EDT 2010
On 5/11/2010 9:52 AM, Alok Govil wrote:
> Hi all,
>
> I am setting CMAKE_CXX_FLAGS to "-Wall -ansi -pedantic" but would like
> to remove these flags for compilation
> of UnitTest++. I tried three methods of doing this with some issue
> with each:
>
> 1. string (REPLACE "-Wall" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
> # And likewise for -ansi and -pedantic
>
> 2. set (CMAKE_CXX_FLAGS "")
>
> 3. unset (CMAKE_CXX_FLAGS CACHE)
>
> I am doing the above for both CMAKE_CXX_FLAGS and CMAKE_C_FLAGS.
>
> The problem with 1 and 2 is that they are not working. GCC
> (MinGW-W32) still gives the concerned warnings. I do not get these
> warnings if I do not set these flags at all to begin with.
>
> Method 3 does work. The problem however is that it removes
> CMAKE_CXX_FLAGS globally, not just from CMakeList.txt for UnitTest++.
> I could in principle recreate CMAKE_CXX_FLAGS but would like to
> understand what's going on first.
>
> Method 1 worked well for MSVC (using different flags than for GCC).
>
> Here are all my files with relevant lines (shown only for
> CMAKE_CXX_FLAGS but done also for CMAKE_C_FLAGS):
>
> _CXX_Flag_Overrides.cmake_:
> # ...
> if (CMAKE_COMPILER_IS_GNUCXX)
> # message ("CMAKE_COMPILER_IS_GNUCXX")
> set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -Wall -ansi
> -pedantic")
> endif()
> # ...
>
> _CMakeLists.txt (top-level)_
> # ...
> set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
> ${CMAKE_CURRENT_SOURCE_DIR}/CXX_Flag_Overrides.cmake)
> project (projectname)
> # ...
> add_subdirectory (UnitTest++)
> # ...
>
> _CMakeLists.txt (UnitTest++)_
> # ...
> if (CMAKE_COMPILER_IS_GNUCXX) #
> http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_COMPILER_IS_GNULANG
> message ("CMAKE_COMPILER_IS_GNUCXX")
> #string (REPLACE "-Wall" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
> #string (REPLACE "-ansi" "" CMAKE_CXX_FLAGS
> ${CMAKE_CXX_FLAGS})
> #string (REPLACE "-pedantic" "" CMAKE_CXX_FLAGS
> ${CMAKE_CXX_FLAGS})
> #unset (CMAKE_CXX_FLAGS CACHE)
> set (CMAKE_CXX_FLAGS "")
> message ("${CMAKE_CXX_FLAGS}")
> endif()
> # ...
> add_library (UnitTest++ ${Sources})
>
> Thanks,
>
> Alok
You might consider using the target property COMPILE_FLAGS as a more
fine-grained way to control the flags, instead of the build-wide
variable. See the help for more info.
Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100511/3ecef5c5/attachment-0001.htm>
More information about the CMake
mailing list