From c47190f2f1bb7e23ae7da76ca659235862a74d70 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Sat, 28 Oct 2023 16:47:22 -0400 Subject: [PATCH] Switching to CPM --- CMakeLists.txt | 2 +- cmake/CPM.cmake | 24 ++++++++++++++++ cmake/import.cmake | 52 ---------------------------------- microbenchmarks/CMakeLists.txt | 11 +++++-- tools/cmake/FindCTargets.cmake | 7 +++-- 5 files changed, 39 insertions(+), 57 deletions(-) create mode 100644 cmake/CPM.cmake delete mode 100644 cmake/import.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index bde4727cd..9bdd478bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake") find_package(CTargets) find_package(Options) find_package(LTO) -include(Import) +include(cmake/CPM.cmake) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/roaring.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/roaring.pc" @ONLY) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 000000000..ad6b74a8b --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.38.6) +set(CPM_HASH_SUM "11c3fa5f1ba14f15d31c2fb63dbc8628ee133d81c8d764caad9a8db9e0bacb07") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/cmake/import.cmake b/cmake/import.cmake deleted file mode 100644 index a9b6ffe5d..000000000 --- a/cmake/import.cmake +++ /dev/null @@ -1,52 +0,0 @@ -set(dep_root "${PROJEC_SOURCE_DIR}/dependencies/.cache") -if(DEFINED ENV{roaring_DEPENDENCY_CACHE_DIR}) - set(dep_root "$ENV{roaring_DEPENDENCY_CACHE_DIR}") -endif() - -function(import_dependency NAME GITHUB_REPO COMMIT) - message(STATUS "Importing ${NAME} (${GITHUB_REPO}@${COMMIT})") - set(target "${dep_root}/${NAME}") - - # If the folder exists in the cache, then we assume that everything is as - # should be and do nothing - if(EXISTS "${target}") - set("${NAME}_SOURCE_DIR" "${target}" PARENT_SCOPE) - return() - endif() - - set(zip_url "https://github.com/${GITHUB_REPO}/archive/${COMMIT}.zip") - set(archive "${dep_root}/archive.zip") - set(dest "${dep_root}/_extract") - - file(DOWNLOAD "${zip_url}" "${archive}") - file(MAKE_DIRECTORY "${dest}") - execute_process( - WORKING_DIRECTORY "${dest}" - COMMAND "${CMAKE_COMMAND}" -E tar xf "${archive}") - file(REMOVE "${archive}") - - # GitHub archives only ever have one folder component at the root, so this - # will always match that single folder - file(GLOB dir LIST_DIRECTORIES YES "${dest}/*") - - file(RENAME "${dir}" "${target}") - - set("${NAME}_SOURCE_DIR" "${target}" PARENT_SCOPE) -endfunction() - -# Delegates to the dependency -macro(add_dependency NAME) - if(NOT DEFINED "${NAME}_SOURCE_DIR") - message(FATAL_ERROR "Missing ${NAME}_SOURCE_DIR variable") - endif() - - add_subdirectory("${${NAME}_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/_deps/${NAME}" EXCLUDE_FROM_ALL) -endmacro() - -function(set_off NAME) - set("${NAME}" OFF CACHE INTERNAL "") -endfunction() - -function(set_on NAME) - set("${NAME}" ON CACHE INTERNAL "") -endfunction() \ No newline at end of file diff --git a/microbenchmarks/CMakeLists.txt b/microbenchmarks/CMakeLists.txt index 628515bbc..4a7288e70 100644 --- a/microbenchmarks/CMakeLists.txt +++ b/microbenchmarks/CMakeLists.txt @@ -7,8 +7,15 @@ set_off(BENCHMARK_ENABLE_TESTING) set_off(BENCHMARK_ENABLE_INSTALL) set_off(BENCHMARK_ENABLE_WERROR) set(BENCHMARK_ENABLE_WERROR OFF) -import_dependency(google_benchmarks google/benchmark 3441176) -add_dependency(google_benchmarks) + CPMAddPackage( + NAME benchmark + GITHUB_REPOSITORY google/benchmark + GIT_TAG 3441176 + OPTIONS "BENCHMARK_ENABLE_TESTING OFF" + "BENCHMARK_ENABLE_INSTALL OFF" + "BENCHMARK_ENABLE_WERROR OFF" + + ) add_executable(bench bench.cpp) target_link_libraries(bench PRIVATE roaring) diff --git a/tools/cmake/FindCTargets.cmake b/tools/cmake/FindCTargets.cmake index c659bdf55..8eb227e6c 100644 --- a/tools/cmake/FindCTargets.cmake +++ b/tools/cmake/FindCTargets.cmake @@ -4,8 +4,11 @@ endif () include(${PROJECT_SOURCE_DIR}/tools/cmake/Import.cmake) set(BUILD_STATIC_LIB ON) if (ENABLE_ROARING_TESTS) - import_dependency(cmocka clibs/cmocka f5e2cd7) - add_dependency(cmocka) + CPMAddPackage( + NAME cmocka + GITHUB_REPOSITORY clibs/cmocka + GIT_TAG f5e2cd7 + ) endif() function(add_c_test TEST_NAME)