Even if I don’t want to bind my CMakeLists file to a specific compiler, I still need to include certain options, such as -Wall, which I know that many compilers support.
Currently, I am doing this to set the -Wall and -pedantic flags if accepted by the current compiler:
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wall temp)
if(temp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
check_cxx_compiler_flag(-pedantic temp)
if(temp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
endif()
Is there a better way? Or at least a nicer way to do pretty much the same thing? The above is incredibly verbose and ugly to achieve. A nicer command would look something like this:
enable_cxx_compiler_flags_if_supported(-Wall -pedantic)
source
share