cmake: rework 3p management

* be able to also be able to disable tests of pybind11_abseil
* use shallow copy when fetching dependencies
* bump them e.g. bump pybind11 to v2.13.6
This commit is contained in:
Corentin Le Molgat
2024-01-12 16:33:18 +01:00
committed by Mizux Seiha
parent a0c54e8cc5
commit 03b5020973
3 changed files with 39 additions and 17 deletions

View File

@@ -1,14 +1,11 @@
cmake_minimum_required(VERSION 3.16)
project(pybind11_abseil LANGUAGES CXX)
include(FetchContent)
include(CTest)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif(NOT DEFINED CMAKE_CXX_STANDARD)
set(ABSL_PROPAGATE_CXX_STD ON)
set(BUILD_TESTING OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
@@ -16,17 +13,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
cmake_policy(SET CMP0135 NEW)
endif()
FetchContent_Declare(
abseil-cpp
URL https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.0.tar.gz
URL_HASH
SHA256=59d2976af9d6ecf001a81a35749a6e551a335b949d34918cfade07737b9d93c5)
FetchContent_Declare(
pybind11
URL https://github.com/pybind/pybind11/archive/refs/heads/master.tar.gz)
FetchContent_MakeAvailable(abseil-cpp pybind11)
add_subdirectory(cmake/dependencies dependencies)
set(TOP_LEVEL_DIR ${CMAKE_CURRENT_LIST_DIR})
include_directories(${TOP_LEVEL_DIR} ${pybind11_INCLUDE_DIRS})

View File

@@ -0,0 +1,33 @@
include(FetchContent)
set(BUILD_TESTING OFF)
if(NOT TARGET absl::base)
message(CHECK_START "Fetching Abseil-cpp")
list(APPEND CMAKE_MESSAGE_INDENT " ")
# ensure that abseil also installs itself, since we are using it in our public API
set(ABSL_ENABLE_INSTALL ON)
set(ABSL_USE_SYSTEM_INCLUDES ON)
set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_BUILD_TESTING OFF)
FetchContent_Declare(
absl
GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git"
GIT_TAG "20240722.0"
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(absl)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")
endif()
if(NOT TARGET pybind11::pybind11_headers)
message(CHECK_START "Fetching Pybind11")
list(APPEND CMAKE_MESSAGE_INDENT " ")
FetchContent_Declare(
pybind11
GIT_REPOSITORY "https://github.com/pybind/pybind11.git"
GIT_TAG "v2.13.6"
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(pybind11)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")
endif()

View File

@@ -176,12 +176,14 @@ add_library(status_casters INTERFACE)
add_library(pybind11_abseil::status_casters ALIAS status_casters)
target_include_directories(status_casters
INTERFACE $<BUILD_INTERFACE:${TOP_LEVEL_DIR}>)
INTERFACE $<BUILD_INTERFACE:${TOP_LEVEL_DIR}>)
target_link_libraries(status_casters INTERFACE import_status_module
status_caster statusor_caster)
status_caster statusor_caster)
add_subdirectory(tests)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
if(CMAKE_INSTALL_PYDIR)
# Copying to two target directories for simplicity. It is currently unknown