-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMakeLists.txt
102 lines (78 loc) · 2.92 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
cmake_minimum_required(VERSION 3.20...3.30)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Please do out of source build like
cmake -Bbuild")
endif()
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT is_multi_config AND NOT (CMAKE_BUILD_TYPE OR DEFINED ENV{CMAKE_BUILD_TYPE}))
set(CMAKE_BUILD_TYPE Release CACHE STRING "Release default")
endif()
project(h5fortran
LANGUAGES C Fortran
VERSION 4.10.6
)
include(CTest)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(NOT DEFINED CRAY AND DEFINED ENV{PE_ENV})
set(CRAY true)
endif()
# --- avoid Anaconda libraries
find_package(Python COMPONENTS Interpreter)
if(DEFINED ENV{CONDA_PREFIX})
list(APPEND CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
list(APPEND CMAKE_IGNORE_PATH $ENV{CONDA_PREFIX}/bin)
# need CMAKE_IGNORE_PATH for CMake < 3.23
# and to ensure system env var PATH doesn't interfere
# despite CMAKE_IGNORE_PREFIX_PATH
endif()
include(options.cmake)
include(cmake/compilers.cmake)
include(cmake/CheckHDF5.cmake)
if(NOT TARGET HDF5::HDF5 AND (h5fortran_find OR CRAY))
find_package(HDF5 COMPONENTS Fortran)
endif()
if(h5fortran_IS_TOP_LEVEL AND HDF5_FOUND)
check_hdf5()
elseif(NOT TARGET HDF5::HDF5)
include(cmake/hdf5.cmake)
endif()
set(HDF5_VERSION ${HDF5_VERSION} CACHE STRING "HDF5 version")
if(h5fortran_IS_TOP_LEVEL AND (hdf5_parallel OR HDF5_HAVE_PARALLEL))
target_link_libraries(HDF5::HDF5 INTERFACE MPI::MPI_Fortran)
endif()
# HDF5 bug #3663 for HDF5 1.14.2..4, ...?
# https://github.com/HDFGroup/hdf5/issues/3663
if(WIN32 AND CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
if(HDF5_VERSION MATCHES "1.14.[2-4]")
message(VERBOSE "HDF5: applying workaround for HDF5 bug #3663 with Intel oneAPI on Windows")
target_link_libraries(HDF5::HDF5 INTERFACE shlwapi)
endif()
endif()
# --- h5fortran library
add_library(h5fortran)
target_include_directories(h5fortran PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(h5fortran PUBLIC HDF5::HDF5)
set_property(TARGET h5fortran PROPERTY Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
set_property(TARGET h5fortran PROPERTY VERSION ${PROJECT_VERSION})
# GLOBAL needed for use by parent projects
add_library(h5fortran::h5fortran INTERFACE IMPORTED GLOBAL)
target_link_libraries(h5fortran::h5fortran INTERFACE h5fortran)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
# avoid race condition when used by parent projects
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/h5fortran.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS h5fortran EXPORT h5fortran-targets)
add_subdirectory(src)
if(h5fortran_BUILD_TESTING)
add_subdirectory(test)
endif()
# additional Find*.cmake necessary
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindHDF5.cmake
DESTINATION cmake
)
include(cmake/pkgconf.cmake)
include(cmake/install.cmake)
file(GENERATE OUTPUT .gitignore CONTENT "*")