diff --git a/CMakeLists.txt b/CMakeLists.txt index a4cbb576e..7d189d24e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ set(ADA_LIB_SOVERSION "2" CACHE STRING "ada library soversion") include(GNUInstallDirs) +include(FetchContent) include(CTest) include(cmake/ada-flags.cmake) @@ -22,38 +23,39 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake) option(ADA_BENCHMARKS "Build benchmarks" OFF) option(ADA_TESTING "Build tests" ${BUILD_TESTING}) -# There are cases where when embedding ada as a dependency for other CMake -# projects as submodules or subdirectories (via FetchContent) can lead to -# errors due to CPM, so this is here to support disabling all the testing -# and tooling for ada if one only wishes to use the ada library. if(ADA_TESTING OR ADA_BENCHMARKS OR ADA_TOOLS) - include(cmake/CPM.cmake) - # CPM requires git as an implicit dependency find_package(Git QUIET) # We use googletest in the tests if(Git_FOUND AND ADA_TESTING) - CPMAddPackage( - NAME GTest - GITHUB_REPOSITORY google/googletest - VERSION 1.15.2 - OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF" + FetchContent_Declare( + GTest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.15.2 ) + set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(GTest) endif() # We use simdjson in both the benchmarks and tests if(Git_FOUND AND (ADA_TESTING OR ADA_BENCHMARKS)) - CPMAddPackage("gh:simdjson/simdjson@3.10.1") + FetchContent_Declare( + simdjson + GIT_REPOSITORY https://github.com/simdjson/simdjson.git + GIT_TAG v3.10.1 + ) + FetchContent_MakeAvailable(simdjson) endif() # We use Google Benchmark, but it does not build under several 32-bit systems. if(Git_FOUND AND ADA_BENCHMARKS AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) - CPMAddPackage( - NAME benchmark - GITHUB_REPOSITORY google/benchmark - VERSION 1.9.0 - OPTIONS "BENCHMARK_ENABLE_TESTING OFF" - "BENCHMARK_ENABLE_INSTALL OFF" - "BENCHMARK_ENABLE_WERROR OFF" - + FetchContent_Declare( + benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG v1.9.0 ) + set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) + set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) + set(BENCHMARK_ENABLE_WERROR OFF CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(benchmark) endif() if (ADA_TESTING AND NOT EMSCRIPTEN) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index a20c2b82c..909994725 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -16,7 +16,12 @@ target_include_directories(bench PUBLIC "$") # Benchdata -CPMAddPackage("gh:ada-url/url-dataset#9749b92c13e970e70409948fa862461191504ccc") +FetchContent_Declare( + url-dataset + GIT_REPOSITORY https://github.com/ada-url/url-dataset.git + GIT_TAG 9749b92c13e970e70409948fa862461191504ccc +) +FetchContent_MakeAvailable(url-dataset) add_executable(benchdata bench.cpp) target_link_libraries(benchdata PRIVATE ada) target_include_directories(benchdata PUBLIC "$") @@ -94,12 +99,14 @@ if(NOT ICU_FOUND) endif(NOT ICU_FOUND) if(ICU_FOUND) - CPMAddPackage( - NAME url_whatwg - GITHUB_REPOSITORY rmisev/url_whatwg - GIT_TAG 72bcabf - OPTIONS "URL_BUILD_TESTS OFF" "URL_USE_LIBS OFF" + FetchContent_Declare( + url_whatwg + GIT_REPOSITORY https://github.com/rmisev/url_whatwg.git + GIT_TAG 72bcabf ) + set(URL_BUILD_TESTS OFF CACHE BOOL "") + set(URL_USE_LIBS OFF CACHE BOOL "") + FetchContent_MakeAvailable(url_whatwg) add_library(url_whatwg_lib STATIC "${url_whatwg_SOURCE_DIR}/src/url.cpp" "${url_whatwg_SOURCE_DIR}/src/url_idna.cpp" "${url_whatwg_SOURCE_DIR}/src/url_ip.cpp" @@ -110,7 +117,6 @@ if(ICU_FOUND) target_include_directories(url_whatwg_lib PUBLIC "${url_whatwg_SOURCE_DIR}/include") target_link_libraries(url_whatwg_lib PRIVATE ICU::uc ICU::i18n) - target_link_libraries(bench PRIVATE url_whatwg_lib) target_link_libraries(benchdata PRIVATE url_whatwg_lib) target_link_libraries(bbc_bench PRIVATE url_whatwg_lib) @@ -255,13 +261,13 @@ endif(ZURI_FOUND) if(NOT WIN32) # We want the check whether Rust is available before trying to build a crate. -CPMAddPackage( - NAME corrosion - GITHUB_REPOSITORY corrosion-rs/corrosion - VERSION 0.4.4 - DOWNLOAD_ONLY ON - OPTIONS "Rust_FIND_QUIETLY OFF" +FetchContent_Declare( + corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG v0.4.4 ) +set(Rust_FIND_QUIETLY OFF CACHE BOOL "") +FetchContent_MakeAvailable(corrosion) include("${corrosion_SOURCE_DIR}/cmake/FindRust.cmake") endif() diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake deleted file mode 100644 index ad6b74a8b..000000000 --- a/cmake/CPM.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# 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/tools/cli/CMakeLists.txt b/tools/cli/CMakeLists.txt index 397b428e4..0a5013db7 100644 --- a/tools/cli/CMakeLists.txt +++ b/tools/cli/CMakeLists.txt @@ -8,12 +8,21 @@ if(MSVC AND BUILD_SHARED_LIBS) "$" # <--this is in-file "$") # <--this is out-file path endif() -CPMAddPackage("gh:fmtlib/fmt#11.0.2") -CPMAddPackage( - GITHUB_REPOSITORY jarro2783/cxxopts - VERSION 3.2.0 - OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES" +FetchContent_Declare( + fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 11.0.2 ) +FetchContent_MakeAvailable(fmt) +FetchContent_Declare( + cxxopts + GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git + GIT_TAG v3.2.0 +) +set(CXXOPTS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +set(CXXOPTS_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(CXXOPTS_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(cxxopts) target_link_libraries(adaparse PRIVATE cxxopts::cxxopts fmt::fmt) if(MSVC OR MINGW) @@ -21,9 +30,8 @@ if(MSVC OR MINGW) endif() install( - TARGETS - adaparse - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + TARGETS adaparse + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )