Skip to content

Commit 4e54bab

Browse files
committed
remove autobuild
1 parent c494aa8 commit 4e54bab

18 files changed

+142
-135
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ jobs:
6767
sudo apt update
6868
sudo apt install --no-install-recommends libhdf5-dev
6969
70-
- run: cmake -B build -DCMAKE_INSTALL_PREFIX=${{ runner.temp }}
70+
- name: Configure NetCDF4
71+
run: cmake -S scripts -B scripts/build -DCMAKE_INSTALL_PREFIX=${{ runner.temp }} -DBUILD_SHARED_LIBS:BOOL=${{ matrix.shared }}
72+
73+
- name: Build/install NetCDF4
74+
run: cmake --build scripts/build --parallel
75+
76+
- name: configure nc4fortran
77+
run: cmake -B build -DCMAKE_INSTALL_PREFIX=${{ runner.temp }} -DCMAKE_PREFIX_PATH=${{ runner.temp }}
78+
7179
- run: cmake --build build --parallel
7280
- run: ctest --test-dir build --preset default
7381
- run: cmake --install build
@@ -127,7 +135,15 @@ jobs:
127135
- name: install libs
128136
run: brew install hdf5
129137

130-
- run: cmake -B build --install-prefix=${{ runner.temp }}
138+
- name: Configure NetCDF4
139+
run: cmake -S scripts -B scripts/build -DCMAKE_INSTALL_PREFIX=${{ runner.temp }} -DBUILD_SHARED_LIBS:BOOL=${{ matrix.shared }}
140+
141+
- name: Build/install NetCDF4
142+
run: cmake --build scripts/build --parallel
143+
144+
- name: configure nc4fortran
145+
run: cmake -B build -DCMAKE_INSTALL_PREFIX=${{ runner.temp }} -DCMAKE_PREFIX_PATH=${{ runner.temp }}
146+
131147
- run: cmake --build build
132148
- run: ctest --test-dir build --preset default
133149
- run: cmake --install build

.github/workflows/ci_windows.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ jobs:
3535

3636
- uses: actions/checkout@v2
3737

38-
- run: cmake --preset multi -DCMAKE_INSTALL_PREFIX=${{ runner.temp }}
38+
- name: Configure NetCDF4
39+
run: cmake -S scripts -B scripts/build -DCMAKE_INSTALL_PREFIX=${{ runner.temp }} -DBUILD_SHARED_LIBS:BOOL=${{ matrix.shared }}
40+
41+
- name: Build/install NetCDF4
42+
run: cmake --build scripts/build --parallel
43+
44+
- name: configure nc4fortran
45+
run: cmake --preset multi -DCMAKE_INSTALL_PREFIX=${{ runner.temp }} -DCMAKE_PREFIX_PATH=${{ runner.temp }}
3946

4047
- run: cmake --build --preset debug
4148
- run: ctest --preset debug

CITATION.cff

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ authors:
55
orcid: https://orcid.org/0000-0002-1637-6526
66
title: nc4fortran
77
doi: 10.5281/zenodo.3598941
8-
date-released: 2021-11-21

CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ endif()
2323
include(cmake/options.cmake)
2424
include(cmake/compilers.cmake)
2525

