Skip to content

Commit

Permalink
Add support for installation of the C++ library
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Feb 25, 2021
1 parent 9276c26 commit 9d84476
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
42 changes: 41 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ add_library(ruckig SHARED
src/velocity1.cpp
src/velocity2.cpp
)
add_library(ruckig::ruckig ALIAS ruckig)

target_compile_features(ruckig PUBLIC cxx_std_17)
target_include_directories(ruckig PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(ruckig PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(ruckig PUBLIC)
target_compile_options(ruckig PRIVATE -Werror -Wall -Wextra)

Expand Down Expand Up @@ -62,6 +65,43 @@ if(BUILD_PYTHON_MODULE)
target_link_libraries(_ruckig PUBLIC ruckig)
endif()

# Add support for installation
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# Install headers
install(DIRECTORY include/ruckig DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Install library
install(TARGETS ruckig
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

# Install CMake config files
set(ruckig_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})

install(EXPORT ${PROJECT_NAME}-targets
DESTINATION ${ruckig_INSTALL_CONFIGDIR}
NAMESPACE ruckig::
)

configure_package_config_file(cmake/ruckig-config.cmake.in ruckig-config.cmake
INSTALL_DESTINATION ${ruckig_INSTALL_CONFIGDIR}
)

write_basic_package_version_file(ruckig-config-version.cmake
VERSION ${ruckig_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/ruckig-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ruckig-config-version.cmake"
DESTINATION ${ruckig_INSTALL_CONFIGDIR}
)


if(BUILD_TESTS)
enable_testing()
Expand Down
5 changes: 5 additions & 0 deletions cmake/ruckig-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generated by CMake @CMAKE_VERSION@ for @PROJECT_NAME@

@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
8 changes: 8 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10)

project(ruckig_examples)

find_package(ruckig REQUIRED)

add_executable(ruckig-example-position position.cpp)
target_link_libraries(ruckig-example-position PRIVATE ruckig::ruckig)

0 comments on commit 9d84476

Please sign in to comment.