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"?