26-
# --- find or build NetCDF4
26+
find_package(NetCDF COMPONENTS C Fortran)
27+
if(NOT NetCDF_FOUND)
28+
message(FATAL_ERROR "NetCDF not found or working on the system. First build:
2729
28-
include(cmake/netcdf.cmake)
30+
cmake -S scripts -B scripts/build -DCMAKE_INSTALL_PREFIX=~/mylibs
31+
cmake --build scripts/build
32+
33+
Then build nc4fortran:
34+
35+
cmake -B build -DCMAKE_PREFIX_PATH=~/mylibs
36+
cmake --build build
37+
")
38+
endif()
2939

3040
# --- build
3141

cmake/Modules/FindHDF5.cmake

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,19 @@ if(NOT ZLIB_ROOT)
160160
set(ZLIB_ROOT "${HDF5_ROOT};${zlib_dir}")
161161
endif()
162162

163+
164+
set(hdf5_prereqs true PARENT_SCOPE)
165+
163166
if(hdf5_have_zlib)
164-
find_package(ZLIB)
167+
if(HDF5_FIND_REQUIRED)
168+
find_package(ZLIB REQUIRED)
169+
else()
170+
find_package(ZLIB)
171+
endif()
172+
if(NOT ZLIB_FOUND)
173+
set(hdf5_prereqs false PARENT_SCOPE)
174+
return()
175+
endif()
165176

166177
if(hdf5_have_szip)
167178
# Szip even though not used by default.
@@ -170,7 +181,16 @@ if(hdf5_have_zlib)
170181
if(NOT SZIP_ROOT)
171182
set(SZIP_ROOT ${ZLIB_ROOT})
172183
endif()
173-
find_package(SZIP)
184+
if(HDF5_FIND_REQUIRED)
185+
find_package(SZIP REQUIRED)
186+
else()
187+
find_package(SZIP)
188+
endif()
189+
if(NOT SZIP_FOUND)
190+
set(hdf5_prereqs false PARENT_SCOPE)
191+
return()
192+
endif()
193+
174194
list(APPEND CMAKE_REQUIRED_INCLUDES ${SZIP_INCLUDE_DIRS})
175195
list(APPEND CMAKE_REQUIRED_LIBRARIES ${SZIP_LIBRARIES})
176196
endif()
@@ -656,7 +676,7 @@ endfunction(check_fortran_links)
656676

657677
function(check_hdf5_link)
658678

659-
if(NOT HDF5_C_FOUND)
679+
if(NOT (hdf5_prereqs AND HDF5_C_FOUND))
660680
return()
661681
endif()
662682

@@ -777,11 +797,11 @@ if(HDF5_C_FOUND)
777797
detect_config()
778798
endif(HDF5_C_FOUND)
779799

780-
if(HDF5_C_FOUND AND CXX IN_LIST HDF5_FIND_COMPONENTS)
800+
if(hdf5_prereqs AND HDF5_C_FOUND AND CXX IN_LIST HDF5_FIND_COMPONENTS)
781801
find_hdf5_cxx()
782802
endif()
783803

784-
if(HDF5_C_FOUND AND Fortran IN_LIST HDF5_FIND_COMPONENTS)
804+
if(hdf5_prereqs AND HDF5_C_FOUND AND Fortran IN_LIST HDF5_FIND_COMPONENTS)
785805
find_hdf5_fortran()
786806
endif()
787807

@@ -795,9 +815,10 @@ set(CMAKE_REQUIRED_INCLUDES)
795815
# pop off ignored paths so rest of script can find Python
796816
list(REMOVE_ITEM CMAKE_IGNORE_PATH ${h5_ignore_path})
797817

818+
798819
include(FindPackageHandleStandardArgs)
799820
find_package_handle_standard_args(HDF5
800-
REQUIRED_VARS HDF5_C_LIBRARIES HDF5_links
821+
REQUIRED_VARS HDF5_C_LIBRARIES HDF5_links hdf5_prereqs
801822
VERSION_VAR HDF5_VERSION
802823
HANDLE_COMPONENTS
803824
HANDLE_VERSION_RANGE

cmake/Modules/FindSZIP.cmake

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,22 @@ Targets
2727
SZIP Imported Target
2828
#]=======================================================================]
2929

30-
find_package(libaec QUIET)
3130

32-
if(NOT SZIP_FOUND)
31+
find_library(SZIP_LIBRARY
32+
NAMES szip sz
33+
NAMES_PER_DIR
34+
DOC "SZIP API"
35+
)
3336

34-
find_library(SZIP_LIBRARY
35-
NAMES szip sz
36-
NAMES_PER_DIR
37-
DOC "SZIP API")
38-
39-
find_path(SZIP_INCLUDE_DIR
40-
NAMES szlib.h
41-
DOC "SZIP header")
42-
43-
endif()
37+
find_path(SZIP_INCLUDE_DIR
38+
NAMES szlib.h
39+
DOC "SZIP header"
40+
)
4441

4542
include(FindPackageHandleStandardArgs)
4643
find_package_handle_standard_args(SZIP
47-
REQUIRED_VARS SZIP_LIBRARY SZIP_INCLUDE_DIR)
44+
REQUIRED_VARS SZIP_LIBRARY SZIP_INCLUDE_DIR
45+
)
4846

4947
if(SZIP_FOUND)
5048
set(SZIP_INCLUDE_DIRS ${SZIP_INCLUDE_DIR})
@@ -53,8 +51,9 @@ if(SZIP_FOUND)
5351
if(NOT TARGET SZIP::SZIP)
5452
add_library(SZIP::SZIP INTERFACE IMPORTED)
5553
set_target_properties(SZIP::SZIP PROPERTIES
56-
INTERFACE_LINK_LIBRARIES "${SZIP_LIBRARIES}"
57-
INTERFACE_INCLUDE_DIRECTORIES "${SZIP_INCLUDE_DIRS}")
54+
INTERFACE_LINK_LIBRARIES "${SZIP_LIBRARIES}"
55+
INTERFACE_INCLUDE_DIRECTORIES "${SZIP_INCLUDE_DIRS}"
56+
)
5857
endif()
5958
endif()
6059

