diff --git a/CMakeLists.txt b/CMakeLists.txt index 277aac87e1..07cff53827 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -422,6 +422,11 @@ else (build_errors) join_paths(pkgconfig_libdir "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") join_paths(pkgconfig_includedir "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") + file(RELATIVE_PATH + PC_CONFIG_RELATIVE_PATH_TO_PREFIX + ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/pkgconfig + ${CMAKE_INSTALL_PREFIX} + ) foreach (pkgconfig ${pkgconfig_files}) configure_file(${CMAKE_SOURCE_DIR}/cmake/pkgconfig/${pkgconfig}.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${pkgconfig}.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${pkgconfig}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig COMPONENT pkgconfig) @@ -475,9 +480,15 @@ else (build_errors) set(PKG_LIBRARIES ${PKG_LIBRARIES} gazebo_ccd) endif() + include(CMakePackageConfigHelpers) set(cmake_conf_file "cmake/gazebo-config.cmake") set(cmake_conf_version_file "cmake/gazebo-config-version.cmake") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${cmake_conf_file}.in" "${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}" @ONLY) + set(DATAROOT_INSTALL_DIR ${CMAKE_INSTALL_DATAROOTDIR}) + set(BASE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}) + configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/${cmake_conf_file}.in" "${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}" + INSTALL_DESTINATION ${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME_LOWER}/ + PATH_VARS BASE_INSTALL_INCLUDEDIR LIB_INSTALL_DIR DATAROOT_INSTALL_DIR + ) # 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 # TODO: keep this instruction until deprecate Ubuntu/Precise and update with diff --git a/cmake/GazeboTestUtils.cmake b/cmake/GazeboTestUtils.cmake index 7c42178b63..ca1768c42b 100644 --- a/cmake/GazeboTestUtils.cmake +++ b/cmake/GazeboTestUtils.cmake @@ -67,11 +67,9 @@ macro (gz_build_tests) --gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml) set(_env_vars) - list(APPEND _env_vars "CMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}:$ENV{CMAKE_PREFIX_PATH}") list(APPEND _env_vars "GAZEBO_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins:${CMAKE_BINARY_DIR}/plugins/events:${CMAKE_BINARY_DIR}/plugins/rest_web") list(APPEND _env_vars "GAZEBO_RESOURCE_PATH=${CMAKE_SOURCE_DIR}") list(APPEND _env_vars "PATH=${CMAKE_BINARY_DIR}/gazebo:${CMAKE_BINARY_DIR}/tools:$ENV{PATH}") - list(APPEND _env_vars "PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/cmake/pkgconfig:$ENV{PKG_CONFIG_PATH}") set_tests_properties(${BINARY_NAME} PROPERTIES TIMEOUT 240 ENVIRONMENT "${_env_vars}") @@ -137,11 +135,9 @@ if (VALID_DISPLAY) -xml -o ${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml) set(_env_vars) - list(APPEND _env_vars "CMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}:${CMAKE_PREFIX_PATH}") list(APPEND _env_vars "GAZEBO_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins:${CMAKE_BINARY_DIR}/plugins/events:${CMAKE_BINARY_DIR}/plugins/rest_web") list(APPEND _env_vars "GAZEBO_RESOURCE_PATH=${CMAKE_SOURCE_DIR}") list(APPEND _env_vars "PATH=${CMAKE_BINARY_DIR}/gazebo:${CMAKE_BINARY_DIR}/tools:$ENV{PATH}") - list(APPEND _env_vars "PKG_CONFIG_PATH=${CMAKE_BINARY_DIR}/cmake/pkgconfig:$PKG_CONFIG_PATH") set_tests_properties(${BINARY_NAME} PROPERTIES TIMEOUT 240 ENVIRONMENT "${_env_vars}") diff --git a/cmake/gazebo-config.cmake.in b/cmake/gazebo-config.cmake.in index e68584082c..dccc3f2a08 100644 --- a/cmake/gazebo-config.cmake.in +++ b/cmake/gazebo-config.cmake.in @@ -5,14 +5,21 @@ set(@PKG_NAME@_CONFIG_INCLUDED TRUE) set(@PKG_NAME@_VERSION @GAZEBO_VERSION@) set(@PKG_NAME@_MAJOR_VERSION @GAZEBO_MAJOR_VERSION@) -set(@PKG_NAME@_PLUGIN_PATH "@CMAKE_INSTALL_FULL_LIBDIR@/gazebo-@GAZEBO_MAJOR_VERSION@/plugins") +@PACKAGE_INIT@ + +# Including Dartsim will overwrite the PACKAGE_PREFIX_DIR, therefore make gazebo-specific vars +set(GAZEBO_INSTALL_DATAROOT_DIR @PACKAGE_DATAROOT_INSTALL_DIR@) +set(GAZEBO_INSTALL_LIB_DIR @PACKAGE_LIB_INSTALL_DIR@) +set(GAZEBO_INSTALL_INCLUDE_DIR @PACKAGE_BASE_INSTALL_INCLUDEDIR@) + +set(@PKG_NAME@_PLUGIN_PATH "${GAZEBO_INSTALL_LIB_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@/plugins") # The media path contains the location on disk where images, # materials scripts, shaders, and other related resources are stored. -set(@PKG_NAME@_MEDIA_PATH "@CMAKE_INSTALL_PREFIX@/share/gazebo-@GAZEBO_MAJOR_VERSION@/media") +set(@PKG_NAME@_MEDIA_PATH "${GAZEBO_INSTALL_DATAROOT_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@/media") # The model path contains the location on disk where models are stored. -set(@PKG_NAME@_MODEL_PATH "@CMAKE_INSTALL_PREFIX@/share/gazebo-@GAZEBO_MAJOR_VERSION@/models") +set(@PKG_NAME@_MODEL_PATH "${GAZEBO_INSTALL_DATAROOT_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@/models") # Set whether Gazebo was built with Bullet support set (GAZEBO_HAS_BULLET @HAVE_BULLET@) @@ -72,23 +79,23 @@ include (FindPkgConfig) # target_link_libraries(your_package @PKG_NAME@_PROTO_LIBRARIES) # set(@PKG_NAME@_PROTO_PATH - "@CMAKE_INSTALL_FULL_INCLUDEDIR@/gazebo-@GAZEBO_MAJOR_VERSION@/gazebo/msgs/proto") + "${GAZEBO_INSTALL_INCLUDE_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@/gazebo/msgs/proto") find_library(gazebo_proto_msgs_lib gazebo_msgs - PATHS "@CMAKE_INSTALL_FULL_LIBDIR@" NO_DEFAULT_PATH) + PATHS "${GAZEBO_INSTALL_LIB_DIR}" NO_DEFAULT_PATH) list(APPEND @PKG_NAME@_PROTO_LIBRARIES ${gazebo_proto_msgs_lib}) list(APPEND @PKG_NAME@_PROTO_INCLUDE_DIRS - "@CMAKE_INSTALL_FULL_INCLUDEDIR@/gazebo-@GAZEBO_MAJOR_VERSION@/gazebo/msgs") + "${GAZEBO_INSTALL_INCLUDE_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@/gazebo/msgs") # End @PKG_NAME@_PROTO_PATH, @PKG_NAME@_PROTO_INCLUDE_DIRS, and # @PKG_NAME@_PROTO_LIBRARIES -list(APPEND @PKG_NAME@_INCLUDE_DIRS @CMAKE_INSTALL_FULL_INCLUDEDIR@) -list(APPEND @PKG_NAME@_INCLUDE_DIRS @CMAKE_INSTALL_FULL_INCLUDEDIR@/gazebo-@GAZEBO_MAJOR_VERSION@) +list(APPEND @PKG_NAME@_INCLUDE_DIRS ${GAZEBO_INSTALL_INCLUDE_DIR}) +list(APPEND @PKG_NAME@_INCLUDE_DIRS ${GAZEBO_INSTALL_INCLUDE_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@) -list(APPEND @PKG_NAME@_LIBRARY_DIRS @CMAKE_INSTALL_FULL_LIBDIR@) -list(APPEND @PKG_NAME@_LIBRARY_DIRS @CMAKE_INSTALL_FULL_LIBDIR@/gazebo-@GAZEBO_MAJOR_VERSION@/plugins) +list(APPEND @PKG_NAME@_LIBRARY_DIRS ${GAZEBO_INSTALL_LIB_DIR}) +list(APPEND @PKG_NAME@_LIBRARY_DIRS ${GAZEBO_INSTALL_LIB_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@/plugins) -list(APPEND @PKG_NAME@_CFLAGS -I@CMAKE_INSTALL_FULL_INCLUDEDIR@) -list(APPEND @PKG_NAME@_CFLAGS -I@CMAKE_INSTALL_FULL_INCLUDEDIR@/gazebo-@GAZEBO_MAJOR_VERSION@) +list(APPEND @PKG_NAME@_CFLAGS -I${GAZEBO_INSTALL_INCLUDE_DIR}) +list(APPEND @PKG_NAME@_CFLAGS -I${GAZEBO_INSTALL_INCLUDE_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@) if (GAZEBO_HAS_BULLET) if (PKG_CONFIG_FOUND) @@ -139,7 +146,7 @@ endif () foreach(lib @PKG_LIBRARIES@) set(onelib "${lib}-NOTFOUND") find_library(onelib ${lib} - PATHS "@CMAKE_INSTALL_FULL_LIBDIR@" + PATHS "${GAZEBO_INSTALL_LIB_DIR}" NO_DEFAULT_PATH ) if(NOT onelib) @@ -216,6 +223,6 @@ list(APPEND @PKG_NAME@_INCLUDE_DIRS ${IGNITION-FUEL_TOOLS_INCLUDE_DIRS}) list(APPEND @PKG_NAME@_LIBRARY_DIRS ${IGNITION-FUEL_TOOLS_LIBRARY_DIRS}) list(APPEND @PKG_NAME@_LIBRARIES ${IGNITION-FUEL_TOOLS_LIBRARIES}) -list(APPEND @PKG_NAME@_LDFLAGS -Wl,-rpath,@CMAKE_INSTALL_FULL_LIBDIR@/gazebo-@GAZEBO_MAJOR_VERSION@/plugins) -list(APPEND @PKG_NAME@_LDFLAGS -L@CMAKE_INSTALL_FULL_LIBDIR@) -list(APPEND @PKG_NAME@_LDFLAGS -L@CMAKE_INSTALL_FULL_LIBDIR@/gazebo-@GAZEBO_MAJOR_VERSION@/plugins) +list(APPEND @PKG_NAME@_LDFLAGS -Wl,-rpath,${GAZEBO_INSTALL_LIB_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@/plugins) +list(APPEND @PKG_NAME@_LDFLAGS -L${GAZEBO_INSTALL_LIB_DIR}) +list(APPEND @PKG_NAME@_LDFLAGS -L${GAZEBO_INSTALL_LIB_DIR}/gazebo-@GAZEBO_MAJOR_VERSION@/plugins) diff --git a/cmake/pkgconfig/gazebo.in b/cmake/pkgconfig/gazebo.in index 16cc62e562..091bbcb06e 100644 --- a/cmake/pkgconfig/gazebo.in +++ b/cmake/pkgconfig/gazebo.in @@ -1,4 +1,4 @@ -prefix=@CMAKE_INSTALL_PREFIX@ +prefix=${pcfiledir}/@PC_CONFIG_RELATIVE_PATH_TO_PREFIX@ libdir=@pkgconfig_libdir@ includedir=@pkgconfig_includedir@ diff --git a/cmake/pkgconfig/gazebo_ode.in b/cmake/pkgconfig/gazebo_ode.in index 2516a73c0f..fdd319963a 100644 --- a/cmake/pkgconfig/gazebo_ode.in +++ b/cmake/pkgconfig/gazebo_ode.in @@ -1,4 +1,4 @@ -prefix=@CMAKE_INSTALL_PREFIX@ +prefix=${pcfiledir}/@PC_CONFIG_RELATIVE_PATH_TO_PREFIX@ libdir=@pkgconfig_libdir@ includedir=@pkgconfig_includedir@ diff --git a/cmake/pkgconfig/gazebo_transport.in b/cmake/pkgconfig/gazebo_transport.in index f3ac1de4a2..dcfdd6e32d 100644 --- a/cmake/pkgconfig/gazebo_transport.in +++ b/cmake/pkgconfig/gazebo_transport.in @@ -1,4 +1,4 @@ -prefix=@CMAKE_INSTALL_PREFIX@ +prefix=${pcfiledir}/@PC_CONFIG_RELATIVE_PATH_TO_PREFIX@ libdir=@pkgconfig_libdir@ includedir=@pkgconfig_includedir@