[CMake] compiler independent compiler flags

🐋 Jan Hegewald jan.hegewald at awi.de
Fri Feb 5 05:36:34 EST 2016


Dear all,
do you know a best practice on how to specify compiler flags without knowing in advance which compiler will be used?
Its about Fortran projects, where I e.g. want to explicitly enable the preprocessor, or make all default real values 8 byte wide. This could be done as such:
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
  set(CMAKE_Fortran_FLAGS "-fpp -r8")
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU")
  set(CMAKE_Fortran_FLAGS "-cpp -fdefault-real-8")
endif()

Cmake has the cmake-compile-features and I though maybe some similar mechanism exists for above mentioned compiler switches. So I could say
target_compile_features(mylib PRIVATE f_preprocessor f_real_8)

Thanks for sharing your advise,
Jan




More information about the CMake mailing list