Skip to content

Commit

Permalink
CMake Chem and Chem+KPP Build (#2018)
Browse files Browse the repository at this point in the history
TYPE: enhancement

KEYWORDS: cmake, chem, kpp

SOURCE: internal

DESCRIPTION OF CHANGES:
Problem:
Current CMake build does not build chem or chem+kpp configurations

Solution:
Build kpp and associated tools, and cmake commands to facilitate
simplified logic of the `configure_wkc` and `compile_wkc` scripts. As
with all CMake builds, all auto-generated source code is placed in the
out-of-source build directory.

Notable differences to make build :
* Use of Bison instead of Yacc as it is more easily accessible for
install and usage as well as backward compatible
* Allow `-j N` parallel jobs to generate KPP sources up to a limit
* Use KPP-generated source file original names (not renamed to
`module_kpp_*`
* Pass `tuv_kpp` a directory to locate where include file is to be
generated, and allow control of file IO mode*
* Allow integration decomp rewrite to specify file locations rather than
hard-coded*
* `registry` uses `-DWRF_CHEM` and `-DWRF_KPP` defines passed at command
line instead of `getenv()` to match all other options*


*Affects make build in subtle ways but do not change user instructions

LIST OF MODIFIED FILES: 
M       CMakeLists.txt
M       chem/CMakeLists.txt
A       chem/KPP/CMakeLists.txt
M       chem/KPP/compile_wkc
A       chem/KPP/kpp/kpp-2.1/CMakeLists.txt
A       chem/KPP/util/wkc/CMakeLists.txt
M       chem/KPP/util/wkc/gen_kpp.c
M       chem/KPP/util/wkc/protos_kpp.h
M       chem/KPP/util/wkc/tuv_kpp.c
A       chem/KPP/util/write_decomp/CMakeLists.txt
M       chem/KPP/util/write_decomp/Makefile
M       chem/KPP/util/write_decomp/integr_edit.c
M       chem/chem_driver.F
M       tools/CMakeLists.txt
M       tools/data.h
M       tools/registry.c

TESTS CONDUCTED: 
1. Reproduction of chem and chem+kpp regtests with cmake is possible now

RELEASE NOTE: 
CMake Chem and Chem+KPP Build
  • Loading branch information
islas authored Jan 24, 2025
1 parent 30a16a1 commit b26e645
Show file tree
Hide file tree
Showing 16 changed files with 660 additions and 121 deletions.
29 changes: 25 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required( VERSION 3.19 )
cmake_minimum_required( VERSION 3.20 )

project( WRF )

Expand Down Expand Up @@ -218,6 +218,13 @@ set( DWORDSIZE 8 )
set( LWORDSIZE 4 )


# To limit the KPP generation to not consume copious amounts of RAM
if ( NOT DEFINED MAX_KPP_GEN_THREADS )
# 1 thread takes about 4.75 GB
set( MAX_KPP_GEN_THREADS 2 )
endif()


########################

################################################################################
Expand Down Expand Up @@ -259,6 +266,7 @@ endif()

if ( ${ENABLE_KPP} AND NOT ${ENABLE_CHEM} )
message( WARNING "ENABLE_KPP requires ENABLE_CHEM but is not set, ignoring" )
set( ENABLE_KPP OFF CACHE BOOL "Force ignore by configuration" FORCE )
endif()


Expand Down Expand Up @@ -497,6 +505,19 @@ if ( ${ENABLE_CTSM} )
# find_package( CTSM REQUIRED )
endif()

if ( ${ENABLE_KPP} )
find_package( BISON REQUIRED )
find_package( FLEX REQUIRED )
if ( ${FLEX_FOUND} AND "${FLEX_LIBRARIES}" STREQUAL "FL_LIBRARY-NOTFOUND" )
message( FATAL_ERROR
"Flex executable found, but libraries were not. Please provide a searchable path for both "
"\n"
"Refer to https://cmake.org/cmake/help/latest/command/find_package.html for more info "
"on providing a suitable path"
)
endif()
endif()

# Will need our own finder
# find_package( GPFS REQUIRED )

Expand Down Expand Up @@ -707,9 +728,9 @@ if ( ${USE_DOUBLE} )
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS DOUBLE_PRECISION )
endif()
if ( ${ENABLE_CHEM} )
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_CHEM=1 )
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_CHEM )
if ( ${ENABLE_KPP} )
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_KPP=1 )
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_KPP )
endif()
endif()
if ( ${ENABLE_CHEM} )
Expand Down Expand Up @@ -942,7 +963,7 @@ add_subdirectory( share )
add_subdirectory( frame )
add_subdirectory( inc )

if ( ${WRF_CHEM} )
if ( ${ENABLE_CHEM} )
add_subdirectory( chem )
endif()

Expand Down
71 changes: 46 additions & 25 deletions chem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ target_include_directories(
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
if ( ${ENABLE_KPP} )
add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" )
add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )
add_subdirectory( KPP )
endif()

########################################################################################################################
#
Expand Down Expand Up @@ -209,31 +214,47 @@ target_sources(
aerosol_driver.F
)

########################################################################################################################
#
# convert_emiss executable
#
########################################################################################################################
add_executable(
convert_emiss
convert_emiss.F
)

target_link_libraries(
convert_emiss
PRIVATE
${PROJECT_NAME}_Core
)
#!TODO: I'm not entirely sure when this exec is supposed to be generated or if it
# is exclusive to the real test case
# ########################################################################################################################
# #
# # convert_emiss executable
# #
# ########################################################################################################################
# set( CONVERT_EMISS_TARGET convert_emiss )
# add_executable(
# ${CONVERT_EMISS_TARGET}
# convert_emiss.F
# )

target_compile_options(
convert_emiss
PRIVATE
${PROJECT_COMPILE_OPTIONS}
)
# target_link_libraries(
# ${CONVERT_EMISS_TARGET}
# PRIVATE
# ${PROJECT_NAME}_Core
# )
# set_target_properties(
# ${CONVERT_EMISS_TARGET}
# PROPERTIES
# # Just dump everything in here
# Fortran_MODULE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/modules/${CONVERT_EMISS_TARGET}/
# Fortran_FORMAT FREE
# )
# target_compile_options(
# convert_emiss
# PRIVATE
# ${PROJECT_COMPILE_OPTIONS}
# )


target_compile_definitions(
convert_emiss
PRIVATE
${PROJECT_COMPILE_DEFINITIONS}
)
# target_compile_definitions(
# convert_emiss
# PRIVATE
# ${PROJECT_COMPILE_DEFINITIONS}
# )
# install(
# TARGETS ${CONVERT_EMISS_TARGET}
# EXPORT ${EXPORT_NAME}Targets
# RUNTIME DESTINATION bin/
# ARCHIVE DESTINATION lib/
# LIBRARY DESTINATION lib/
# )
Loading

0 comments on commit b26e645

Please sign in to comment.