Change internal flag organization in CMake build to not be global (#2053)
[WRF.git] / external / io_netcdfpar / CMakeLists.txt
blob9536023c58fee773ef9914d8f4aba7a76f605541
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(
20                       ${FOLDER_COMPILE_TARGET}
21                         PUBLIC
22                           $<$<BOOL:${USE_OPENMP}>:$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_Fortran>>
23                           $<$<BOOL:${USE_MPI}>:$<TARGET_NAME_IF_EXISTS:MPI::MPI_Fortran>>
24                           ${netCDF_LIBRARIES}
25                           ${netCDF-Fortran_LIBRARIES}
26                       )
28 # Because of the way netCDF provides its info and the way cmake auto-gens RPATH, we need to help it along
29 target_link_directories(
30                         ${FOLDER_COMPILE_TARGET}
31                         PUBLIC
32                           ${netCDF_LIBRARY_DIR}
33                           ${netCDF-Fortran_LIBRARY_DIR}
34                         )
36 target_include_directories(
37                             ${FOLDER_COMPILE_TARGET}
38                             PUBLIC
39                               $<TARGET_PROPERTY:${FOLDER_COMPILE_TARGET},Fortran_MODULE_DIRECTORY>
40                               $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/external/ioapi_share>
41                               $<INSTALL_INTERFACE:include/external/ioapi_share>
42                               ${netCDF_INCLUDE_DIRS}
43                               ${netCDF-Fortran_INCLUDE_DIRS}
44                             PRIVATE
45                               ${CMAKE_CURRENT_SOURCE_DIR}
46                             )
49 # First preprocess
50 get_target_property   ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES )
51 wrf_c_preproc_fortran( 
52                         TARGET_NAME     ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io
53                         OUTPUT_DIR      ${CMAKE_CURRENT_BINARY_DIR}/preproc/
54                         EXTENSION       ".f90"
55                         INCLUDES        ${FOLDER_COMPILE_TARGET_INCLUDES}
56                         DEFINITIONS     ${PROJECT_COMPILE_DEFINITIONS}
57                         SOURCES         wrf_io.F90
58                         )
60 # Now M4 preprocess
61 wrf_m4_preproc_fortran( 
62                         TARGET_NAME     ${FOLDER_COMPILE_TARGET}_m4_preproc_wrf_io
63                         OUTPUT_DIR      ${CMAKE_CURRENT_BINARY_DIR}/preproc/
64                         PREFIX          "m4_preproc_"
65                         EXTENSION       ".f90"
66                         SOURCES         ${CMAKE_CURRENT_BINARY_DIR}/preproc/wrf_io.f90
67                         DEPENDENCIES    ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io
68                         TARGET_SCOPE    ${FOLDER_COMPILE_TARGET}
69                         FLAGS           ${M4_FLAGS}
70                         )
72 add_dependencies( ${FOLDER_COMPILE_TARGET} ${FOLDER_COMPILE_TARGET}_m4_preproc_wrf_io )
74 target_sources(
75                 ${FOLDER_COMPILE_TARGET}
76                 PRIVATE
77                   ${CMAKE_CURRENT_BINARY_DIR}/preproc/m4_preproc_wrf_io.f90
78                   module_wrfsi_static.F90
79                   field_routines.F90
80                   )
82 # Now build diffwrf
83 set( DIFFWRF_TARGET diffwrf_ncpar )
84 add_executable(
85                 ${DIFFWRF_TARGET}
86                 diffwrf.F90
87                 ${PROJECT_SOURCE_DIR}/frame/clog.c
88                 ${PROJECT_SOURCE_DIR}/frame/module_wrf_error.F
89                 ${PROJECT_SOURCE_DIR}/frame/wrf_debug.F
90                 )
92 target_link_libraries(
93                       ${DIFFWRF_TARGET}
94                         PRIVATE
95                           ${FOLDER_COMPILE_TARGET}
96                       )
97 set_target_properties( 
98                       ${DIFFWRF_TARGET}
99                         PROPERTIES
100                           # Just dump everything in here
101                           Fortran_MODULE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/modules/${DIFFWRF_TARGET}
102                           Fortran_FORMAT           FREE
103                       )
106 install(
107         TARGETS ${FOLDER_COMPILE_TARGET} ${DIFFWRF_TARGET}
108         EXPORT  ${EXPORT_NAME}Targets
109         RUNTIME DESTINATION bin/
110         ARCHIVE DESTINATION lib/
111         LIBRARY DESTINATION lib/
112         )