diff --git a/install/CMakeLists.txt b/install/CMakeLists.txt index 414373edc..f297b5cdc 100644 --- a/install/CMakeLists.txt +++ b/install/CMakeLists.txt @@ -23,7 +23,15 @@ function(install_zenohc_lib configurations property_postfix package_name) get_filename_component(STATICLIB ${staticlib_path} NAME) # Install dynamic, import and static library - install(FILES ${dylib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations}) + + # On Windows .dll need to be installed in ${CMAKE_INSTALL_BINDIR}, + # while on Linux and macOS .so and .dylib need to be installed in ${CMAKE_INSTALL_LIBDIR} + if(WIN32) + set(ZENOHC_INSTALL_DYLIBDIR ${CMAKE_INSTALL_BINDIR}) + else() + set(ZENOHC_INSTALL_DYLIBDIR ${CMAKE_INSTALL_LIBDIR}) + endif() + install(FILES ${dylib_path} DESTINATION ${ZENOHC_INSTALL_DYLIBDIR} CONFIGURATIONS ${configurations}) if(DEFINED implib_path) install(FILES ${implib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations}) endif() diff --git a/install/PackageConfig.cmake.in b/install/PackageConfig.cmake.in index e803d012f..e8e3a0574 100644 --- a/install/PackageConfig.cmake.in +++ b/install/PackageConfig.cmake.in @@ -25,32 +25,35 @@ if(_IMPORT_PREFIX STREQUAL "/") set(_IMPORT_PREFIX "") endif() -add_library(__zenohc_static STATIC IMPORTED GLOBAL) -message(STATUS "ZENOHC_BUILD_WITH_UNSTABLE_API=${ZENOHC_BUILD_WITH_UNSTABLE_API}") -message(STATUS "ZENOHC_BUILD_WITH_SHARED_MEMORY=${ZENOHC_BUILD_WITH_SHARED_MEMORY}") - -add_library(zenohc::static ALIAS __zenohc_static) -target_link_libraries(__zenohc_static INTERFACE @NATIVE_STATIC_LIBS@) -set_target_properties(__zenohc_static PROPERTIES - IMPORTED_LOCATION "${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@/@STATICLIB@" - INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@" -) +if(NOT TARGET __zenohc_static) + add_library(__zenohc_static STATIC IMPORTED GLOBAL) + add_library(zenohc::static ALIAS __zenohc_static) + target_link_libraries(__zenohc_static INTERFACE @NATIVE_STATIC_LIBS@) + set_target_properties(__zenohc_static PROPERTIES + IMPORTED_LOCATION "${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@/@STATICLIB@" + INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@" + ) +endif() -add_library(__zenohc_shared SHARED IMPORTED GLOBAL) -add_library(zenohc::shared ALIAS __zenohc_shared) -set_target_properties(__zenohc_shared PROPERTIES - IMPORTED_NO_SONAME TRUE - INTERFACE_COMPILE_DEFINITION ZENOHC_DYN_LIB - IMPORTED_LOCATION "${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@/@DYLIB@" - INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@" -) +if(NOT TARGET __zenohc_shared) + add_library(__zenohc_shared SHARED IMPORTED GLOBAL) + add_library(zenohc::shared ALIAS __zenohc_shared) + set_target_properties(__zenohc_shared PROPERTIES + IMPORTED_NO_SONAME TRUE + INTERFACE_COMPILE_DEFINITION ZENOHC_DYN_LIB + IMPORTED_LOCATION "${_IMPORT_PREFIX}/@ZENOHC_INSTALL_DYLIBDIR@/@DYLIB@" + INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/@CMAKE_INSTALL_INCLUDEDIR@" + ) +endif() if(NOT ("@IMPLIB@" STREQUAL "")) set_property(TARGET __zenohc_shared PROPERTY IMPORTED_IMPLIB "${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@/@IMPLIB@") endif() -if(ZENOHC_LIB_STATIC) +if(NOT TARGET zenohc::lib) + if(ZENOHC_LIB_STATIC) add_library(zenohc::lib ALIAS __zenohc_static) -else() + else() add_library(zenohc::lib ALIAS __zenohc_shared) + endif() endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c247b1787..69e7e1530 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,6 +2,8 @@ message(STATUS "zenoh-c tests") add_custom_target(tests) +find_package(Threads REQUIRED) + file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.c") foreach(file ${files}) get_filename_component(target ${file} NAME_WE) @@ -34,7 +36,7 @@ foreach(file ${files}) add_executable(${target} EXCLUDE_FROM_ALL ${file}) add_dependencies(tests ${target}) add_dependencies(${target} zenohc::lib) - target_link_libraries(${target} PRIVATE zenohc::lib) + target_link_libraries(${target} PRIVATE zenohc::lib Threads::Threads) copy_dlls(${target}) set_property(TARGET ${target} PROPERTY C_STANDARD 11) add_test(NAME "${test_type}_${target}" COMMAND ${target})