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