From 626621f64c56fb4c8464346a530a69fdb990b30e Mon Sep 17 00:00:00 2001 From: boxanm Date: Fri, 24 Nov 2023 09:27:59 -0500 Subject: [PATCH 1/3] Use CMakePackageConfigHelpers to generate config files. Fill libnabo_INCLUDE_DIRS and libnabo_LIBRARIES variables. --- CMakeLists.txt | 32 ++++++++++++++++++-------------- libnaboConfig.cmake.in | 10 ++++++++++ libnaboConfigVersion.cmake.in | 11 ----------- package.xml | 1 + 4 files changed, 29 insertions(+), 25 deletions(-) delete mode 100644 libnaboConfigVersion.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index c0061df..6cf48bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.8) +include(CMakePackageConfigHelpers) + if (NOT CMAKE_VERSION VERSION_LESS "3.1") cmake_policy(SET CMP0054 NEW) endif () @@ -84,6 +86,8 @@ else () set (CMAKE_CXX_STANDARD 11) endif () +#======================== External Dependencies =============================== + include(GNUInstallDirs) # eigen 2 or 3 @@ -243,35 +247,35 @@ export( # Create variable with the library location -set(libnabo_library $) +set(libnabo_library $) # Create variable for the local build tree get_property(libnabo_include_dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) # Configure & generate config file for local build tree -configure_file(libnaboConfig.cmake.in - "${PROJECT_BINARY_DIR}/libnaboConfig.cmake.conf" @ONLY) -file(GENERATE - OUTPUT "${PROJECT_BINARY_DIR}/libnaboConfig.cmake" - INPUT "${PROJECT_BINARY_DIR}/libnaboConfig.cmake.conf") +configure_package_config_file(libnaboConfig.cmake.in + "${PROJECT_BINARY_DIR}/libnaboConfig.cmake" + INSTALL_DESTINATION share/libnabo/cmake + PATH_VARS PROJECT_NAME + ) # 2- installation build # # Change the library location for an install location -set(libnabo_library ${CMAKE_INSTALL_PREFIX}/lib/$) +set(libnabo_library $) # Change the include location for the case of an install location set(libnabo_include_dirs ${CMAKE_INSTALL_PREFIX}/include) # We put the generated file for installation in a different repository (i.e., ./CMakeFiles/) -configure_file(libnaboConfig.cmake.in - "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libnaboConfig.cmake.conf" @ONLY) -file(GENERATE - OUTPUT "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libnaboConfig.cmake" - INPUT "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libnaboConfig.cmake.conf") +configure_package_config_file(libnaboConfig.cmake.in + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libnaboConfig.cmake" + INSTALL_DESTINATION share/libnabo/cmake + PATH_VARS PROJECT_NAME + ) # The same versioning file can be used for both cases -configure_file(libnaboConfigVersion.cmake.in - "${PROJECT_BINARY_DIR}/libnaboConfigVersion.cmake" @ONLY) +write_basic_package_version_file(libnaboConfigVersion.cmake + COMPATIBILITY AnyNewerVersion) install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libnaboConfig.cmake" diff --git a/libnaboConfig.cmake.in b/libnaboConfig.cmake.in index 0de01c3..65b4834 100644 --- a/libnaboConfig.cmake.in +++ b/libnaboConfig.cmake.in @@ -1,6 +1,16 @@ # - Config file for the libnabo package +# It defines the following variables +# libnabo_INCLUDE_DIRS - include directories for libnabo +# libnabo_LIBRARIES - libraries to link against +@PACKAGE_INIT@ include(${CMAKE_CURRENT_LIST_DIR}/libnabo-targets.cmake) # This causes catkin_simple to link against these libraries set(libnabo_FOUND_CATKIN_PROJECT true) + +# Compute paths +set(libnabo_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") +set(libnabo_LIBRARIES "@libnabo_library@") + +check_required_components("@PROJECT_NAME@") \ No newline at end of file diff --git a/libnaboConfigVersion.cmake.in b/libnaboConfigVersion.cmake.in deleted file mode 100644 index 0b99844..0000000 --- a/libnaboConfigVersion.cmake.in +++ /dev/null @@ -1,11 +0,0 @@ -set(PACKAGE_VERSION "@PROJECT_VERSION@") - -# Check whether the requested PACKAGE_FIND_VERSION is compatible -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() diff --git a/package.xml b/package.xml index cb9bac6..ceab2c5 100644 --- a/package.xml +++ b/package.xml @@ -15,6 +15,7 @@ cmake eigen boost + eigen boost catkin From 5119df9db4fc0e3398b53ed8a8d48335354c8260 Mon Sep 17 00:00:00 2001 From: boxanm Date: Fri, 24 Nov 2023 09:33:57 -0500 Subject: [PATCH 2/3] Update README.md with cmake guide --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 2cf9e00..9239dfc 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,14 @@ libnabo provides the following compilation options, available through [CMake]: You can specify them with a command-line tool, `ccmake`, or with a graphical tool, `cmake-gui`. Please read the [CMake documentation] for more information. +Add libnabo to your CMake project +--------------------------------------------- +```cmake +find_package(libnabo REQUIRED) +target_link_libraries(example PUBLIC ${libnabo_LIBRARIES}) +target_include_directories(example PUBLIC ${libnabo_DIRECTORIES}) +``` + Quick compilation and installation under Unix --------------------------------------------- From af4470fa565c91ccbda06f8a6d6ce2f9181b3421 Mon Sep 17 00:00:00 2001 From: boxanm <47394922+boxanm@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:19:24 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9239dfc..210446a 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Add libnabo to your CMake project ```cmake find_package(libnabo REQUIRED) target_link_libraries(example PUBLIC ${libnabo_LIBRARIES}) -target_include_directories(example PUBLIC ${libnabo_DIRECTORIES}) +target_include_directories(example PUBLIC ${libnabo_INCLUDE_DIRS}) ``` Quick compilation and installation under Unix