Skip to content

Commit

Permalink
download: use archive to save time
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jan 28, 2024
1 parent 990748d commit 8634807
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.19...3.28)
cmake_minimum_required(VERSION 3.19...3.29)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed. Do like:
Expand Down
12 changes: 4 additions & 8 deletions cmake/libraries.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{
"netcdfC": {
"url": "https://github.com/Unidata/netcdf-c.git",
"tag": "v4.9.2"
"url": "https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz"
},
"netcdfFortran": {
"url": "https://github.com/Unidata/netcdf-fortran.git",
"tag": "v4.6.1"
"url": "https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz"
},
"zlib": {
"url" : "https://github.com/zlib-ng/zlib-ng.git",
"tag": "2.1.5"
"url" : "https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.1.6.tar.gz"
},
"hdf5": {
"url": "https://github.com/HDFGroup/hdf5.git",
"tag": "hdf5-1_10_9"
"url": "https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5-1_14_3.tar.gz"
}
}
7 changes: 3 additions & 4 deletions cmake/netcdf-c.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(netcdf_c_cmake_args
-DENABLE_BYTERANGE:BOOL=OFF
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
-DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARIES}
)
# BUILD_SHARED_LIBS=on for netcdf-fortran symbol finding bug

Expand All @@ -32,12 +33,10 @@ endif()
set(NetCDF_C_INCLUDE_DIRS ${CMAKE_INSTALL_FULL_INCLUDEDIR})

string(JSON netcdfC_url GET ${json} netcdfC url)
string(JSON netcdfC_tag GET ${json} netcdfC tag)


ExternalProject_Add(NETCDF_C
GIT_REPOSITORY ${netcdfC_url}
GIT_TAG ${netcdfC_tag}
GIT_SHALLOW true
URL ${netcdfC_url}
CONFIGURE_HANDLED_BY_BUILD TRUE
CMAKE_ARGS ${netcdf_c_cmake_args}
BUILD_BYPRODUCTS ${NetCDF_C_LIBRARIES}
Expand Down
5 changes: 1 addition & 4 deletions cmake/netcdf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ endif()
set(NetCDF_Fortran_INCLUDE_DIRS ${CMAKE_INSTALL_FULL_INCLUDEDIR})

string(JSON netcdfFortran_url GET ${json} netcdfFortran url)
string(JSON netcdfFortran_tag GET ${json} netcdfFortran tag)

ExternalProject_Add(NETCDF_FORTRAN
GIT_REPOSITORY ${netcdfFortran_url}
GIT_TAG ${netcdfFortran_tag}
GIT_SHALLOW true
URL ${netcdfFortran_url}
CONFIGURE_HANDLED_BY_BUILD ON
CMAKE_ARGS ${netcdf_fortran_cmake_args}
CMAKE_CACHE_ARGS -DCMAKE_REQUIRED_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}
Expand Down
29 changes: 6 additions & 23 deletions cmake/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
include(GNUInstallDirs)
include(ExternalProject)

if(zlib_legacy)
string(JSON zlib_url GET ${json} zlib1 url)
string(JSON zlib_sha256 GET ${json} zlib1 sha256)
else()
string(JSON zlib_url GET ${json} zlib2 url)
string(JSON zlib_tag GET ${json} zlib2 tag)
endif()

set(ZLIB_INCLUDE_DIRS ${CMAKE_INSTALL_FULL_INCLUDEDIR})

if(BUILD_SHARED_LIBS)
Expand All @@ -20,40 +12,30 @@ if(BUILD_SHARED_LIBS)
set(ZLIB_LIBRARIES ${CMAKE_INSTALL_FULL_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}z${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
else()
if(MSVC OR (WIN32 AND zlib_legacy))
if(MSVC)
set(ZLIB_LIBRARIES ${CMAKE_INSTALL_FULL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}zlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(ZLIB_LIBRARIES ${CMAKE_INSTALL_FULL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}z${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
endif()


string(JSON zlib_url GET ${json} zlib url)

set(zlib_cmake_args
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DCMAKE_BUILD_TYPE=Release
-DZLIB_COMPAT:BOOL=on
-DZLIB_ENABLE_TESTS:BOOL=off
-DZLIBNG_ENABLE_TESTS:BOOL=off
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
)
# NetCDF 4.9/4.6 needs fPIC

if(zlib_legacy)
set(zlib_download
URL ${zlib_url}
URL_HASH SHA256=${zlib_sha256}
)
else()
set(zlib_download
GIT_REPOSITORY ${zlib_url}
GIT_TAG ${zlib_tag}
GIT_SHALLOW true
)
endif()

ExternalProject_Add(ZLIB
${zlib_download}
URL ${zlib_url}
CMAKE_ARGS ${zlib_cmake_args}
BUILD_BYPRODUCTS ${ZLIB_LIBRARIES}
CONFIGURE_HANDLED_BY_BUILD ON
Expand All @@ -71,6 +53,7 @@ USES_TERMINAL_TEST true
file(MAKE_DIRECTORY ${ZLIB_INCLUDE_DIRS})
# avoid race condition

# for visibility in parent projects
add_library(ZLIB::ZLIB INTERFACE IMPORTED GLOBAL)
add_dependencies(ZLIB::ZLIB ZLIB) # to avoid include directory race condition
target_link_libraries(ZLIB::ZLIB INTERFACE ${ZLIB_LIBRARIES})
Expand Down

0 comments on commit 8634807

Please sign in to comment.