diff --git a/CMakeLists.txt b/CMakeLists.txt index 825d4af3..b22f4e39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,49 +7,29 @@ project(python++) set(CMAKE_CXX_STANDARD 20) -FetchContent_Declare( - spdlog - GIT_REPOSITORY https://github.com/gabime/spdlog.git - GIT_TAG v1.8.5 - SYSTEM) -FetchContent_MakeAvailable(spdlog) - -FetchContent_Declare( - gtest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.17.0 - SYSTEM) -FetchContent_MakeAvailable(gtest) - -FetchContent_Declare( - cxxopts - GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git - GIT_TAG v3.0.0 - SYSTEM) -FetchContent_MakeAvailable(cxxopts) - -FetchContent_Declare( - cpython - GIT_REPOSITORY https://github.com/python/cpython.git - GIT_TAG v3.9.13) -FetchContent_MakeAvailable(cpython) - -FetchContent_Declare( - tsl - GIT_REPOSITORY https://github.com/Tessil/ordered-map - GIT_TAG v1.2.0) -FetchContent_MakeAvailable(tsl) +include(cmake/CPM.cmake) + +CPMAddPackage("gh:gabime/spdlog@1.8.5") +CPMAddPackage("gh:google/googletest@1.17.0") +CPMAddPackage("gh:jarro2783/cxxopts@3.0.0") +CPMAddPackage("gh:Tessil/ordered-map@1.2.0") +CPMAddPackage("gh:python/cpython@3.9.25") +CPMAddPackage("gh:antirez/linenoise#1.0") +CPMAddPackage("gh:aminya/project_options@0.41.0") + +if(linenoise_ADDED) + add_library(linenoise ${linenoise_SOURCE_DIR}/linenoise.c) + target_include_directories(linenoise SYSTEM PUBLIC ${linenoise_SOURCE_DIR}) +endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -find_package(GMP REQUIRED) +find_package(GMP REQUIRED) find_package(ICU REQUIRED COMPONENTS uc data) add_library(GTest::GTest ALIAS gtest) add_library(GTest::GMock ALIAS gmock) add_library(GTest::Main ALIAS gtest_main) -include(cmake/linenoise.cmake) -include(cmake/project_options.cmake) option(ENABLE_CACHE "Enable build cache" ON) option(ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" OFF) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 00000000..84748734 --- /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.42.0) +set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a") + +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/linenoise.cmake b/cmake/linenoise.cmake deleted file mode 100644 index 57a59301..00000000 --- a/cmake/linenoise.cmake +++ /dev/null @@ -1,17 +0,0 @@ -include(FetchContent) - - -FetchContent_Declare(linenoise_src - GIT_REPOSITORY https://github.com/antirez/linenoise.git - GIT_TAG master -) - -FetchContent_MakeAvailable(linenoise_src) - -FetchContent_GetProperties(linenoise_src) -if(NOT linenoise_src_POPULATED) - FetchContent_Populate(linenoise_src) -endif() - -add_library(linenoise ${linenoise_src_SOURCE_DIR}/linenoise.c) -target_include_directories(linenoise PUBLIC ${linenoise_src_SOURCE_DIR}) diff --git a/cmake/project_options.cmake b/cmake/project_options.cmake deleted file mode 100644 index 69080595..00000000 --- a/cmake/project_options.cmake +++ /dev/null @@ -1,10 +0,0 @@ -# Add project_options v0.25.2 -# https://github.com/aminya/project_options -# Change the version in the following URL to update the package (watch the releases of the repository for future updates) -include(FetchContent) -FetchContent_Declare(_project_options - DOWNLOAD_EXTRACT_TIMESTAMP TRUE - URL https://github.com/aminya/project_options/archive/refs/tags/v0.25.2.zip -) -FetchContent_MakeAvailable(_project_options) -include(${_project_options_SOURCE_DIR}/Index.cmake) \ No newline at end of file