1 cmake_minimum_required( VERSION 3.20 )
2 cmake_policy( SET CMP0118 NEW )
6 enable_language( Fortran )
9 set( EXPORT_NAME ${PROJECT_NAME} )
10 set( INTERNAL_GRIB2_PATH ${CMAKE_INSTALL_PREFIX}/grib2 )
12 if ( NOT DEFINED WRF_DIR )
13 message( STATUS "No WRF_DIR provided, skipping targets that rely on WRF" )
16 # if ( DEFINED CMAKE_TOOLCHAIN_FILE )
17 # set( WPS_CONFIG ${CMAKE_TOOLCHAIN_FILE} )
18 # message( STATUS "Loading configuration file... : ${WPS_CONFIG}" )
19 # include( ${WPS_CONFIG} )
22 # list( APPEND CMAKE_MODULE_PATH )
23 list( APPEND CMAKE_MODULE_PATH
24 ${PROJECT_SOURCE_DIR}/cmake/
25 ${PROJECT_SOURCE_DIR}/cmake/modules
28 # I'd love to be able to do something like this, but this would place a depedency
29 # on WRF which would be bad since who would expect the *WRF Preprocessing System*
30 # to have a strict dependency on WRF. Silly me
31 # if ( DEFINED WRF_DIR )
32 # list( APPEND CMAKE_MODULE_PATH
37 # Use link paths as rpaths
38 set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
39 set( CMAKE_Fortran_PREPROCESS ON )
41 include( CMakePackageConfigHelpers )
42 # include( confcheck )
44 include( wrf_get_version )
47 wrf_get_version( ${PROJECT_SOURCE_DIR}/README )
49 ################################################################################
53 ################################################################################
55 # Through ***MUCH*** debugging, if utilizing MPI_<LANG>_COMPILER
56 # https://cmake.org/cmake/help/latest/module/FindMPI.html#variables-for-locating-mpi
57 # the find logic makes a mess of things by utilizing <mpi> -show[me]
58 # Which may or may not get polluted by the environment
59 # It still technically finds MPI but the output is nonintuitive
60 # saying things like hdf5 or pthread
61 find_package( MPI REQUIRED COMPONENTS Fortran C )
62 add_compile_definitions(
67 if ( DEFINED WRF_MPI_Fortran_FLAGS AND NOT "${WRF_MPI_Fortran_FLAGS}" STREQUAL "" )
69 $<$<COMPILE_LANGUAGE:Fortran>,${WRF_MPI_Fortran_FLAGS}>
73 if ( DEFINED WRF_MPI_C_FLAGS AND NOT "${WRF_MPI_C_FLAGS}" STREQUAL "" )
75 $<$<COMPILE_LANGUAGE:C>,${WRF_MPI_C_FLAGS}>
81 find_package( OpenMP REQUIRED COMPONENTS Fortran C )
82 add_compile_definitions( USE_OPENMP=1 SM_PARALLEL )
87 if ( BUILD_EXTERNALS )
88 add_subdirectory( external )
89 # If we got here everything built, we are safe to add find paths for libs
90 set( ZLIB_ROOT ${INTERNAL_GRIB2_PATH} ) # This may get overridden by HDF5 if zlib is packaged with that
91 set( PNG_ROOT ${INTERNAL_GRIB2_PATH} )
92 set( Jasper_ROOT ${INTERNAL_GRIB2_PATH} )
96 # Now find required libraries, which may have been affected by externals
97 if ( DEFINED WRF_DIR )
98 find_package( WRF COMPONENTS WRF_Core io_netcdf io_grib1 io_int HINTS ${WRF_DIR}/lib )
101 # Find externals now -- this is a little different than normal since we want WRF to
102 # take precedence if it is present on which libraries to use to avoid library splicing
103 # rather than finding our external thirdparty libraries first
104 find_package( ZLIB REQUIRED )
105 find_package( PNG REQUIRED )
106 find_package( Jasper REQUIRED )
108 # Add config definitions
109 message( STATUS "Adding configuration specific definitions : ${WPS_DEFINITIONS}" )
110 # In CMake 2.26 this will not be necessary
111 string( REPLACE " " ";" WPS_DEFINITIONS_LIST ${WPS_DEFINITIONS} )
112 list( TRANSFORM WPS_DEFINITIONS_LIST REPLACE "^-D(.*)" "\\1" )
113 add_compile_definitions(
114 ${WPS_DEFINITIONS_LIST}
115 $<$<COMPILE_LANGUAGE:Fortran>:USE_JPEG2000>
116 $<$<COMPILE_LANGUAGE:Fortran>:USE_PNG>
118 # Whole project flags
120 $<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-fallow-argument-mismatch>
124 # Always build whatever we can
125 add_subdirectory( ungrib )
127 if ( DEFINED WRF_DIR )
128 # WRF Specific things
129 add_subdirectory( metgrid )
130 add_subdirectory( geogrid )
134 ################################################################################
136 ## Install and export
138 ################################################################################
140 # Install to namespace
142 EXPORT ${EXPORT_NAME}Targets
143 DESTINATION lib/cmake/
144 FILE ${EXPORT_NAME}Targets.cmake
145 NAMESPACE ${EXPORT_NAME}::
148 configure_package_config_file(
149 ${PROJECT_SOURCE_DIR}/cmake/template/${EXPORT_NAME}Config.cmake.in
150 ${CMAKE_BINARY_DIR}/${EXPORT_NAME}Config.cmake
151 INSTALL_DESTINATION lib/cmake
154 write_basic_package_version_file(
155 ${CMAKE_BINARY_DIR}/${EXPORT_NAME}ConfigVersion.cmake
156 VERSION ${PROJECT_VERSION}
157 #!TODO Check if this is the type of versioning support we want to use
158 COMPATIBILITY SameMinorVersion
163 ${CMAKE_BINARY_DIR}/${EXPORT_NAME}Config.cmake
164 ${CMAKE_BINARY_DIR}/${EXPORT_NAME}ConfigVersion.cmake
165 DESTINATION lib/cmake
168 # Install some helper files for anyone using this build as part of their code
171 # Trailing / is important
172 ${PROJECT_SOURCE_DIR}/cmake/modules/
180 # ${PROJECT_SOURCE_DIR}/cmake/confcheck.cmake
181 # ${PROJECT_SOURCE_DIR}/cmake/gitinfo.cmake
182 # ${PROJECT_SOURCE_DIR}/cmake/printOption.cmake
183 # ${PROJECT_SOURCE_DIR}/cmake/wrf_get_version.cmake