diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d479f8..3f70724 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ project(gz-python) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -15,50 +16,48 @@ option(BUILD_TESTS "Build tests." OFF) #============================================================================ # Find Python -# -# macOS: $ brew install python -# macOS: $ brew install pybind11 -# -find_package(Python 3.10 EXACT COMPONENTS Interpreter Development) -#============================================================================ -# Find Gazebo dependencies - -# Default versions to Gazebo Garden -set(GZ_MSGS_VER 9) -set(GZ_TRANSPORT_VER 12) - -if("$ENV{GZ_VERSION}" STREQUAL "garden") - # Garden - message(STATUS "Compiling against Gazebo Garden") -else() - # Default to Garden - message(STATUS "Compiling against Gazebo Garden") -endif() - -find_package(gz-msgs${GZ_MSGS_VER} REQUIRED) -find_package(gz-transport${GZ_TRANSPORT_VER} REQUIRED) +find_package(Python COMPONENTS Interpreter Development) #============================================================================ # Build dependencies -set(_protobuf_repository "https://github.com/protocolbuffers/protobuf.git") -set(_protobuf_version 21.5) -set(_protobuf_tag v21.5) +set(_absl_repository "https://github.com/abseil/abseil-cpp.git") +set(_absl_version 20230802) +set(_absl_tag 20230802.1) +find_package(absl ${_absl_version} QUIET) -set(_pybind11_protobuf_repository "https://github.com/pybind/pybind11_protobuf.git") +set(_protobuf_repository "https://github.com/protocolbuffers/protobuf.git") +set(_protobuf_version 3.25.0) +set(_protobuf_tag v25.0) +# do not use system protobuf as it will not include proto_api.h +# see also: https://github.com/pybind/pybind11_protobuf/issues/127 +# find_package(Protobuf ${_protobuf_version} QUIET) + +set(_pybind11_repository "https://github.com/pybind/pybind11.git") +set(_pybind11_version 2.11.1) +set(_pybind11_tag v2.11.1) +find_package(pybind11 ${_pybind11_version} QUIET) + +set(_pybind11_protobuf_repository "https://github.com/srmainwaring/pybind11_protobuf.git") set(_pybind11_protobuf_version 0.0.0) -set(_pybind11_protobuf_tag main) +set(_pybind11_protobuf_tag prs/pr-proto-api-fix) +find_package(pybind11_protobuf ${_pybind11_version} QUIET) add_subdirectory(cmake/dependencies dependencies) list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}/dependencies/install) message("pybind11_protobuf_FOUND: ${pybind11_protobuf_FOUND}") message("pybind11_protobuf_SOURCE_DIR: ${pybind11_protobuf_SOURCE_DIR}") -message("pybind11_protobuf_INCLUDE_DIRS: ${pybind11_protobuf_INCLUDE_DIRS}") +message("pybind11_protobuf_SOURCE_DIR: ${pybind11_protobuf_SOURCE_DIR}") +message("protobuf_SOURCE_DIR: ${protobuf_SOURCE_DIR}") # TODO fix upstream... -set(pybind11_protobuf_INCLUDE_DIRS ${pybind11_protobuf_SOURCE_DIR}) +set(pybind11_protobuf_INCLUDE_DIRS + ${pybind11_protobuf_SOURCE_DIR} + ${protobuf_SOURCE_DIR} +) + #============================================================================ # gz_msgs_extras_lib C++ library diff --git a/cmake/dependencies/CMakeLists.txt b/cmake/dependencies/CMakeLists.txt index 9b7ae72..4dc954a 100644 --- a/cmake/dependencies/CMakeLists.txt +++ b/cmake/dependencies/CMakeLists.txt @@ -3,9 +3,19 @@ include(FetchContent) #============================================================================ # Declare all dependencies first -find_package(Protobuf ${_protobuf_version} EXACT QUIET) +if(NOT absl_FOUND) + set(ABSL_PROPAGATE_CXX_STD ON) + set(ABSL_ENABLE_INSTALL ON) + FetchContent_Declare( + absl + GIT_REPOSITORY ${_absl_repository} + GIT_TAG ${_absl_tag}) +endif() + if(NOT Protobuf_FOUND) - set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "") + set(protobuf_BUILD_TESTS + OFF + CACHE INTERNAL "") FetchContent_Declare( Protobuf GIT_REPOSITORY ${_protobuf_repository} @@ -14,7 +24,14 @@ if(NOT Protobuf_FOUND) ) endif() -find_package(pybind11_protobuf ${_pybind11_protobuf_version} EXACT QUIET) +if(NOT pybind11_FOUND) + set(PYBIND11_TEST OFF) + FetchContent_Declare( + pybind11 + GIT_REPOSITORY ${_pybind11_repository} + GIT_TAG ${_pybind11_tag}) +endif() + if(NOT pybind11_protobuf_FOUND) FetchContent_Declare( pybind11_protobuf @@ -26,6 +43,14 @@ endif() #============================================================================ # Make dependencies avaialble +if(NOT absl_FOUND) + message(CHECK_START "Fetching Abseil-cpp") + list(APPEND CMAKE_MESSAGE_INDENT " ") + FetchContent_MakeAvailable(absl) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() + if(NOT Protobuf_FOUND) message(CHECK_START "Fetching Protobuf") list(APPEND CMAKE_MESSAGE_INDENT " ") @@ -34,6 +59,14 @@ if(NOT Protobuf_FOUND) message(CHECK_PASS "fetched") endif() +if(NOT pybind11_FOUND) + message(CHECK_START "Fetching pybind11") + list(APPEND CMAKE_MESSAGE_INDENT " ") + FetchContent_MakeAvailable(pybind11) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() + if(NOT pybind11_protobuf_FOUND) message(CHECK_START "Fetching pybind11_protobuf") list(APPEND CMAKE_MESSAGE_INDENT " ")