Skip to content

Commit

Permalink
add sample toolchains and fix library names
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Oct 24, 2024
1 parent aab2487 commit a13f7ac
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 97 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ rustflags = "-Ctarget-feature=-crt-static"

[target.aarch64-unknown-linux-musl]
rustflags = "-Ctarget-feature=-crt-static"

[target.armv7-unknown-linux-gnueabihf]
linker = "armv7-linux-gnueabihf-gcc"
79 changes: 50 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,35 @@ endmacro()
# dylib[r|d] - dymamic library (.so, .dll, .dylib)
# staticlib[r|d] - static library (.a, .lib)
# implib[r|d] - import library for windows dynamic library (DLL) - .lib
# dylibs[r|d] - list of files required for use dynamic libraty
# staticlibs[r|d] - list of files required for use static libraty
set_lib(dylibsr dylibr ${CMAKE_SHARED_LIBRARY_PREFIX}zenohc${CMAKE_SHARED_LIBRARY_SUFFIX})
set_lib(dylibsd dylibd ${CMAKE_SHARED_LIBRARY_PREFIX}zenohcd${CMAKE_SHARED_LIBRARY_SUFFIX})
set_lib(staticlibsr staticlibr ${CMAKE_STATIC_LIBRARY_PREFIX}zenohc${CMAKE_STATIC_LIBRARY_SUFFIX})
set_lib(staticlibsd staticlibd ${CMAKE_STATIC_LIBRARY_PREFIX}zenohcd${CMAKE_STATIC_LIBRARY_SUFFIX})
# dylibs[r|d] - list of files required for use dynamic library
# staticlibs[r|d] - list of files required for use static library
# get rust output library names from https://github.com/corrosion-rs/corrosion/blob/1c6974c2473765449e7c4649f9f96f1b751420c3/cmake/Corrosion.cmake#L331
if(WIN32)
set_lib(dylibsr implibr ${CMAKE_IMPORT_LIBRARY_PREFIX}zenohc${CMAKE_SHARED_LIBRARY_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX})
set_lib(dylibsd implibd ${CMAKE_IMPORT_LIBRARY_PREFIX}zenohcd${CMAKE_SHARED_LIBRARY_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX})
set_lib(dylibsr dylibr zenohc.dll)
set_lib(dylibsd dylibd zenohcd.dll)
if(MSVC)
set_lib(staticlibsr staticlibr zenohc.lib)
set_lib(staticlibsd staticlibd zenohcd.lib)
set_lib(dylibsr implibr zenohc.dll.lib)
set_lib(dylibsd implibd zenohcd.dll.lib)
else() #gnu/mingw/msys ?
set_lib(staticlibsr staticlibr libzenohc.a)
set_lib(staticlibsd staticlibd libzenohcd.a)
set_lib(dylibsr implibr libzenohc.dll.a)
set_lib(dylibsd implibd libzenohcd.dll.a)
endif()
elseif(APPLE)
set_lib(dylibsr dylibr libzenohc.dylib)
set_lib(dylibsd dylibd libzenohcd.dylib)
set_lib(staticlibsr staticlibr libzenohc.a)
set_lib(staticlibsd staticlibd libzenohcd.a)
else() #UNIX
set_lib(dylibsr dylibr libzenohc.so)
set_lib(dylibsd dylibd libzenohcd.so)
set_lib(staticlibsr staticlibr libzenohc.a)
set_lib(staticlibsd staticlibd libzenohcd.a)
endif()

list(APPEND libsr ${dylibsr})
list(APPEND libsr ${staticlibsr})
list(APPEND libsd ${dylibsd})
Expand Down Expand Up @@ -262,31 +281,33 @@ endfunction()
# *IMPORTANT* any options in this section should be repeated in install/PackageConfig.cmake.in
# to achieve correct behavior of find_package(zenohc)
#
add_library(zenohc_shared SHARED IMPORTED GLOBAL)
add_library(zenohc::shared ALIAS zenohc_shared)
add_dependencies(zenohc_shared cargo)
target_compile_definitions(zenohc_shared INTERFACE ZENOHC_DYN_LIB)
# Workaroud for https://github.com/rust-lang/cargo/issues/5045
# mentioned in https://github.com/eclipse-zenoh/zenoh-c/issues/138
# If it's fixed, do not forget to correct PackageConfig.cmake.in also
set_target_properties(zenohc_shared PROPERTIES IMPORTED_NO_SONAME TRUE)
set_target_imported_locations(zenohc_shared ${dylibr} ${dylibd})
add_library(zenohc_static STATIC IMPORTED GLOBAL)
add_library(zenohc::static ALIAS zenohc_static)
add_dependencies(zenohc_static cargo)
get_required_static_libs(NATIVE_STATIC_LIBS)
target_link_libraries(zenohc_static INTERFACE ${NATIVE_STATIC_LIBS})
set_target_imported_locations(zenohc_static ${staticlibr} ${staticlibd})
target_include_directories(zenohc_static INTERFACE ${cargo_generated_include_dir})
set_target_properties(zenohc_static PROPERTIES IMPORTED_GLOBAL TRUE)

