Skip to content

Commit

Permalink
Replace submodules with CMake FetchContent (#16)
Browse files Browse the repository at this point in the history
- Remove .gitmodules and external folder.
- Replace submodules with CMake FetchContent
- Update dependencies.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
  • Loading branch information
srmainwaring committed Jan 14, 2023
1 parent c9f6610 commit c38289b
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 32 deletions.
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

0 comments on commit c38289b

Please sign in to comment.