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

Cmake package config helpers #128

Merged
merged 4 commits into from
Jan 31, 2024
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
32 changes: 18 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 ()
Expand Down Expand Up @@ -84,6 +86,8 @@ else ()
set (CMAKE_CXX_STANDARD 11)
endif ()

#======================== External Dependencies ===============================

include(GNUInstallDirs)

# eigen 2 or 3
Expand Down Expand Up @@ -243,35 +247,35 @@ export(


# Create variable with the library location
set(libnabo_library $<TARGET_FILE:${LIB_NAME}>)
set(libnabo_library $<TARGET_FILE:${PROJECT_NAME}::${LIB_NAME}>)

# 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/$<TARGET_FILE_NAME:${LIB_NAME}>)
set(libnabo_library $<TARGET_FILE:${PROJECT_NAME}::${LIB_NAME}>)

# 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"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,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_INCLUDE_DIRS})
```

Quick compilation and installation under Unix
---------------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions libnaboConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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@")
11 changes: 0 additions & 11 deletions libnaboConfigVersion.cmake.in

This file was deleted.

1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<buildtool_depend>cmake</buildtool_depend>
<build_depend>eigen</build_depend>
<build_depend>boost</build_depend>

<exec_depend>eigen</exec_depend>
<exec_depend>boost</exec_depend>
<exec_depend condition="$ROS_VERSION == 1">catkin</exec_depend>
Expand Down