if(DEFINED implibr)
set_target_imported_implib(zenohc_shared ${implibr} ${implibd})
endif()
target_include_directories(zenohc_shared INTERFACE ${cargo_generated_include_dir})
set_target_properties(zenohc_shared PROPERTIES IMPORTED_GLOBAL TRUE)
if (BUILD_SHARED_LIBS)
add_library(zenohc_shared SHARED IMPORTED GLOBAL)
add_library(zenohc::lib ALIAS zenohc_shared)
add_dependencies(zenohc_shared cargo)
target_compile_definitions(zenohc_shared INTERFACE ZENOHC_DYN_LIB)
# Workaroud for https://github.com/rust-lang/cargo/issues/5045
# mentioned in https://github.com/eclipse-zenoh/zenoh-c/issues/138
# If it's fixed, do not forget to correct PackageConfig.cmake.in also
set_target_properties(zenohc_shared PROPERTIES IMPORTED_NO_SONAME TRUE)
set_target_imported_locations(zenohc_shared ${dylibr} ${dylibd})
if(DEFINED implibr)
set_target_imported_implib(zenohc_shared ${implibr} ${implibd})
endif()
target_include_directories(zenohc_shared INTERFACE ${cargo_generated_include_dir})
set_target_properties(zenohc_shared PROPERTIES IMPORTED_GLOBAL TRUE)
else()
add_library(zenohc_static STATIC IMPORTED GLOBAL)
add_library(zenohc::lib ALIAS zenohc_static)
add_library(zenohc::static ALIAS zenohc_static)
add_dependencies(zenohc_static cargo)
get_required_static_libs(NATIVE_STATIC_LIBS)
target_link_libraries(zenohc_static INTERFACE ${NATIVE_STATIC_LIBS})
set_target_imported_locations(zenohc_static ${staticlibr} ${staticlibd})
target_include_directories(zenohc_static INTERFACE ${cargo_generated_include_dir})
set_target_properties(zenohc_static PROPERTIES IMPORTED_GLOBAL TRUE)
endif()


Expand Down
5 changes: 5 additions & 0 deletions TC-armv7-unknown-linux-gnueabihf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7)
set(ZENOHC_CUSTOM_TARGET armv7-unknown-linux-gnueabihf)
set(CMAKE_C_COMPILER armv7-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER armv7-linux-gnueabihf-g++)
5 changes: 5 additions & 0 deletions TC-x86_64-pc-windows-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(ZENOHC_CUSTOM_TARGET x86_64-pc-windows-gnu)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER_TARGET x86_64-w64-mingw32-g++)
5 changes: 5 additions & 0 deletions TC-x86_64-unknown-linux-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(ZENOHC_CUSTOM_TARGET x86_64-unknown-linux-gnu)
set(CMAKE_C_COMPILER x86_64-unknown-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER x86_64-unknown-linux-gnu-g++)
5 changes: 0 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ foreach(file ${files})
endif()
endif()

# FIXME: remove once zenoh time primitives are available and examples updated
if(NOT(UNIX) AND(${target} STREQUAL "z_ping" OR ${target} STREQUAL "z_pong" OR ${target} STREQUAL "z_sub_thr"))
continue()
endif()

add_executable(${target} EXCLUDE_FROM_ALL ${file})
add_dependencies(examples ${target})

Expand Down
63 changes: 32 additions & 31 deletions install/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,37 @@ include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

