Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace submodules with CMake FetchContent #16

Merged
merged 2 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

40 changes: 25 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.18)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

project(gz-python)

Expand All @@ -10,20 +11,20 @@ if(NOT APPLE)
endif()

#============================================================================
# Find protobuf
#
# macOS: $ brew install protobuf
#
find_package(Protobuf REQUIRED)
# Options
option(BUILD_protobuf "Build protobuf Library" ON)
message(STATUS "Build protobuf: ${BUILD_protobuf}")

option(BUILD_pybind11_protobuf "Build pybind11_protobuf Library" ON)
message(STATUS "Build pybind11_protobuf: ${BUILD_pybind11_protobuf}")

#============================================================================
# Find pybind11
# Find Python
#
# macOS: $ brew install python
# macOS: $ brew install pybind11
#
find_package(Python 3.10 EXACT COMPONENTS Interpreter Development)
# find_package(pybind11 CONFIG)

#============================================================================
# Find Gazebo dependencies
Expand All @@ -44,9 +45,18 @@ find_package(gz-msgs${GZ_MSGS_VER} REQUIRED)
find_package(gz-transport${GZ_TRANSPORT_VER} REQUIRED)

#============================================================================
# subdirectories for external dependencies
# Build dependencies
add_subdirectory(cmake/dependencies dependencies)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}/dependencies/install)

include(deps)

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}")

add_subdirectory(external)
# TODO fix upstream...
set(pybind11_protobuf_INCLUDE_DIRS ${pybind11_protobuf_SOURCE_DIR})

#============================================================================
# gz_msgs_extras_lib C++ library
Expand Down Expand Up @@ -75,14 +85,14 @@ target_link_libraries(extras
PRIVATE
gz_msgs_extras_lib
gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
${Protobuf_LIBRARY}
protobuf::libprotobuf
pybind11_native_proto_caster
)

target_include_directories(extras
PRIVATE
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/external/pybind11_protobuf
${pybind11_protobuf_INCLUDE_DIRS}
)

add_dependencies(extras
Expand All @@ -107,14 +117,14 @@ target_link_libraries(transport
PRIVATE
gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
gz-transport${GZ_TRANSPORT_VER}::gz-transport${GZ_TRANSPORT_VER}
${Protobuf_LIBRARY}
protobuf::libprotobuf
pybind11_native_proto_caster
)

target_include_directories(transport
PRIVATE
${Protobuf_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/external/pybind11_protobuf
${protobuf_INCLUDE_DIRS}
${pybind11_protobuf_INCLUDE_DIRS}
)

set_target_properties(transport
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ This project depends directly on [`gz-msgs`](https://github.com/gazebosim/gz-msg

### Install `gz-python`

Clone this repo into the workspace source directory and update external submodules:
Clone this repo into the workspace source directory:

```bash
cd ~/gz_ws/src
git clone --recurse-submodules https://github.com/srmainwaring/gz-python.git
git clone https://github.com/srmainwaring/gz-python.git
```

### Build with CMake
Expand Down
42 changes: 42 additions & 0 deletions cmake/dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
include(FetchContent)

#============================================================================
# Declare all dependencies first

if(BUILD_protobuf)
set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "")
FetchContent_Declare(
protobuf
GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git"
GIT_TAG "v21.5"
GIT_SUBMODULES ""
)
endif()

if(BUILD_pybind11_protobuf)
FetchContent_Declare(
pybind11_protobuf
GIT_REPOSITORY "https://github.com/srmainwaring/pybind11_protobuf"
GIT_TAG "eea7c8e839bbcd624d8a8230773829cd49e41cba"
)
endif()

#============================================================================
# Make dependencies avaialble

if(BUILD_protobuf)
message(CHECK_START "Fetching protobuf")
list(APPEND CMAKE_MESSAGE_INDENT " ")
FetchContent_MakeAvailable(protobuf)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")
endif()

if(BUILD_pybind11_protobuf)
message(CHECK_START "Fetching pybind11_protobuf")
list(APPEND CMAKE_MESSAGE_INDENT " ")
FetchContent_MakeAvailable(pybind11_protobuf)
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "fetched")
endif()

8 changes: 8 additions & 0 deletions cmake/deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if(NOT BUILD_protobuf)
find_package(protobuf REQUIRED)
endif()

if(NOT BUILD_pybind11_protobuf)
find_package(pybind11_protobuf REQUIRED)
endif()

1 change: 0 additions & 1 deletion external/CMakeLists.txt

This file was deleted.

10 changes: 0 additions & 10 deletions external/com_google_protobuf_build.patch

This file was deleted.

1 change: 0 additions & 1 deletion external/pybind11_protobuf
Submodule pybind11_protobuf deleted from ec0d86