Use the compiler documentation to see the difference between O2 and O3 and make your choice (: for example, gcc . Here you can find a recommendation to use O2 for stability .
You can use this macro to remove flags:
macro(remove_cxx_flag flag) string(REPLACE "${flag}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endmacro()
[using]
macro(remove_cxx_flag flag) string(REPLACE "${flag}" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") endmacro() message(${CMAKE_CXX_FLAGS_RELEASE}) # print "-O3 -DNDEBUG" remove_cxx_flag("-O3") message(${CMAKE_CXX_FLAGS_RELEASE}) # print "-DNDEBUG"
The macro is used here because you need to update the variable from the parent scope, read this - http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:macro (or you can use the function with PARENT_SCOPE )
NDEBUG is used to disable assert , see What is the NDEBUG preprocessor macro used for (on different platforms)? for more information.
user2288008
source share