function(install_zenohc_lib configurations property_postfix package_name)
if (BUILD_SHARED_LIBS)
get_target_property(dylib_path zenohc::lib IMPORTED_LOCATION_${property_postfix})
get_target_property_if_set(implib_path zenohc::lib IMPORTED_IMPLIB_${property_postfix})
get_filename_component(DYLIB ${dylib_path} NAME)
get_filename_component(IMPLIB "${implib_path}" NAME)
# 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} COMPONENT lib)
if(DEFINED implib_path)
install(FILES ${implib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations} COMPONENT lib)
endif()
if((APPLE OR UNIX))
get_filename_component(LIBNAME ${DYLIB} NAME_WE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zenohc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${package_name}_${property_postfix}.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${package_name}_${property_postfix}.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CONFIGURATIONS ${configurations}
RENAME ${package_name}.pc
OPTIONAL
COMPONENT dev)
endif()
get_target_property(dylib_path zenohc::shared IMPORTED_LOCATION_${property_postfix})
get_target_property_if_set(implib_path zenohc::shared IMPORTED_IMPLIB_${property_postfix})
get_filename_component(DYLIB ${dylib_path} NAME)
get_filename_component(IMPLIB "${implib_path}" NAME)
# 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()
get_target_property(staticlib_path zenohc::static IMPORTED_LOCATION_${property_postfix})
get_target_property(NATIVE_STATIC_LIBS zenohc::static INTERFACE_LINK_LIBRARIES)
get_filename_component(STATICLIB ${staticlib_path} NAME)
install(FILES ${staticlib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations} COMPONENT lib)
set(ZENOHC_INSTALL_DYLIBDIR ${CMAKE_INSTALL_LIBDIR})
endif()
install(FILES ${dylib_path} DESTINATION ${ZENOHC_INSTALL_DYLIBDIR} CONFIGURATIONS ${configurations} COMPONENT lib)
if(DEFINED implib_path)
install(FILES ${implib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations} COMPONENT lib)
endif()
if((APPLE OR UNIX))
get_filename_component(LIBNAME ${DYLIB} NAME_WE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zenohc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${package_name}_${property_postfix}.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${package_name}_${property_postfix}.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CONFIGURATIONS ${configurations}
RENAME ${package_name}.pc
OPTIONAL
COMPONENT dev)
endif()

get_target_property(staticlib_path zenohc::static IMPORTED_LOCATION_${property_postfix})
get_target_property(NATIVE_STATIC_LIBS zenohc::static INTERFACE_LINK_LIBRARIES)
get_filename_component(STATICLIB ${staticlib_path} NAME)
install(FILES ${staticlib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR} CONFIGURATIONS ${configurations} COMPONENT lib)

set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${package_name}")

# Generate <Package>Config.cmake
Expand Down Expand Up @@ -92,6 +90,7 @@ install_zenohc_lib("Debug" "DEBUG" zenohc)
#
# Configure CPack
#
set(CPACK_BUILD_CONFIG ${CMAKE_BUILD_TYPE})
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages")
set(CPACK_PACKAGE_CHECKSUM MD5)
set(CPACK_PACKAGE_VENDOR "The Eclipse Foundation")
Expand Down Expand Up @@ -123,7 +122,9 @@ if(NOT CPACK_PACKAGE_VERSION)
endif()
endif()

set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")

set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cpack_project_config.cmake")

include(CPack)
53 changes: 29 additions & 24 deletions install/PackageConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,35 @@ if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()

if (@BUILD_SHARED_LIBS@)
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@"
)
add_library(zenohc::lib ALIAS __zenohc_shared)
if(NOT ("@IMPLIB@" STREQUAL ""))
set_property(TARGET __zenohc_shared PROPERTY IMPORTED_IMPLIB "${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@/@IMPLIB@")
endif()

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@"
)
if(NOT ("@IMPLIB@" STREQUAL ""))
set_property(TARGET __zenohc_shared PROPERTY IMPORTED_IMPLIB "${_IMPORT_PREFIX}/@CMAKE_INSTALL_LIBDIR@/@IMPLIB@")
endif()
endif()
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()

if(@BUILD_SHARED_LIBS@)
add_library(zenohc::lib ALIAS __zenohc_shared)
else()
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@"
)
add_library(zenohc::lib ALIAS __zenohc_static)
endif()
add_library(zenohc::lib ALIAS __zenohc_static)
endif()


endif()
8 changes: 0 additions & 8 deletions install/cpack_project_config.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
if(CPACK_GENERATOR MATCHES "DEB")
# DEB package
if(NOT DEBARCH)
execute_process(
COMMAND dpkg --print-architecture
OUTPUT_VARIABLE DEBARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
message(STATUS "Configure DEB packaging for Linux ${DEBARCH}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ZettaScale Zenoh Team, <zenoh@zettascale.tech>")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEBARCH})
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_LIB_PACKAGE_NAME lib${CPACK_PACKAGE_NAME})
Expand Down

0 comments on commit a13f7ac

Please sign in to comment.