Skip to content

Commit

Permalink
Use add_compile_options to apply compiler flags
Browse files Browse the repository at this point in the history
Since compiler flags are the same across all targets, this change
applies the flags globally to all targets in the current directory and
below.
  • Loading branch information
SeanBryan51 committed Mar 13, 2024
1 parent b57facb commit c292e97
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ set(CABLE_Intel_Fortran_FLAGS -fp-model precise)
set(CABLE_Intel_Fortran_FLAGS_DEBUG -O0 -g -traceback -fpe0)
set(CABLE_Intel_Fortran_FLAGS_RELEASE -O2)
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(
CABLE_Fortran_FLAGS
add_compile_options(
${CABLE_Intel_Fortran_FLAGS}
"$<$<CONFIG:Release>:${CABLE_Intel_Fortran_FLAGS_RELEASE}>"
"$<$<CONFIG:Debug>:${CABLE_Intel_Fortran_FLAGS_DEBUG}>"
Expand All @@ -31,8 +30,7 @@ set(CABLE_GNU_Fortran_FLAGS -cpp -ffree-form -ffixed-line-length-132)
set(CABLE_GNU_Fortran_FLAGS_DEBUG -O -g -pedantic-errors -Wall -W -Wno-maybe-uninitialized -fbacktrace -ffpe-trap=zero,overflow,underflow -finit-real=nan)
set(CABLE_GNU_Fortran_FLAGS_RELEASE -O3 -Wno-aggressive-loop-optimizations)
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(
CABLE_Fortran_FLAGS
add_compile_options(
${CABLE_GNU_Fortran_FLAGS}
"$<$<CONFIG:Release>:${CABLE_GNU_Fortran_FLAGS_RELEASE}>"
"$<$<CONFIG:Debug>:${CABLE_GNU_Fortran_FLAGS_DEBUG}>"
Expand Down Expand Up @@ -151,15 +149,13 @@ add_library(
src/util/cable_runtime_opts_mod.F90
src/util/masks_cbl.F90
)
target_compile_options(cable_common_objlib PRIVATE ${CABLE_Fortran_FLAGS})
target_link_libraries(cable_common_objlib PRIVATE PkgConfig::NETCDF)

add_executable(
cable
src/offline/cable_driver.F90
"$<TARGET_OBJECTS:cable_common_objlib>"
)
target_compile_options(cable PRIVATE ${CABLE_Fortran_FLAGS})
target_link_libraries(cable PRIVATE PkgConfig::NETCDF)
install(TARGETS cable RUNTIME)

Expand All @@ -173,7 +169,6 @@ if(CABLE_MPI)
src/science/pop/pop_mpi.F90
"$<TARGET_OBJECTS:cable_common_objlib>"
)
target_compile_options(cable-mpi PRIVATE ${CABLE_Fortran_FLAGS})
target_link_libraries(cable-mpi PRIVATE PkgConfig::NETCDF MPI::MPI_Fortran)
install(TARGETS cable-mpi RUNTIME)
endif()

0 comments on commit c292e97

Please sign in to comment.