[CMake] CMake rebuilding too much

Thomas Sondergaard ts at medical-insight.com
Tue Oct 12 08:08:13 EDT 2010


On 12-10-2010 13:24, Michael Wild wrote:

> The FORCE is OK, but you should do this only once, and only if CMAKE_CXX_FLAGS is the default. You don't want to upset your users, do you? Something like this should do:
>
> if(CMAKE_COMPILER_IS_GNUCXX AND NOT __CHECKED_CXX_FLAGS)
>    # this is the guard so we do this only once
>    set(__CHECKED_CXX_FLAGS TRUE CACHE INTERNAL "Whether we checked the CXX flags already")
>    if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_INIT}")
>      # only override defaults if the user didn't do so already!
>      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} Wall -Woverloaded-virtual -Wno-unknown-pragmas -Werror"
>        CACHE STRING "Flags used by the compiler during all build types." FORCE)
>    endif()
> endif()
>
> This way the flags end up in the cache and can be changed by the user without having to change the CMakeLists.txt file, and it also respects the user's choice of flags if he provides them in the initial CMake-run.
>

Thanks, I'll try it that way.

Thomas



More information about the CMake mailing list