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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to