From e25bcb5238eb6f10addf84f8bd03c37386854896 Mon Sep 17 00:00:00 2001 From: aalbaali Date: Sat, 27 Apr 2024 15:16:13 -0400 Subject: [PATCH 1/5] Export cmake targets without installing Signed-off-by: aalbaali --- CMakeLists.txt | 22 +++++++++++++++------- TransformsGraphConfig.cmake.in | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9800845..3164ae7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,10 +33,11 @@ endif() # Export package for use from the build tree set(TRANSFORMS_GRAPH_CMAKE_EXPORT_DIR lib/cmake/TransformsGraph) -install(TARGETS TransformsGraph - EXPORT TransformsGraphTargets - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib +install( + TARGETS TransformsGraph + EXPORT TransformsGraphTargets + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib ) install(EXPORT TransformsGraphTargets NAMESPACE TransformsGraph:: @@ -44,9 +45,10 @@ install(EXPORT TransformsGraphTargets ) # Install the include directory -install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ - DESTINATION include) - +install( + DIRECTORY ${PROJECT_SOURCE_DIR}/include/ + DESTINATION include +) include(CMakePackageConfigHelpers) configure_package_config_file( "TransformsGraphConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphConfig.cmake" @@ -54,3 +56,9 @@ configure_package_config_file( ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphConfig.cmake" DESTINATION "lib/cmake/TransformsGraph") +# Export without installing +export( + EXPORT TransformsGraphTargets + FILE "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphTargets.cmake" + NAMESPACE TransformsGraph:: +) diff --git a/TransformsGraphConfig.cmake.in b/TransformsGraphConfig.cmake.in index 07f89f3..a5288b1 100644 --- a/TransformsGraphConfig.cmake.in +++ b/TransformsGraphConfig.cmake.in @@ -1,3 +1,5 @@ @PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/TransformsGraphTargets.cmake") + +check_required_components(TransformsGraph) From 3283c4e6cbf78a40ac8d22d89c5f517384518918 Mon Sep 17 00:00:00 2001 From: aalbaali Date: Sat, 27 Apr 2024 15:34:02 -0400 Subject: [PATCH 2/5] Add linking instructions to readme Signed-off-by: aalbaali --- README.md | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6e9fb5f..2ea1669 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,10 @@ This is similar to the [tf2 ROS package](http://wiki.ros.org/tf2), but this pack * [Using `enum` for `Frame`](#using-enum-for-frame) * [Transforms storage](#transforms-storage) * [Mermaid graphs](#mermaid-graphs) -* [Installation](#installation) +Building and installing](#building-and-installing) + * [Copy include files locally](#copy-include-files-locally) + * [Link package to the downstream project](#link-package-to-the-downstream-project) + * [Install the package globally](#install-the-package-globally) * [FAQ](#faq) @@ -163,14 +166,38 @@ graph TD The transforms can be visualized for this option as well by passing `true` as the second argument to `GetMermaidGraph`. -# Installation -This is a header-only library. -It can be used by directly including the `include/transforms_graph/transforms_graph.h` into your folder, or it can be installed on your system by running the following from the root of this repo. +# Building and installing +This is a header-only library, so it doesn't need to be built. However, the examples and tests need to be built: ```bash -cmake -S . --build build +cmake -S . --build build -DBUILD_EXAMPLES=ON cmake --build build -sudo cmake --install build ``` +There are various ways to use the package downstream, which are listed below: +## Copy include files locally +Since the library is header-only, the header files can be included in the downstream project by copying `include/transforms_graph/transforms_graph.h` into the downstream project and including it into the CMake targets. + +## Link package to the downstream project +The TransformsGraph exports the `TransformsGraph::TransformsGraph` library. +The library can be imported downstream by adding the following to the `CMakeLists.txt` +```bash +# In the downstream CMakeLists.txt +find_package(TransformsGraph REQUIRED) +... +target_link_libraries(main TransformsGraph::TransformsGraph) +``` +The TransformsGraph *build* directory `` then needs to be passed as an argument when building the CMake project: +Then, the downstream +```bash +# In the downstream project +cmake -S . -B build -DTransformsGraph_DIR= +``` + +## Install the package globally +The TransformsGraph package can be installed globally by running +```bash +cmake --install build # May require `sudo` privileges +``` +The `CMakeLists.txt` downstream can then be used as shown in the [previous section](#link-package-to-the-downstream-project) # FAQ - Why use a graph instead of a tree or a forest? From c85b69b028ad369bc9ffed5e3cdf8a924992c9ef Mon Sep 17 00:00:00 2001 From: aalbaali Date: Sat, 27 Apr 2024 15:41:40 -0400 Subject: [PATCH 3/5] Use path variable in cmakelists Signed-off-by: aalbaali --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3164ae7..abe17ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,9 +52,9 @@ install( include(CMakePackageConfigHelpers) configure_package_config_file( "TransformsGraphConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphConfig.cmake" - INSTALL_DESTINATION "lib/cmake/TransformsGraph" + INSTALL_DESTINATION "${TRANSFORMS_GRAPH_CMAKE_EXPORT_DIR}" ) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphConfig.cmake" DESTINATION "lib/cmake/TransformsGraph") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphConfig.cmake" DESTINATION "${TRANSFORMS_GRAPH_CMAKE_EXPORT_DIR}") # Export without installing export( From 84452d2ca986ee09e2e90474bb4d9c63fdece1fb Mon Sep 17 00:00:00 2001 From: aalbaali Date: Sat, 27 Apr 2024 16:01:12 -0400 Subject: [PATCH 4/5] Generalize cmake target installation Signed-off-by: aalbaali --- CMakeLists.txt | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abe17ea..deb9a42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,17 +31,20 @@ endif() # Installation ################################################ # Export package for use from the build tree -set(TRANSFORMS_GRAPH_CMAKE_EXPORT_DIR lib/cmake/TransformsGraph) +set(CMAKE_EXPORT_DIR lib/cmake/TransformsGraph) +set(TARGETS_NAME "TransformsGraph") +set(TARGETS_NAMESPACE "TransformsGraph") +set(TARGETS_CONFIG_FILENAME "${TARGETS_NAME}Config.cmake.in") install( - TARGETS TransformsGraph - EXPORT TransformsGraphTargets + TARGETS "${TARGETS_NAME}" + EXPORT "${TARGETS_NAME}Targets" ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) -install(EXPORT TransformsGraphTargets - NAMESPACE TransformsGraph:: - DESTINATION ${TRANSFORMS_GRAPH_CMAKE_EXPORT_DIR} +install(EXPORT "${TARGETS_NAME}Targets" + NAMESPACE "${TARGETS_NAMESPACE}::" + DESTINATION ${CMAKE_EXPORT_DIR} ) # Install the include directory @@ -51,14 +54,14 @@ install( ) include(CMakePackageConfigHelpers) configure_package_config_file( - "TransformsGraphConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphConfig.cmake" - INSTALL_DESTINATION "${TRANSFORMS_GRAPH_CMAKE_EXPORT_DIR}" + "${TARGETS_CONFIG_FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/${TARGETS_NAME}Config.cmake" + INSTALL_DESTINATION "${CMAKE_EXPORT_DIR}" ) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphConfig.cmake" DESTINATION "${TRANSFORMS_GRAPH_CMAKE_EXPORT_DIR}") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${TARGETS_NAME}Config.cmake" DESTINATION "${CMAKE_EXPORT_DIR}") # Export without installing export( EXPORT TransformsGraphTargets - FILE "${CMAKE_CURRENT_BINARY_DIR}/TransformsGraphTargets.cmake" - NAMESPACE TransformsGraph:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGETS_NAME}Targets.cmake" + NAMESPACE "${TARGETS_NAMESPACE}::" ) From 8609c2d56c41c806e5ec31705ad12cdfeefffab7 Mon Sep 17 00:00:00 2001 From: aalbaali Date: Sat, 27 Apr 2024 16:02:27 -0400 Subject: [PATCH 5/5] fix: use var name to export target Signed-off-by: aalbaali --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index deb9a42..ca70337 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${TARGETS_NAME}Config.cmake" DESTINAT # Export without installing export( - EXPORT TransformsGraphTargets + EXPORT "${TARGETS_NAME}Targets" FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGETS_NAME}Targets.cmake" NAMESPACE "${TARGETS_NAMESPACE}::" )