1 | cmake_minimum_required(VERSION 3.16) |
---|
2 | list(APPEND CMAKE_MESSAGE_CONTEXT NetCDF95) |
---|
3 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build") |
---|
4 | project(NetCDF95 LANGUAGES Fortran C) |
---|
5 | enable_testing() |
---|
6 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
---|
7 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release Profile) |
---|
8 | add_library(netcdf95 nf95_abort.f90 netcdf95.f90 nf95_def_dim.f90 |
---|
9 | nf95_inq_dimid.f90 nf95_inquire_dimension.f90 nf95_constants.f90 |
---|
10 | nc_constants.f90) |
---|
11 | add_subdirectory(Attributes) |
---|
12 | add_subdirectory(Datasets) |
---|
13 | add_subdirectory(Groups) |
---|
14 | add_subdirectory(Variables) |
---|
15 | set_target_properties(netcdf95 PROPERTIES Fortran_MODULE_DIRECTORY |
---|
16 | ${PROJECT_BINARY_DIR}/modules) |
---|
17 | target_include_directories(netcdf95 PUBLIC |
---|
18 | $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/modules>) |
---|
19 | |
---|
20 | if(CMAKE_Fortran_COMPILER_ID MATCHES NAG) |
---|
21 | target_include_directories(netcdf95 PRIVATE ${CMAKE_CURRENT_LIST_DIR}) |
---|
22 | endif() |
---|
23 | |
---|
24 | find_package(netCDF REQUIRED) |
---|
25 | find_package(NetCDF_Fortran REQUIRED) |
---|
26 | target_link_libraries(netcdf95 PUBLIC NetCDF_Fortran::netcdff |
---|
27 | PRIVATE netCDF::netcdf) |
---|
28 | add_subdirectory(Tests) |
---|
29 | add_library(${PROJECT_NAME}::netcdf95 ALIAS netcdf95) |
---|
30 | configure_file(${PROJECT_NAME}Config.cmake.in ${PROJECT_NAME}Config.cmake @ONLY) |
---|
31 | |
---|
32 | # Start installation part |
---|
33 | |
---|
34 | if(CMAKE_Fortran_COMPILER_ID MATCHES GNU) |
---|
35 | set(install_include_dir include) |
---|
36 | install(FILES ${PROJECT_BINARY_DIR}/modules/netcdf95.mod TYPE INCLUDE) |
---|
37 | else() |
---|
38 | set(install_include_dir include/${PROJECT_NAME}) |
---|
39 | install(DIRECTORY ${PROJECT_BINARY_DIR}/modules/ DESTINATION |
---|
40 | ${install_include_dir}) |
---|
41 | endif() |
---|
42 | |
---|
43 | install(TARGETS netcdf95 EXPORT ${PROJECT_NAME}Targets INCLUDES |
---|
44 | DESTINATION ${install_include_dir}) |
---|
45 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake |
---|
46 | DESTINATION lib/cmake/${PROJECT_NAME}) |
---|
47 | install(EXPORT ${PROJECT_NAME}Targets DESTINATION |
---|
48 | lib/cmake/${PROJECT_NAME} NAMESPACE ${PROJECT_NAME}::) |
---|
49 | |
---|
50 | # End installation part |
---|
51 | |
---|
52 | export(EXPORT ${PROJECT_NAME}Targets NAMESPACE ${PROJECT_NAME}::) |
---|