cmake/abi_check/CMakeLists.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
cmake_minimum_required(VERSION 3.14...3.23)
1+
cmake_minimum_required(VERSION 3.19...3.23)
22
project(abi_check LANGUAGES C Fortran)
33

4+
enable_testing()
5+
46
add_library(addone OBJECT addone.c)
7+
add_executable(main_f main.f90 $<TARGET_OBJECTS:addone>)
8+
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
9+
set_target_properties(main_f PROPERTIES LINKER_LANGUAGE Fortran)
10+
else()
11+
set_target_properties(main_f PROPERTIES LINKER_LANGUAGE C)
12+
endif()
13+
add_test(NAME Fortran_main COMMAND main_f)
14+
15+
add_library(addone_f OBJECT addone.f90)
16+
17+
add_executable(main_c main.c $<TARGET_OBJECTS:addone_f>)
18+
set_target_properties(main_c PROPERTIES LINKER_LANGUAGE C)
19+
add_test(NAME C_main COMMAND main_c)
520

6-
add_executable(main main.f90 $<TARGET_OBJECTS:addone>)
21+
set_tests_properties(Fortran_main C_main PROPERTIES TIMEOUT 10)

cmake/abi_check/addone.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern int addone(int);
2+
13
int addone(int N){
24
return N + 1;
35
}

cmake/abi_check/addone.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module adder
2+
3+
use, intrinsic :: iso_c_binding, only : C_INT
4+
implicit none (type, external)
5+
6+
contains
7+
8+
pure integer(C_INT) function addone(N) bind(C)
9+
integer(C_INT), intent(in), value :: N
10+
addone = N + 1
11+
end function addone
12+
13+
end module adder

cmake/abi_check/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
3+
extern int addone(int);
4+
5+
6+
int main(void) {
7+
8+
if(addone(2) != 3) {
9+
fprintf(stderr, "2 + 1 != %d", addone(2));
10+
return 1;
11+
}
12+
13+
return 0;
14+
}

cmake/abi_check/main.f90

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
program adder
22

3-
implicit none
3+
use, intrinsic :: iso_fortran_env, only : stderr=>error_unit
4+
5+
implicit none (type, external)
46

57
interface
8+
69
integer function addone(N) bind(C)
710
integer, intent(in), value :: N
811
end function addone
12+
913
end interface
1014

1115

12-
if (addone(2) /= 3) error stop "unexpected addone result"
16+
if (addone(2) /= 3) then
17+
write(stderr,*) "ERROR: 2+1 /= ", addone(2)
18+
error stop
19+
endif
1320

14-
print *, "OK: 2+1=3"
21+
print *, "OK: Fortran main with C libraries"
1522

1623

1724
end program

cmake/hdf5.cmake

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
# builds HDF5 library from scratch
2-
# note: the use of "lib" vs. CMAKE_*_LIBRARY_PREFIX is deliberate based on HDF5
3-
# across Intel Fortran on Windows (MSVC-like) vs. Gfortran on Windows vs. Linux.
42

53
include(ExternalProject)
64

7-
set(hdf5_external true CACHE BOOL "autobuild HDF5")
8-
95
if(hdf5_parallel)
106
find_package(MPI REQUIRED COMPONENTS C)
117
endif()
@@ -15,25 +11,7 @@ if(NOT MPI_ROOT AND DEFINED ENV{MPI_ROOT})
1511
set(MPI_ROOT $ENV{MPI_ROOT})
1612
endif()
1713

