diff --git a/cmake/test/add_local_data.cmake b/cmake/test/add_local_data.cmake index d8cf413..e487f3a 100644 --- a/cmake/test/add_local_data.cmake +++ b/cmake/test/add_local_data.cmake @@ -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 () diff --git a/cmake/test/declare_datasource.cmake b/cmake/test/declare_datasource.cmake index a7a236d..fa3a892 100644 --- a/cmake/test/declare_datasource.cmake +++ b/cmake/test/declare_datasource.cmake @@ -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: # @@ -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) @@ -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 + ${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 ()