Skip to content

Commit

Permalink
Make CMake configuration files relocatable (#45)
Browse files Browse the repository at this point in the history
See discussion in #44
  • Loading branch information
traversaro authored and scpeters committed Aug 3, 2017
1 parent 9ef664d commit 15eb3ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
22 changes: 16 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ generate_export_header(${PROJECT_NAME}
EXPORT_MACRO_NAME CONSOLE_BRIDGE_DLLAPI)

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand All @@ -64,10 +65,21 @@ install(DIRECTORY include/
install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

if(WIN32 AND NOT CYGWIN)
set(CMAKE_CONFIG_INSTALL_DIR CMake)
else()
set(CMAKE_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/)
endif()

include(CMakePackageConfigHelpers)
set(PKG_NAME ${PROJECT_NAME})
set(PKG_LIBRARIES ${PROJECT_NAME})
set(cmake_conf_file "${PROJECT_NAME}-config.cmake")
configure_file("${cmake_conf_file}.in" "${CMAKE_BINARY_DIR}/${cmake_conf_file}" @ONLY)
configure_package_config_file("${cmake_conf_file}.in" "${CMAKE_BINARY_DIR}/${cmake_conf_file}"
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
set(cmake_conf_version_file "${PROJECT_NAME}-config-version.cmake")
# Use write_basic_package_version_file to generate a ConfigVersion file that
# allow users of gazebo to specify the API or version to depend on
Expand All @@ -79,11 +91,9 @@ write_basic_config_version_file(
VERSION "${CONSOLE_BRIDGE_VERSION}"
COMPATIBILITY SameMajorVersion)

if(WIN32 AND NOT CYGWIN)
set(CMAKE_CONFIG_INSTALL_DIR CMake)
else()
set(CMAKE_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/)
endif()
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR})
install(FILES
"${CMAKE_BINARY_DIR}/${cmake_conf_file}"
"${CMAKE_BINARY_DIR}/${cmake_conf_version_file}"
Expand Down
23 changes: 4 additions & 19 deletions console_bridge-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,9 @@ if (@PKG_NAME@_CONFIG_INCLUDED)
endif()
set(@PKG_NAME@_CONFIG_INCLUDED TRUE)

set(@PKG_NAME@_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
@PACKAGE_INIT@

foreach(lib @PKG_LIBRARIES@)
set(onelib "${lib}-NOTFOUND")
find_library(onelib ${lib}
PATHS "@CMAKE_INSTALL_FULL_LIBDIR@"
NO_DEFAULT_PATH
)
if(NOT onelib)
message(FATAL_ERROR "Library '${lib}' in package @PKG_NAME@ is not installed properly")
endif()
list(APPEND @PKG_NAME@_LIBRARIES ${onelib})
endforeach()
set(@PKG_NAME@_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")

foreach(dep @PKG_DEPENDS@)
if(NOT ${dep}_FOUND)
find_package(${dep})
endif()
list(APPEND @PKG_NAME@_INCLUDE_DIRS ${${dep}_INCLUDE_DIRS})
list(APPEND @PKG_NAME@_LIBRARIES ${${dep}_LIBRARIES})
endforeach()
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
set(@PKG_NAME@_LIBRARIES @PKG_NAME@)

0 comments on commit 15eb3ea

Please sign in to comment.