Skip to content

Commit

Permalink
Do not re-define targets if find_package(zenohcxx) is called twice (#232
Browse files Browse the repository at this point in the history
)
  • Loading branch information
traversaro authored Oct 2, 2024
1 parent 088563b commit 71d8d5a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions install/PackageConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()

set(_ZENOHCXX_BACKEND_FOUND FALSE)
add_library(zenohcxx INTERFACE IMPORTED)
target_include_directories(zenohcxx INTERFACE "${_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@")
if(NOT TARGET zenohcxx)
add_library(zenohcxx INTERFACE IMPORTED)
target_include_directories(zenohcxx INTERFACE "${_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@")
endif()

# zenohcxx for zenohpico
if(TARGET zenohpico::lib)
set(_ZENOHCXX_BACKEND_FOUND TRUE)
if(TARGET zenohpico::lib AND NOT TARGET zenohcxx_zenohpico)
message(STATUS "defined lib target zenohcxx::zenohpico for zenohpico::lib")
add_library(zenohcxx_zenohpico INTERFACE IMPORTED)
target_compile_definitions(zenohcxx_zenohpico INTERFACE ZENOHCXX_ZENOHPICO)
Expand All @@ -40,8 +40,7 @@ if(TARGET zenohpico::lib)
endif()

# zenohcxx for zenohc static/dynamic depending on ZENOHC_LIB_STATIC
if(TARGET zenohc::lib)
set(_ZENOHCXX_BACKEND_FOUND TRUE)
if(TARGET zenohc::lib AND NOT TARGET zenohcxx_zenohc)
message(STATUS "defined lib target zenohcxx::zenohc for zenohc::lib")
add_library(zenohcxx_zenohc INTERFACE IMPORTED)
target_compile_definitions(zenohcxx_zenohc INTERFACE ZENOHCXX_ZENOHC)
Expand All @@ -51,6 +50,6 @@ if(TARGET zenohc::lib)
add_library(zenohcxx::zenohc ALIAS zenohcxx_zenohc)
endif()

if(NOT _ZENOHCXX_BACKEND_FOUND)
if(NOT TARGET zenohcxx_zenohpico AND NOT TARGET zenohcxx_zenohc)
message(FATAL_ERROR "Failed to detect zenoh-cpp backend, you need to have either zenoh-c or zenoh-pico installed" )
endif()
endif()

0 comments on commit 71d8d5a

Please sign in to comment.