When compiling code with debug symbols, I usually also want to enable certain compile-time and run-time checks, like so:
gfortran -c -o hello.o -g -O0 -Wall -fcheck-all -fbacktrace hello.f90
(Yes, it's Fortran, but I assume that it'd work with other languages just the same.)
If I wanted to compile the same with the Intel Fortran Compiler, the command would look like this:
ifort -c -o hello.o -g -O0 -warn all -check all -traceback hello.f90
The only way to compile like this in CMake that I have found so far is something like this:
IF(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -Wall -fcheck=all -fbacktrace")
ELSEIF(${CMAKE_Fortran_COMPILER_ID} MATCHES "Intel")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -warn all -check all -traceback")
ELSE()
message(WARNING "Unable to determine Compiler ID: ${CMAKE_Fortran_COMPILER_ID}")
ENDIF(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")
But this introduces all the hardcoded flags that I wanted to avoid when starting to use CMake. Is there a way to add compiler switches based on what they do, like "Enable all Compile time Warnings" or "Enable all Runtime Checks"?
CMake warning API: coming soon.
The discussion proposes commands like
add_compile_warnings
ortarget_compile_warnings
, following the model ofadd_compile_options
andtarget_compile_definitions
, with warning levels such as:You may study the proposed API and perhaps expose your unsatisfied needs in the discussion.
No, CMakes (in the current version 3.6) does not offer such sets of compiler switches. You have to define them by yourself.
Actually, all compilers offer such a switch like
Wall
. You are not satisfied with the choice of the compiler programmers, how could the CMake programmers do better?