Skip to content

Commit 8d13ade

Browse files
committed
h5fortran_hdf5_nobuild option to disable auto-build
1 parent 641a527 commit 8d13ade

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

CMakePresets.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
"FETCHCONTENT_TRY_FIND_PACKAGE_MODE": "NEVER"
2424
}
2525
},
26-
{ "name": "no-build", "inherits": "default",
27-
"displayName": "Don't build HDF5 and ZLib from source with h5fortran if not found",
26+
{ "name": "no-build-hdf5", "inherits": "default",
27+
"displayName": "Don't build HDF5 and ZLib from source if not found",
2828
"cacheVariables": {
29-
"FETCHCONTENT_TRY_FIND_PACKAGE_MODE": "ALWAYS",
30-
"FETCHCONTENT_FULLY_DISCONNECTED": true
29+
"h5fortran_hdf5_nobuild": true
3130
}
3231
},
3332
{ "name": "debug", "inherits": "default",
@@ -67,6 +66,7 @@
6766
"buildPresets": [
6867
{ "name": "default", "configurePreset": "default" },
6968
{ "name": "build", "configurePreset": "build", "inherits": "default" },
69+
{ "name": "no-build-hdf5", "configurePreset": "no-build-hdf5", "inherits": "default" },
7070
{ "name": "shared", "configurePreset": "shared", "inherits": "default" },
7171
{
7272
"name": "explain",
@@ -137,6 +137,14 @@
137137
{ "type": "build", "name": "build" }
138138
]
139139
},
140+
{
141+
"name": "no-build-hdf5",
142+
"displayName": "Don't build HDF5 and ZLib from source if not found",
143+
"steps": [
144+
{ "type": "configure", "name": "no-build-hdf5" },
145+
{ "type": "build", "name": "no-build-hdf5" }
146+
]
147+
},
140148
{
141149
"name": "debug",
142150
"displayName": "Build and Test in Debug mode",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ h5fortran is designed for easy use using static or shared linking from your proj
3636
If using CMake, h5fortran will automatically build the HDF5 library (and Zlib if HDF5 2.x) from source if a compiler-compatible HDF5 is not found on the system.
3737
HDF5 auto-build options include:
3838

39-
* To disable the auto-build of HDF5 use `cmake --preset no-build`
39+
* To disable the auto-build of HDF5 use `cmake --preset no-build-hdf5`
4040
* To always build HDF5 from source, set `cmake --preset build`
4141
* To use CMake factory FindHDF5 instead of our custom FindHDF5.cmake use `cmake -Dh5fortran_find_hdf5_factory=yes`
4242
* To disable the use of HDF5 compiler wrappers in finding HDF5 use `cmake -DHDF5_NO_FIND_WRAPPER=yes`

cmake/hdf5.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ endif()
110110

111111
if(NOT TARGET HDF5::HDF5)
112112

113-
FetchContent_Declare(HDF5 URL ${hdf5_url} FIND_PACKAGE_ARGS COMPONENTS HL Fortran C)
114-
# "C" as well so that link tests work and corner cases OK
115-
116-
FetchContent_MakeAvailable(HDF5)
117-
113+
if(h5fortran_hdf5_nobuild)
114+
find_package(HDF5 REQUIRED COMPONENTS HL Fortran C)
115+
else()
116+
FetchContent_Declare(HDF5 URL ${hdf5_url} FIND_PACKAGE_ARGS COMPONENTS HL Fortran C)
117+
# "C" as well so that link tests work and corner cases OK
118+
FetchContent_MakeAvailable(HDF5)
118119
endif()
119120

120121

options.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include(GNUInstallDirs)
55
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
66

77
option(h5fortran_hdf5_zlib "use Zlib when building HDF5" ON)
8+
option(h5fortran_hdf5_nobuild "only find HDF5, do not build HDF5" OFF)
89

910
option(h5fortran_warning_as_error "treat warnings as errors" OFF)
1011

0 commit comments

Comments
 (0)