Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / external / io_pnetcdf / CMakeLists.txt
blob8c7c13823374d98a86a4637772e734434ba9d384
1 # WRF CMake Build
3 get_filename_component( FOLDER_COMPILE_TARGET ${CMAKE_CURRENT_SOURCE_DIR} NAME)
5 add_library(
6             ${FOLDER_COMPILE_TARGET}
7               STATIC
8               )
10 # Do this first to simplify steps later
11 set_target_properties( 
12                       ${FOLDER_COMPILE_TARGET} 
13                         PROPERTIES
14                           Fortran_MODULE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${FOLDER_COMPILE_TARGET}
15                           EXPORT_PROPERTIES        Fortran_MODULE_DIRECTORY
16                       )
19 target_link_libraries(  ${FOLDER_COMPILE_TARGET}
20                           PRIVATE
21                             ${netCDF_LIBRARIES}
22                             ${pnetCDF_LIBRARIES}
23                             $<$<BOOL:${USE_MPI}>:$<TARGET_NAME_IF_EXISTS:MPI::MPI_Fortran>>
24                             $<$<BOOL:${USE_OPENMP}>:$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_Fortran>>
25                         )
27 target_include_directories( ${FOLDER_COMPILE_TARGET}
28                             PRIVATE
29                               ${netCDF_INCLUDE_DIRS}
30                               ${pnetCDF_INCLUDE_DIRS}
31                               ${CMAKE_CURRENT_SOURCE_DIR}
32                               ${CMAKE_CURRENT_SOURCE_DIR}/../ioapi_share
33                               ${CMAKE_INSTALL_PREFIX}/${FOLDER_COMPILE_TARGET}
34                             )
37 # First preprocess
38 get_target_property   ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES )
39 wrf_c_preproc_fortran( 
40                         TARGET_NAME     ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io
41                         OUTPUT_DIR      ${CMAKE_CURRENT_BINARY_DIR}/preproc/
42                         EXTENSION       ".f90"
43                         INCLUDES        ${FOLDER_COMPILE_TARGET_INCLUDES}
44                         DEFINITIONS     ${PROJECT_COMPILE_DEFINITIONS}
45                         SOURCES         wrf_io.F90
46                         )
48 # Now M4 preprocess
49 wrf_m4_preproc_fortran( 
50                         TARGET_NAME     ${FOLDER_COMPILE_TARGET}_m4_preproc_wrf_io
51                         OUTPUT_DIR      ${CMAKE_CURRENT_BINARY_DIR}/preproc/
52                         PREFIX          "m4_preproc_"
53                         EXTENSION       ".f90"
54                         SOURCES         ${CMAKE_CURRENT_BINARY_DIR}/preproc/wrf_io.f90
55                         DEPENDENCIES    ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io
56                         TARGET_SCOPE    ${FOLDER_COMPILE_TARGET}
57                         FLAGS           ${M4_FLAGS}
58                         )
60 add_dependencies( ${FOLDER_COMPILE_TARGET} ${FOLDER_COMPILE_TARGET}_m4_preproc_wrf_io )
62 target_sources(
63                 ${FOLDER_COMPILE_TARGET}
64                 PRIVATE
65                   ${CMAKE_CURRENT_BINARY_DIR}/preproc/m4_preproc_wrf_io.f90
66                   module_wrfsi_static.F90
67                   field_routines.F90
68                   )
70 install(
71         TARGETS ${FOLDER_COMPILE_TARGET}
72         EXPORT  ${EXPORT_NAME}Targets
73         RUNTIME DESTINATION bin/
74         ARCHIVE DESTINATION lib/
75         LIBRARY DESTINATION lib/
76         )