Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INFRA] Add fallback for cmake < 3.30 #163

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ()
Loading