18-
set(HDF5_LIBRARIES)
19-
foreach(_name hdf5_hl_fortran hdf5_hl_f90cstub hdf5_fortran hdf5_f90cstub hdf5_hl hdf5)
20-
if(BUILD_SHARED_LIBS)
21-
if(WIN32)
22-
list(APPEND HDF5_LIBRARIES ${CMAKE_INSTALL_PREFIX}/bin/lib${_name}${CMAKE_SHARED_LIBRARY_SUFFIX})
23-
else()
24-
list(APPEND HDF5_LIBRARIES ${CMAKE_INSTALL_PREFIX}/lib/lib${_name}${CMAKE_SHARED_LIBRARY_SUFFIX})
25-
endif()
26-
else()
27-
list(APPEND HDF5_LIBRARIES ${CMAKE_INSTALL_PREFIX}/lib/lib${_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
28-
endif()
29-
endforeach()
30-
31-
set(HDF5_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include)
32-
33-
# --- Zlib
34-
if(NOT TARGET ZLIB::ZLIB)
35-
include(${CMAKE_CURRENT_LIST_DIR}/zlib.cmake)
36-
endif()
14+
include(${CMAKE_CURRENT_LIST_DIR}/zlib.cmake)
3715

3816
# --- HDF5
3917
# https://forum.hdfgroup.org/t/issues-when-using-hdf5-as-a-git-submodule-and-using-cmake-with-add-subdirectory/7189/2
@@ -73,43 +51,7 @@ URL ${hdf5_url}
7351
URL_HASH SHA256=${hdf5_sha256}
7452
CMAKE_ARGS ${hdf5_cmake_args}
7553
CMAKE_GENERATOR ${EXTPROJ_GENERATOR}
76-
BUILD_BYPRODUCTS ${HDF5_LIBRARIES}
77-
DEPENDS ZLIB::ZLIB
54+
DEPENDS ZLIB
7855
CONFIGURE_HANDLED_BY_BUILD ON
7956
INACTIVITY_TIMEOUT 15
8057
)
81-
82-
# --- imported target
83-
84-
file(MAKE_DIRECTORY ${HDF5_INCLUDE_DIRS})
85-
# avoid race condition
86-
87-
# this GLOBAL is required to be visible via other project's FetchContent of h5fortran
88-
add_library(HDF5::HDF5 INTERFACE IMPORTED GLOBAL)
89-
target_include_directories(HDF5::HDF5 INTERFACE "${HDF5_INCLUDE_DIRS}")
90-
target_link_libraries(HDF5::HDF5 INTERFACE "${HDF5_LIBRARIES}")
91-
92-
add_dependencies(HDF5::HDF5 HDF5)
93-
94-
# --- HDF5 parallel compression support
95-
# this could be improved by making it an ExternalProject post-build step instead of assumptions made here
96-
if(hdf5_parallel)
97-
if(MPI_VERSION VERSION_GREATER_EQUAL 3)
98-
message(STATUS "Building HDF5-MPI: MPI-3 available, assuming HDF5 parallel compression enabled")
99-
set(hdf5_parallel_compression ".true." CACHE STRING "configure variable for HDF5 parallel compression")
100-
else()
101-
message(STATUS "Building HDF5-MPI: MPI-3 NOT available => HDF5 parallel compression disabled")
102-
set(hdf5_parallel_compression ".false." CACHE STRING "configure variable for HDF5 parallel compression: MPI < 3")
103-
endif()
104-
endif(hdf5_parallel)
105-
106-
# --- external deps
107-
find_package(Threads)
108-
109-
target_link_libraries(HDF5::HDF5 INTERFACE
110-
ZLIB::ZLIB
111-
${CMAKE_THREAD_LIBS_INIT}
112-
${CMAKE_DL_LIBS}
113-
$<$<BOOL:${UNIX}>:m>
114-
)
115-
# libdl and libm are needed on some systems

cmake/nc4fortran.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ set(nc4fortran_cmake_args
3232
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
3333
-DCMAKE_BUILD_TYPE=Release
3434
-DBUILD_TESTING:BOOL=false
35-
-Dautobuild:BOOL=false
3635
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
3736
-DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER}
3837
)

0 commit comments

Comments
 (0)