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 d4fc448
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmake/test/add_local_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ file (GLOB_RECURSE datasources
RELATIVE ${DATASOURCES_DATA_DIR}
CONFIGURE_DEPENDS ${DATASOURCES_DATA_DIR}/*
)
list (REMOVE_ITEM datasources datasources.cmake README.md)
list (REMOVE_ITEM datasources datasources.cmake README.md REUSE.toml)
list (FILTER datasources EXCLUDE REGEX "\.license")

foreach (datasource IN LISTS datasources)
Expand Down
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 d4fc448

Please sign in to comment.