Skip to content

Commit

Permalink
Change internal flag organization in CMake build to not be global (#2053
Browse files Browse the repository at this point in the history
)

TYPE: enhancement

KEYWORDS: cmake, flags, compilation

SOURCE: internal

DESCRIPTION OF CHANGES:
Problem:
The current iteration of the cmake build places all configuration flags
in the global properties of the project. While this works when just
building WRF, integration with other projects' cmake builds if placed
under WRF pollutes their respective build flags.

Solution:
Adjust the layout of the flags to instead carry them in a variable, and
prefer using `target_*` calls for flag usage.

LIST OF MODIFIED FILES: 
M       CMakeLists.txt
M       chem/CMakeLists.txt
M       external/CMakeLists.txt
M       external/io_adios2/CMakeLists.txt
M       external/io_netcdf/CMakeLists.txt
M       external/io_netcdfpar/CMakeLists.txt
M       external/io_pnetcdf/CMakeLists.txt
M       frame/CMakeLists.txt
M       main/CMakeLists.txt
M       phys/CMakeLists.txt
M       tools/CMakeLists.txt

RELEASE NOTE: 
Change internal flag organization in CMake build to not be global
  • Loading branch information
islas authored Oct 14, 2024
1 parent 5ffa840 commit cd8e545
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 153 deletions.
289 changes: 152 additions & 137 deletions CMakeLists.txt

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion chem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,17 @@ target_link_libraries(
convert_emiss
PRIVATE
${PROJECT_NAME}_Core
)
)

target_compile_options(
convert_emiss
PRIVATE
${PROJECT_COMPILE_OPTIONS}
)


target_compile_definitions(
convert_emiss
PRIVATE
${PROJECT_COMPILE_DEFINITIONS}
)
4 changes: 4 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

# Always build

# Suffice it to say everything under this is WRF-specific while also being external
add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" )
add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )

add_subdirectory( io_int )
add_subdirectory( io_grib1 )
add_subdirectory( io_grib_share )
Expand Down
3 changes: 1 addition & 2 deletions external/io_adios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ target_include_directories( ${FOLDER_COMPILE_TARGET}


# First preprocess
get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
get_target_property ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES )
wrf_c_preproc_fortran(
TARGET_NAME ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/
EXTENSION ".f90"
INCLUDES ${FOLDER_COMPILE_TARGET_INCLUDES}
DEFINITIONS ${DIR_DEFS}
DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS}
SOURCES wrf_io.F90
)

Expand Down
3 changes: 1 addition & 2 deletions external/io_netcdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ target_include_directories(


# First preprocess
get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
get_target_property ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES )
wrf_c_preproc_fortran(
TARGET_NAME ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/
EXTENSION ".f90"
INCLUDES ${FOLDER_COMPILE_TARGET_INCLUDES}
DEFINITIONS ${DIR_DEFS}
DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS}
SOURCES wrf_io.F90
)

Expand Down
3 changes: 1 addition & 2 deletions external/io_netcdfpar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ target_include_directories(


# First preprocess
get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
get_target_property ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES )
wrf_c_preproc_fortran(
TARGET_NAME ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/
EXTENSION ".f90"
INCLUDES ${FOLDER_COMPILE_TARGET_INCLUDES}
DEFINITIONS ${DIR_DEFS}
DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS}
SOURCES wrf_io.F90
)

Expand Down
3 changes: 1 addition & 2 deletions external/io_pnetcdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ target_include_directories( ${FOLDER_COMPILE_TARGET}


# First preprocess
get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
get_target_property ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES )
wrf_c_preproc_fortran(
TARGET_NAME ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/
EXTENSION ".f90"
INCLUDES ${FOLDER_COMPILE_TARGET_INCLUDES}
DEFINITIONS ${DIR_DEFS}
DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS}
SOURCES wrf_io.F90
)

Expand Down
5 changes: 2 additions & 3 deletions frame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ set(
# Generate all the combinations dynamically, not a fan of this file breakdown
########################################################################################################################
set( nl_dyn_source )
get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( n RANGE 0 7 )

wrf_c_preproc_fortran(
Expand All @@ -25,7 +24,7 @@ foreach( n RANGE 0 7 )
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/inc
DEPENDENCIES registry_code
DEFINITIONS ${DIR_DEFS} NNN=${n} NL_set_ROUTINES
DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} NNN=${n} NL_set_ROUTINES
SOURCES nl_access_routines.F
)
wrf_c_preproc_fortran(
Expand All @@ -36,7 +35,7 @@ foreach( n RANGE 0 7 )
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/inc
DEPENDENCIES registry_code
DEFINITIONS ${DIR_DEFS} NNN=${n} NL_get_ROUTINES
DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} NNN=${n} NL_get_ROUTINES
SOURCES nl_access_routines.F
)

Expand Down
2 changes: 2 additions & 0 deletions hydro/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# additions that WRF-Hydro's top CMakeLists.txt handles
add_compile_options( ${PROJECT_COMPILE_OPTIONS} )
add_compile_definitions( ${PROJECT_COMPILE_DEFINITIONS} )
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/hydro/mods)
add_definitions(-DMPP_LAND)
if (WRF_HYDRO_NUDGING STREQUAL "1")
Expand Down
3 changes: 3 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# WRF CMake Build
set( FOLDER_COMPILE_TARGETS )

add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" )
add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )

# First make true executables
if ( ${WRF_CORE} STREQUAL "PLUS" )
add_executable(
Expand Down
3 changes: 1 addition & 2 deletions phys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
# Quickly preprocess some files so that cmake can understand the module dependencies
#
########################################################################################################################
get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
wrf_c_preproc_fortran(
TARGET_NAME module_ra_rrtmg_preproc
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/
EXTENSION ".f90"
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDENCIES registry_code
DEFINITIONS ${DIR_DEFS}
DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS}
SOURCES module_ra_rrtmg_lwk.F
module_ra_rrtmg_lwf.F
module_ra_rrtmg_swk.F
Expand Down
5 changes: 3 additions & 2 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# WRF CMake Build
add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" )
add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )

#!TODO ORGANIZE THIS FOLDER
set( FOLDER_COMPILE_TARGET registry )
Expand Down Expand Up @@ -117,10 +119,9 @@ foreach( n RANGE 0 31 )
)
endforeach()

get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
wrf_expand_definitions(
RESULT_VAR REGISTRY_DEFS
DEFINITIONS ${DIR_DEFS}
DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS}
)

# How this is not a bigger thing or not resolved is beyond me
Expand Down

0 comments on commit cd8e545

Please sign in to comment.