From e6e6c6f2f3be40ae4b4708c8c5eeca9d7b1e003c Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Thu, 5 Oct 2023 22:17:02 +0200 Subject: [PATCH 1/7] Avoid to use CMAKE_SOURCE_DIR Signed-off-by: Silvio Traversaro --- python/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index eb348471..e0e935fc 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -68,10 +68,10 @@ if (BUILD_TESTING AND NOT WIN32) foreach (test ${python_tests}) if (pytest_FOUND) add_test(NAME ${test}.py COMMAND - "${Python3_EXECUTABLE}" -m pytest "${CMAKE_SOURCE_DIR}/python/test/${test}.py" --junitxml "${CMAKE_BINARY_DIR}/test_results/${test}.xml") + "${Python3_EXECUTABLE}" -m pytest "${CMAKE_CURRENT_SOURCE_DIR}/test/${test}.py" --junitxml "${CMAKE_BINARY_DIR}/test_results/${test}.xml") else() add_test(NAME ${test}.py COMMAND - "${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/python/test/${test}.py") + "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test/${test}.py") endif() set(_env_vars) list(APPEND _env_vars "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}/bin") From 87c80e7c9b4c928586b7094149025358fc7d661d Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 29 Sep 2024 01:15:35 +0200 Subject: [PATCH 2/7] Support compilation of bindings as standalone project Signed-off-by: Silvio Traversaro --- python/CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index e0e935fc..eb1a4ba5 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,3 +1,18 @@ +# Detect if we are doing a standalone build of the bindings, using an external gz-transport +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + cmake_minimum_required(VERSION 3.16) + set(GZ_TRANSPORT_VER 14) + project(gz-transport${GZ_TRANSPORT_VER}-python VERSION ${GZ_TRANSPORT_VER}) + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + find_package(pybind11 REQUIRED) + find_package(gz-transport${PROJECT_VERSION_MAJOR} REQUIRED) + set(PROJECT_LIBRARY_TARGET_NAME "gz-transport${PROJECT_VERSION_MAJOR}::gz-transport${PROJECT_VERSION_MAJOR}") + include(CTest) + if(BUILD_TESTING) + enable_testing() + endif() +endif() + if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION) if(NOT Python3_SITEARCH) # Get install variable from Python3 module From f11c332af18511cc3562ced86aea17c8a6fa0c7e Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 5 Nov 2024 08:59:52 -0800 Subject: [PATCH 3/7] Fix python install path Use CMAKE_INSTALL_LIBDIR from GNUInstallDirs instead of GZ_LIB_INSTALL_DIR, which won't be available if only building python bindings. Signed-off-by: Steve Peters --- python/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index eb1a4ba5..59756769 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -7,6 +7,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) find_package(pybind11 REQUIRED) find_package(gz-transport${PROJECT_VERSION_MAJOR} REQUIRED) set(PROJECT_LIBRARY_TARGET_NAME "gz-transport${PROJECT_VERSION_MAJOR}::gz-transport${PROJECT_VERSION_MAJOR}") + include(GNUInstallDirs) include(CTest) if(BUILD_TESTING) enable_testing() @@ -27,7 +28,7 @@ if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION) endif() else() # If not a system installation, respect local paths - set(GZ_PYTHON_INSTALL_PATH ${GZ_LIB_INSTALL_DIR}/python) + set(GZ_PYTHON_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/python) endif() set(GZ_PYTHON_INSTALL_PATH "${GZ_PYTHON_INSTALL_PATH}/gz") From 4083472090fce3cdbff1b41375588a5138d0b6aa Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 5 Nov 2024 09:01:33 -0800 Subject: [PATCH 4/7] Use consistent cmake required version Also remove unneeded enable_testing() call. Signed-off-by: Steve Peters --- python/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 59756769..4285abef 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,6 +1,6 @@ # Detect if we are doing a standalone build of the bindings, using an external gz-transport if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - cmake_minimum_required(VERSION 3.16) + cmake_minimum_required(VERSION 3.22.1) set(GZ_TRANSPORT_VER 14) project(gz-transport${GZ_TRANSPORT_VER}-python VERSION ${GZ_TRANSPORT_VER}) find_package(Python3 COMPONENTS Interpreter Development REQUIRED) @@ -9,9 +9,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(PROJECT_LIBRARY_TARGET_NAME "gz-transport${PROJECT_VERSION_MAJOR}::gz-transport${PROJECT_VERSION_MAJOR}") include(GNUInstallDirs) include(CTest) - if(BUILD_TESTING) - enable_testing() - endif() endif() if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION) From b9f4d048dd25b25afa2d29b8076efc00b152755b Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 5 Nov 2024 09:02:20 -0800 Subject: [PATCH 5/7] Find pybind11 in python/CMakeLists.txt Signed-off-by: Steve Peters --- CMakeLists.txt | 16 ++++------------ python/CMakeLists.txt | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c69aa0e..6c814bd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,19 +58,11 @@ if (SKIP_PYBIND11) message(STATUS "SKIP_PYBIND11 set - disabling python bindings") find_package(Python3 COMPONENTS Interpreter) else() - find_package(Python3 COMPONENTS Interpreter Development) + find_package(Python3 + COMPONENTS Interpreter + OPTIONAL_COMPONENTS Development) if (NOT Python3_Development_FOUND) GZ_BUILD_WARNING("Python development libraries are missing: Python interfaces are disabled.") - else() - set(PYBIND11_PYTHON_VERSION 3) - find_package(pybind11 2.4 CONFIG QUIET) - - if (pybind11_FOUND) - message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.") - else() - GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.") - message (STATUS "Searching for pybind11 - not found.") - endif() endif() endif() @@ -164,7 +156,7 @@ add_subdirectory(conf) #============================================================================ # gz transport python bindings #============================================================================ -if (pybind11_FOUND AND NOT SKIP_PYBIND11) +if (Python3_Development_FOUND AND NOT SKIP_PYBIND11) add_subdirectory(python) endif() diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 4285abef..aafad62e 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -3,14 +3,25 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) cmake_minimum_required(VERSION 3.22.1) set(GZ_TRANSPORT_VER 14) project(gz-transport${GZ_TRANSPORT_VER}-python VERSION ${GZ_TRANSPORT_VER}) - find_package(Python3 COMPONENTS Interpreter Development REQUIRED) - find_package(pybind11 REQUIRED) find_package(gz-transport${PROJECT_VERSION_MAJOR} REQUIRED) set(PROJECT_LIBRARY_TARGET_NAME "gz-transport${PROJECT_VERSION_MAJOR}::gz-transport${PROJECT_VERSION_MAJOR}") + # require python dependencies to be found + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + set(CMAKE_REQUIRE_FIND_PACKAGE_pybind11 TRUE) include(GNUInstallDirs) include(CTest) endif() +set(PYBIND11_PYTHON_VERSION 3) +find_package(pybind11 2.4 CONFIG QUIET) + +if (pybind11_FOUND) + message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.") +else() + message(WARNING "pybind11 is missing: Python interfaces are disabled.") + return() +endif() + if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION) if(NOT Python3_SITEARCH) # Get install variable from Python3 module From 592a694d1ea9569cda6cc15a70b9fefe15a9368b Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 7 Nov 2024 17:46:52 -0800 Subject: [PATCH 6/7] Consolidate build from source instructions Combine similar steps for Ubuntu and macOS Signed-off-by: Steve Peters --- tutorials/02_installation.md | 72 +++++++++++++++++------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/tutorials/02_installation.md b/tutorials/02_installation.md index 89207356..3dfaa0ff 100644 --- a/tutorials/02_installation.md +++ b/tutorials/02_installation.md @@ -45,13 +45,10 @@ library and rebuilding dependencies due to the use of c++11. For purposes of this documentation, assuming OS X 10.9 or greater is in use. Here are the instructions: -Install homebrew, which should also prompt you to install the XCode -command-line tools: -``` -/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -``` +After installing the [Homebrew package manager](https://brew.sh), +which should also prompt you to install the XCode command-line tools +add OSRF packages and run the install command: -Run the following commands: ``` brew tap osrf/simulation brew install gz-transport<#> @@ -81,7 +78,9 @@ which version you need. # Source Install -## Ubuntu Linux +## Install Prerequisites + +### Ubuntu Linux For compiling the latest version of Gazebo Transport you will need an Ubuntu distribution equal to 24.04 (Noble) or newer. @@ -97,10 +96,29 @@ Install prerequisites. A clean Ubuntu system will need: sudo apt-get install git cmake pkg-config python ruby-ronn libprotoc-dev libprotobuf-dev protobuf-compiler uuid-dev libzmq3-dev libgz-msgs11-dev libgz-utils3-cli-dev ``` +### macOS + +After installing the [Homebrew package manager](https://brew.sh), +which should also prompt you to install the XCode command-line tools +add OSRF packages and run the command to install dependencies: + +``` +brew tap osrf/simulation +brew install --only-dependencies gz-transport<#> +``` + +Be sure to replace `<#>` with a number value, such as 10 or 11, depending on +which version you need. + +## Clone, Configure, and Build + Clone the repository ``` -git clone https://github.com/gazebosim/gz-transport +git clone https://github.com/gazebosim/gz-transport -b gz-transport<#> ``` +Be sure to replace `<#>` with a number value, such as 10 or 11, depending on +which version you need. From version 12 use `gz-transport<#>` for lower versions +use `ign-transport<#>` Configure and build ``` @@ -111,6 +129,13 @@ cmake .. make ``` +Optionally, install +``` +sudo make install +``` + +### Configuration options + Configure Gazebo Transport (choose either method a or b below): A. Release mode (recommended): This will generate optimized code, but will not have @@ -170,37 +195,6 @@ cd /tmp/gz-transport/build sudo make uninstall ``` -### macOS - -1. Clone the repository - ``` - git clone https://github.com/gazebosim/gz-transport -b gz-transport<#> - ``` - Be sure to replace `<#>` with a number value, such as 10 or 11, depending on - which version you need. From version 12 use `gz-transport<#>` for lower versions - use `ign-transport<#>` - -2. Install dependencies - ``` - brew install --only-dependencies gz-transport<#> - ``` - Be sure to replace `<#>` with a number value, such as 10 or 11, depending on - which version you need. - -3. Configure and build - ``` - cd gz-transport - mkdir build - cd build - cmake .. - make - ``` - -4. Optionally, install - ``` - sudo make install - ``` - ## Windows ### Prerequisites From 1c30b3d5f1ae30f3a1de601bb53ebb87d1a352d8 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 7 Nov 2024 17:47:38 -0800 Subject: [PATCH 7/7] Document building python bindings separately Signed-off-by: Steve Peters --- tutorials/02_installation.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tutorials/02_installation.md b/tutorials/02_installation.md index 3dfaa0ff..9cf90e16 100644 --- a/tutorials/02_installation.md +++ b/tutorials/02_installation.md @@ -184,6 +184,28 @@ modify your `LD_LIBRARY_PATH`: echo "export LD_LIBRARY_PATH=/local/lib:$LD_LIBRARY_PATH" >> ~/.bashrc ``` +### Build python bindings separately from main library + +If you want to build Python bindings separately from the main gz-transport library +(for example if you want to build Python bindings for multiple versions of Python), +you can invoke cmake on the `python` folder instead of the root folder. +Specify the path to the python executable with which you wish to build bindings +in the `Python3_EXECUTABLE` cmake variable. +Specify the install path for the bindings in the `CMAKE_INSTALL_PREFIX` +variable, and be sure to set your `PYTHONPATH` accordingly after install. + +```bash +cd sdformat +mkdir build_python3 +cd build_python3 +cmake ../python \ + -DPython3_EXECUTABLE=/usr/local/bin/python3.12 \ + -DCMAKE_INSTALL_PREFIX= +``` + +See the homebrew [sdformat15 formula](https://github.com/osrf/homebrew-simulation/blob/027d06f5be49da1e40d01180aedae7f76dc7ff47/Formula/sdformat15.rb#L12-L56) +for an example of building bindings for multiple versions of Python. + ### Uninstalling Source-based Install If you need to uninstall Gazebo Transport or switch back to a