Skip to content

Commit

Permalink
Add USE_VENDORED_DEPS option, set urdfdom_LIBRARIES to targets
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Feb 28, 2024
1 parent 3a3754e commit 47f31c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include(GNUInstallDirs)

option(BUILD_APPS "Build applications" ON)
option(BUILD_TESTING "Build tests" OFF)
option(USE_VENDORED_DEPS "Use vendored dependencies" ON)
option(APPEND_PROJECT_NAME_TO_INCLUDEDIR
"When ON headers are installed to a folder ending with an extra ${PROJECT_NAME}. \
This avoids include directory search order issues when overriding this package
Expand Down Expand Up @@ -47,11 +48,13 @@ endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

find_package(tinyxml2_vendor QUIET)
find_package(TinyXML2 REQUIRED)

find_package(urdfdom_headers 1.0 REQUIRED)
find_package(console_bridge_vendor QUIET) # Provides console_bridge 0.4.0 on platforms without it.

if(USE_VENDORED_DEPS)
find_package(tinyxml2_vendor QUIET)
find_package(console_bridge_vendor QUIET) # Provides console_bridge 0.4.0 on platforms without it.
endif()
find_package(TinyXML2 REQUIRED)
find_package(console_bridge REQUIRED)

# Control where libraries and executables are placed during the build
Expand Down
26 changes: 20 additions & 6 deletions cmake/urdfdom-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ set(@PKG_NAME@_CONFIG_INCLUDED TRUE)
set(CMAKE_MODULE_PATH_BACKUP_URDFDOM ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH "${@PROJECT_NAME@_DIR}")

set(@PKG_NAME@_INCLUDE_DIRS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@")
set(@PKG_NAME@_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")

foreach(lib @PKG_LIBRARIES@)
set(onelib "${lib}-NOTFOUND")
set(onelibd "${lib}-NOTFOUND")
find_library(onelib ${lib}
PATHS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_LIBDIR@"
PATHS "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@"
NO_DEFAULT_PATH)
find_library(onelibd ${lib}d
PATHS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_LIBDIR@"
PATHS "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@"
NO_DEFAULT_PATH)
if(onelib-NOTFOUND AND onelibd-NOTFOUND)
message(FATAL_ERROR "Library '${lib}' in package @PKG_NAME@ is not installed properly")
Expand All @@ -36,17 +36,31 @@ foreach(lib @PKG_LIBRARIES@)
endforeach()

include(CMakeFindDependencyMacro)
find_dependency(tinyxml2_vendor QUIET)
if(@USE_VENDORED_DEPS@)
find_dependency(tinyxml2_vendor QUIET)
find_dependency(console_bridge_vendor QUIET)
else()
find_dependency(TinyXML2 REQUIRED)
find_dependency(console_bridge REQUIRED)
endif()
foreach(dep @PKG_DEPENDS@)
if(NOT ${dep}_FOUND)
find_dependency(${dep})
endif()
list(APPEND @PKG_NAME@_INCLUDE_DIRS ${${dep}_INCLUDE_DIRS})
list(APPEND @PKG_NAME@_LIBRARIES ${${dep}_LIBRARIES})
endforeach()

if(NOT TARGET urdfdom_headers::urdfdom_headers)
add_library(urdfdom_headers::urdfdom_headers INTERFACE IMPORTED)
set_target_properties(urdfdom_headers::urdfdom_headers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${urdfdom_headers_INCLUDE_DIRS}"
)
endif()
list(APPEND @PKG_NAME@_INCLUDE_DIRS "${urdfdom_headers_INCLUDE_DIRS}")

foreach(exp @PKG_EXPORTS@)
include(${@PROJECT_NAME@_DIR}/${exp}Export.cmake)
endforeach()

set(@PKG_NAME@_LIBRARIES ${@PKG_NAME@_TARGETS})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH_BACKUP_URDFDOM})

0 comments on commit 47f31c8

Please sign in to comment.