Skip to content

Commit

Permalink
[INFRA] Add fallback for cmake<3.30
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Nov 5, 2024
1 parent e0c6339 commit a21a75a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
11 changes: 4 additions & 7 deletions cmake/test/add_local_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ file (GLOB_RECURSE datasources
RELATIVE ${DATASOURCES_DATA_DIR}
CONFIGURE_DEPENDS ${DATASOURCES_DATA_DIR}/*
)
list (REMOVE_ITEM datasources datasources.cmake README.md)
list (FILTER datasources EXCLUDE REGEX "\.license")
list (REMOVE_ITEM datasources datasources.cmake README.md REUSE.toml)

foreach (datasource IN LISTS datasources)
get_filename_component (datasource_name "${datasource}" NAME)
file (SHA256 ${DATASOURCES_DATA_DIR}/${datasource} datasource_hash)
set (data_dir "${CMAKE_CURRENT_BINARY_DIR}/data")
file (MAKE_DIRECTORY "${data_dir}")

declare_datasource (FILE ${datasource_name}
URL ${DATASOURCES_DATA_DIR}/${datasource}
URL_HASH SHA256=${datasource_hash}
)
configure_file ("${DATASOURCES_DATA_DIR}/${datasource}" "${data_dir}/${datasource_name}" COPYONLY)
endforeach ()
42 changes: 32 additions & 10 deletions cmake/test/declare_datasource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

include (FetchContent)
if (CMAKE_VERSION VERSION_LESS 3.30)
include (ExternalProject)
else ()
include (FetchContent)
endif ()

# Example call:
#
Expand Down Expand Up @@ -38,6 +42,7 @@ include (FetchContent)
# This uses under the hood ExternalProject's and you can pass any viable option of ExternalProject to this function and
# overwrite the default behaviour. See https://cmake.org/cmake/help/latest/module/ExternalProject.html for more
# information.

function (declare_datasource)
set (options "")
set (one_value_args FILE URL_HASH)
Expand All @@ -50,15 +55,32 @@ function (declare_datasource)
# create data folder
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data)

FetchContent_Populate ("${datasource_name}"
URL "${ARG_URL}"
URL_HASH "${ARG_URL_HASH}"
DOWNLOAD_NAME "${ARG_FILE}"
DOWNLOAD_NO_EXTRACT TRUE # don't extract archive files like .tar.gz.
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/data/"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/data/"
EXCLUDE_FROM_ALL TRUE ${ARG_UNPARSED_ARGUMENTS}
)
if (CMAKE_VERSION VERSION_LESS 3.30)
ExternalProject_Add ("${datasource_name}"
URL "${ARG_URL}"
URL_HASH "${ARG_URL_HASH}"
DOWNLOAD_NAME "${ARG_FILE}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E create_symlink <DOWNLOADED_FILE>
${CMAKE_CURRENT_BINARY_DIR}/data/${ARG_FILE}
TEST_COMMAND ""
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/_datasources"
DOWNLOAD_NO_EXTRACT TRUE # don't extract archive files like .tar.gz.
EXCLUDE_FROM_ALL TRUE
${ARG_UNPARSED_ARGUMENTS}
)
else ()
FetchContent_Populate ("${datasource_name}"
URL "${ARG_URL}"
URL_HASH "${ARG_URL_HASH}"
DOWNLOAD_NAME "${ARG_FILE}"
DOWNLOAD_NO_EXTRACT TRUE # don't extract archive files like .tar.gz.
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/data/"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/data/"
EXCLUDE_FROM_ALL TRUE ${ARG_UNPARSED_ARGUMENTS}
)
endif ()

add_dependencies (${PROJECT_NAME}_test "${datasource_name}")
endfunction ()

0 comments on commit a21a75a

Please sign in to comment.