From 0b97c60ddea3beca93dff5c77702fca5eaed6f18 Mon Sep 17 00:00:00 2001 From: DenisBiryukov91 <155981813+DenisBiryukov91@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:30:23 +0200 Subject: [PATCH] Add cross-compile tests to ci and fix library names (#790) * add sample toolchains and fix library names * add cross-compilation to ci * update linkers in config.toml * add cross-compilation test for linux --- .cargo/config.toml | 20 ++++ .github/workflows/ci.yml | 108 ++++++++++++++++++ CMakeLists.txt | 80 ++++++++----- .../TC-aarch64-unknown-linux-gnu.cmake | 5 + .../TC-aarch64-unknown-linux-musl.cmake | 5 + .../TC-arm-unknown-linux-gnueabi.cmake | 5 + .../TC-armv7-unknown-linux-gnueabihf.cmake | 5 + ci/toolchains/TC-x86_64-pc-windows-gnu.cmake | 5 + .../TC-x86_64-unknown-linux-gnu.cmake | 5 + .../TC-x86_64-unknown-linux-musl.cmake | 5 + cmake/cross_build_check.cmake | 34 ------ examples/CMakeLists.txt | 5 - install/CMakeLists.txt | 63 +++++----- install/PackageConfig.cmake.in | 50 ++++---- install/cpack_project_config.cmake | 8 -- 15 files changed, 271 insertions(+), 132 deletions(-) create mode 100644 ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake create mode 100644 ci/toolchains/TC-aarch64-unknown-linux-musl.cmake create mode 100644 ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake create mode 100644 ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake create mode 100644 ci/toolchains/TC-x86_64-pc-windows-gnu.cmake create mode 100644 ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake create mode 100644 ci/toolchains/TC-x86_64-unknown-linux-musl.cmake delete mode 100644 cmake/cross_build_check.cmake diff --git a/.cargo/config.toml b/.cargo/config.toml index 5adae5e04..829125ef6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,25 @@ [target.x86_64-unknown-linux-musl] rustflags = "-Ctarget-feature=-crt-static" +linker = "x86_64-linux-musl-gcc" [target.aarch64-unknown-linux-musl] rustflags = "-Ctarget-feature=-crt-static" +linker = "aarch64-linux-musl-gcc" + +[target.arm-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" + +[target.arm-unknown-linux-gnueabi] +linker = "arm-linux-gnueabi-gcc" + +[target.armv7-unknown-linux-gnueabihf] +linker = "armv7-linux-gnueabihf-gcc" + +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" + +[target.x86_64-unknown-linux-gnu] +linker = "x86_64-linux-gnu-gcc" + +[target.x86_64-pc-windows-gnu] +linker = "x86_64-w64-mingw32-gcc" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c06294a9..336498474 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,6 +121,114 @@ jobs: !target/release/.* !target/release/*.d + cross-compile-mac-os: + name: Cross compile on macOS-latest + runs-on: macOS-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: | + brew tap messense/macos-cross-toolchains + brew install armv7-unknown-linux-gnueabihf + brew install mingw-w64 + brew install x86_64-unknown-linux-gnu + + - name: Install rust toolchains + run: | + rustup target add armv7-unknown-linux-gnueabihf + rustup target add x86_64-pc-windows-gnu + rustup target add x86_64-unknown-linux-gnu + + - name: Cross compile for armv7-unknown-linux-gnueabihf + run: | + rm -rf ./build + mkdir -p ./build && cd ./build + cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON .. + cmake --build . --target examples + + - name: Cross compile for x86_64-unknown-linux-gnu + run: | + rm -rf ./build + mkdir -p ./build && cd ./build + cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON .. + cmake --build . --target examples + + - name: Cross compile for x86_64-pc-windows-gnu + run: | + rm -rf ./build + mkdir -p ./build && cd ./build + cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-x86_64-pc-windows-gnu.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON .. + cmake --build . --target examples + + cross-compile-ubuntu: + name: Cross compile on ubuntu-latest + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt-get install -y musl-tools + sudo apt-get install -y gcc-arm-linux-gnueabi + sudo apt-get install -y g++-arm-linux-gnueabi + sudo apt-get install -y mingw-w64 + sudo apt-get install -y gcc-aarch64-linux-gnu + sudo apt-get install -y g++-aarch64-linux-gnu + wget https://musl.cc/aarch64-linux-musl-cross.tgz + tar xvfz aarch64-linux-musl-cross.tgz + echo "$(readlink -f aarch64-linux-musl-cross)/bin" >> "$GITHUB_PATH" + wget https://musl.cc/x86_64-linux-musl-cross.tgz + tar xvfz x86_64-linux-musl-cross.tgz + echo "$(readlink -f x86_64-linux-musl-cross)/bin" >> "$GITHUB_PATH" + + - name: Install rust toolchains + run: | + rustup target add arm-unknown-linux-gnueabi + rustup target add x86_64-pc-windows-gnu + rustup target add aarch64-unknown-linux-gnu + rustup target add aarch64-unknown-linux-musl + rustup target add x86_64-unknown-linux-musl + + - name: Cross compile for arm-unknown-linux-gnueabi + run: | + rm -rf ./build + mkdir -p ./build && cd ./build + cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON .. + cmake --build . --target examples + + - name: Cross compile for aarch64-unknown-linux-gnu + run: | + rm -rf ./build + mkdir -p ./build && cd ./build + cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON .. + cmake --build . --target examples + + - name: Cross compile for aarch64-unknown-linux-musl + run: | + rm -rf ./build + mkdir -p ./build && cd ./build + cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-aarch64-unknown-linux-musl.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON .. + cmake --build . --target examples + + - name: Cross compile for x86_64-unknown-linux-musl + run: | + rm -rf ./build + mkdir -p ./build && cd ./build + cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-x86_64-unknown-linux-musl.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON .. + cmake --build . --target examples + + - name: Cross compile for x86_64-pc-windows-gnu + run: | + rm -rf ./build + mkdir -p ./build && cd ./build + cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-x86_64-pc-windows-gnu.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON .. + cmake --build . --target examples + # NOTE: In GitHub repository settings, the "Require status checks to pass # before merging" branch protection rule ensures that commits are only merged # from branches where specific status checks have passed. These checks are diff --git a/CMakeLists.txt b/CMakeLists.txt index 592e291e9..6a125d71e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) @@ -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() @@ -294,7 +315,6 @@ endif() # Components included only if project is the root project # if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) - include(cmake/cross_build_check.cmake) add_subdirectory(install) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${cargo_binary_dir}/tests) add_subdirectory(tests) diff --git a/ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake b/ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake new file mode 100644 index 000000000..8f1a6b36c --- /dev/null +++ b/ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake @@ -0,0 +1,5 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) +set(ZENOHC_CUSTOM_TARGET aarch64-unknown-linux-gnu) +set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) diff --git a/ci/toolchains/TC-aarch64-unknown-linux-musl.cmake b/ci/toolchains/TC-aarch64-unknown-linux-musl.cmake new file mode 100644 index 000000000..0793da1ab --- /dev/null +++ b/ci/toolchains/TC-aarch64-unknown-linux-musl.cmake @@ -0,0 +1,5 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) +set(ZENOHC_CUSTOM_TARGET aarch64-unknown-linux-musl) +set(CMAKE_C_COMPILER aarch64-linux-musl-gcc) +set(CMAKE_CXX_COMPILER aarch64-linux-musl-g++) diff --git a/ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake b/ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake new file mode 100644 index 000000000..8b340ce22 --- /dev/null +++ b/ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake @@ -0,0 +1,5 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(ZENOHC_CUSTOM_TARGET arm-unknown-linux-gnueabi) +set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc) +set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++) diff --git a/ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake b/ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake new file mode 100644 index 000000000..83362af52 --- /dev/null +++ b/ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake @@ -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++) diff --git a/ci/toolchains/TC-x86_64-pc-windows-gnu.cmake b/ci/toolchains/TC-x86_64-pc-windows-gnu.cmake new file mode 100644 index 000000000..9be83069d --- /dev/null +++ b/ci/toolchains/TC-x86_64-pc-windows-gnu.cmake @@ -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 x86_64-w64-mingw32-g++) diff --git a/ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake b/ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake new file mode 100644 index 000000000..ce56df0f3 --- /dev/null +++ b/ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake @@ -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++) diff --git a/ci/toolchains/TC-x86_64-unknown-linux-musl.cmake b/ci/toolchains/TC-x86_64-unknown-linux-musl.cmake new file mode 100644 index 000000000..f4904a4ae --- /dev/null +++ b/ci/toolchains/TC-x86_64-unknown-linux-musl.cmake @@ -0,0 +1,5 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR x86_64) +set(ZENOHC_CUSTOM_TARGET x86_64-unknown-linux-musl) +set(CMAKE_C_COMPILER x86_64-linux-musl-gcc) +set(CMAKE_CXX_COMPILER x86_64-linux-musl-g++) diff --git a/cmake/cross_build_check.cmake b/cmake/cross_build_check.cmake deleted file mode 100644 index 49b5a67d1..000000000 --- a/cmake/cross_build_check.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# -# Rust cross-build check for supported processor architectures -# This check works on linux only -# It requires that the following packages are installed for cross compilation: -# -# sudo apt install gcc-arm-linux-gnueabi -# sudo apt install gcc-x86-64-linux-gnu -# sudo apt install gcc-aarch64-linux-gnu -# -# and the following targets in rustup -# -# rustup target add arm-unknown-linux-gnueabi -# rustup target add aarch64-unknown-linux-gnu -# rustup target add x86_64-unknown-linux-gnu -# -# check which targets are already installed with -# -# rustup target list --installed -# -add_custom_target(crosscheck) - -set(targets -aarch64-unknown-linux-gnu -x86_64-unknown-linux-gnu -arm-unknown-linux-gnueabi -) - -foreach(target ${targets}) - add_custom_target(cargo_check_${target} - COMMAND cargo check --target ${target} ${cargo_flags} - COMMENT "cargo check on ${target}" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - add_dependencies(crosscheck cargo_check_${target}) -endforeach() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 42306a4d1..3674203fc 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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}) diff --git a/install/CMakeLists.txt b/install/CMakeLists.txt index 3b9e64d98..7278eb1db 100644 --- a/install/CMakeLists.txt +++ b/install/CMakeLists.txt @@ -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 Config.cmake @@ -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") @@ -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) diff --git a/install/PackageConfig.cmake.in b/install/PackageConfig.cmake.in index d44094f8a..1327236f4 100644 --- a/install/PackageConfig.cmake.in +++ b/install/PackageConfig.cmake.in @@ -25,30 +25,32 @@ 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() diff --git a/install/cpack_project_config.cmake b/install/cpack_project_config.cmake index f6425b117..51c220aab 100644 --- a/install/cpack_project_config.cmake +++ b/install/cpack_project_config.cmake @@ -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, ") - 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})