Skip to content

Commit b26e645

Browse files
authored
CMake Chem and Chem+KPP Build (#2018)
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
1 parent 30a16a1 commit b26e645

File tree

16 files changed

+660
-121
lines changed

16 files changed

+660
-121
lines changed

CMakeLists.txt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required( VERSION 3.19 )
1+
cmake_minimum_required( VERSION 3.20 )
22

33
project( WRF )
44

@@ -218,6 +218,13 @@ set( DWORDSIZE 8 )
218218
set( LWORDSIZE 4 )
219219

220220

221+
# To limit the KPP generation to not consume copious amounts of RAM
222+
if ( NOT DEFINED MAX_KPP_GEN_THREADS )
223+
# 1 thread takes about 4.75 GB
224+
set( MAX_KPP_GEN_THREADS 2 )
225+
endif()
226+
227+
221228
########################
222229

223230
################################################################################
@@ -259,6 +266,7 @@ endif()
259266

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

264272

@@ -497,6 +505,19 @@ if ( ${ENABLE_CTSM} )
497505
# find_package( CTSM REQUIRED )
498506
endif()
499507

508+
if ( ${ENABLE_KPP} )
509+
find_package( BISON REQUIRED )
510+
find_package( FLEX REQUIRED )
511+
if ( ${FLEX_FOUND} AND "${FLEX_LIBRARIES}" STREQUAL "FL_LIBRARY-NOTFOUND" )
512+
message( FATAL_ERROR
513+
"Flex executable found, but libraries were not. Please provide a searchable path for both "
514+
"\n"
515+
"Refer to https://cmake.org/cmake/help/latest/command/find_package.html for more info "
516+
"on providing a suitable path"
517+
)
518+
endif()
519+
endif()
520+
500521
# Will need our own finder
501522
# find_package( GPFS REQUIRED )
502523

@@ -707,9 +728,9 @@ if ( ${USE_DOUBLE} )
707728
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS DOUBLE_PRECISION )
708729
endif()
709730
if ( ${ENABLE_CHEM} )
710-
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_CHEM=1 )
731+
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_CHEM )
711732
if ( ${ENABLE_KPP} )
712-
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_KPP=1 )
733+
list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_KPP )
713734
endif()
714735
endif()
715736
if ( ${ENABLE_CHEM} )
@@ -942,7 +963,7 @@ add_subdirectory( share )
942963
add_subdirectory( frame )
943964
add_subdirectory( inc )
944965

945-
if ( ${WRF_CHEM} )
966+
if ( ${ENABLE_CHEM} )
946967
add_subdirectory( chem )
947968
endif()
948969

chem/CMakeLists.txt

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ target_include_directories(
44
PRIVATE
55
${CMAKE_CURRENT_SOURCE_DIR}
66
)
7+
if ( ${ENABLE_KPP} )
8+
add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" )
9+
add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" )
10+
add_subdirectory( KPP )
11+
endif()
712

813
########################################################################################################################
914
#
@@ -209,31 +214,47 @@ target_sources(
209214
aerosol_driver.F
210215
)
211216

212-
########################################################################################################################
213-
#
214-
# convert_emiss executable
215-
#
216-
########################################################################################################################
217-
add_executable(
218-
convert_emiss
219-
convert_emiss.F
220-
)
221-
222-
target_link_libraries(
223-
convert_emiss
224-
PRIVATE
225-
${PROJECT_NAME}_Core
226-
)
217+
#!TODO: I'm not entirely sure when this exec is supposed to be generated or if it
218+
# is exclusive to the real test case
219+
# ########################################################################################################################
220+
# #
221+
# # convert_emiss executable
222+
# #
223+
# ########################################################################################################################
224+
# set( CONVERT_EMISS_TARGET convert_emiss )
225+
# add_executable(
226+
# ${CONVERT_EMISS_TARGET}
227+
# convert_emiss.F
228+
# )
227229

228-
target_compile_options(
229-
convert_emiss
230-
PRIVATE
231-
${PROJECT_COMPILE_OPTIONS}
232-
)
230+
# target_link_libraries(
231+
# ${CONVERT_EMISS_TARGET}
232+
# PRIVATE
233+
# ${PROJECT_NAME}_Core
234+
# )
235+
# set_target_properties(
236+
# ${CONVERT_EMISS_TARGET}
237+
# PROPERTIES
238+
# # Just dump everything in here
239+
# Fortran_MODULE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/modules/${CONVERT_EMISS_TARGET}/
240+
# Fortran_FORMAT FREE
241+
# )
242+
# target_compile_options(
243+
# convert_emiss
244+
# PRIVATE
245+
# ${PROJECT_COMPILE_OPTIONS}
246+
# )
233247

234248

235-
target_compile_definitions(
236-
convert_emiss
237-
PRIVATE
238-
${PROJECT_COMPILE_DEFINITIONS}
239-
)
249+
# target_compile_definitions(
250+
# convert_emiss
251+
# PRIVATE
252+
# ${PROJECT_COMPILE_DEFINITIONS}
253+
# )
254+
# install(
255+
# TARGETS ${CONVERT_EMISS_TARGET}
256+
# EXPORT ${EXPORT_NAME}Targets
257+
# RUNTIME DESTINATION bin/
258+
# ARCHIVE DESTINATION lib/
259+
# LIBRARY DESTINATION lib/
260+
# )

0 commit comments

Comments
 (0)