From e11d3efb198722b5c36126f76c86add582e47149 Mon Sep 17 00:00:00 2001 From: Jeremie Deray Date: Sat, 21 May 2022 14:46:33 -0400 Subject: [PATCH] revisit export (#379) --- CMakeLists.txt | 35 ++++++++++++++++++++++++++++------- cmake/Config.cmake.in | 7 +++++++ 2 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 cmake/Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b9cf5d9a..cd490a571 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,7 +279,7 @@ endif() # INSTALL INSTALL(TARGETS ${BEHAVIOR_TREE_LIBRARY} - EXPORT BehaviorTreeV3Config + EXPORT ${PROJECT_NAME}Targets ARCHIVE DESTINATION ${BEHAVIOR_TREE_LIB_DESTINATION} LIBRARY DESTINATION ${BEHAVIOR_TREE_LIB_DESTINATION} RUNTIME DESTINATION ${BEHAVIOR_TREE_BIN_DESTINATION} @@ -289,16 +289,37 @@ INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${BEHAVIOR_TREE_INC_DESTINATION} FILES_MATCHING PATTERN "*.h*") -install(EXPORT BehaviorTreeV3Config - DESTINATION "${BEHAVIOR_TREE_LIB_DESTINATION}/BehaviorTreeV3/cmake" - NAMESPACE BT::) - -export(TARGETS ${PROJECT_NAME} +install(EXPORT ${PROJECT_NAME}Targets + FILE "${PROJECT_NAME}Targets.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" NAMESPACE BT:: - FILE "${CMAKE_CURRENT_BINARY_DIR}/BehaviorTreeV3Config.cmake") + ) export(PACKAGE ${PROJECT_NAME}) +include(CMakePackageConfigHelpers) + +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) + +# This requires to declare to project version in the project() macro + +#write_basic_package_version_file( +# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" +# VERSION ${PROJECT_VERSION} +# COMPATIBILITY AnyNewerVersion +#) + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + # "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) + ###################################################### # EXAMPLES and TOOLS if(BUILD_TOOLS) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 000000000..64f20beb5 --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + +set(@PROJECT_NAME@_TARGETS "BT::@BEHAVIOR_TREE_LIBRARY@") + +check_required_components(@PROJECT_NAME@)