From 13092e1946d503f3d643f7f0b70b33212150b121 Mon Sep 17 00:00:00 2001 From: Mikhail Sedov Date: Mon, 21 Oct 2024 20:40:42 +0200 Subject: [PATCH] Create binary artifacts with cpack in CI --- .github/workflows/cmake-multi-platform.yml | 34 +++++++ CMakeLists.txt | 22 +++- asam_cmp_capture_module/src/CMakeLists.txt | 28 ++---- asam_cmp_data_sink/src/CMakeLists.txt | 112 +++++++++------------ 4 files changed, 109 insertions(+), 87 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index dae22fb..ab711b7 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -7,6 +7,9 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] + +env: + package_path: ${{ github.workspace }}/build/package/ jobs: build_linux: @@ -25,9 +28,11 @@ jobs: - os: ubuntu-latest c_compiler: gcc cpp_compiler: g++ + cpack: tgz - os: ubuntu-latest c_compiler: clang cpp_compiler: clang++ + cpack: tgz steps: - name: Install basic dependencies @@ -60,6 +65,7 @@ jobs: -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DCPACK_GENERATOR=${{ matrix.cpack }} -S ${{ github.workspace }} - name: Build @@ -79,6 +85,19 @@ jobs: name: Test Results ${{ matrix.os }}-${{ matrix.c_compiler }} path: ${{ steps.strings.outputs.build-output-dir }}/Testing/Temporary/LastTest.log retention-days: 7 + + - name: Package + if: always() + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: cpack -C ${{ matrix.build_type }} + + - name: Upload binaries + if: always() + uses: actions/upload-artifact@v4 + with: + name: asam-cmp-${{ matrix.os }}-${{ matrix.c_compiler }} + path: ${{ env.package_path }} + retention-days: 7 build_windows: runs-on: ${{ matrix.os }} @@ -96,6 +115,7 @@ jobs: - os: windows-latest c_compiler: cl cpp_compiler: cl + cpack: zip steps: - uses: actions/checkout@v4 @@ -123,6 +143,7 @@ jobs: -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DCPACK_GENERATOR=${{ matrix.cpack }} -S ${{ github.workspace }} - name: Build @@ -141,4 +162,17 @@ jobs: with: name: Test Results ${{ matrix.os }}-${{ matrix.c_compiler }} path: ${{ steps.strings.outputs.build-output-dir }}/Testing/Temporary/LastTest.log + retention-days: 7 + + - name: Package + if: always() + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: cpack -C ${{ matrix.build_type }} + + - name: Upload binaries + if: always() + uses: actions/upload-artifact@v4 + with: + name: asam-cmp-${{ matrix.os }}-${{ matrix.c_compiler }} + path: ${{ env.package_path }} retention-days: 7 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 92a8ad7..63c4abf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,4 +37,24 @@ endif() if (${REPO_OPTION_PREFIX}_BUILD_DATA_SINK) add_subdirectory(asam_cmp_data_sink) -endif() \ No newline at end of file +endif() + +# Set CPack variables +set(CPACK_COMPONENTS_ALL RUNTIME) +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/package") + +# Set the CPack generator based on the platform +if (WIN32) + set(CPACK_GENERATOR "ZIP") +elseif (UNIX AND NOT APPLE) + cmake_host_system_information(RESULT DISTRO_ID QUERY DISTRIB_ID) + cmake_host_system_information(RESULT DISTRO_VERSION_ID QUERY DISTRIB_VERSION_ID) + set(CPACK_SYSTEM_NAME "${DISTRO_ID}${DISTRO_VERSION_ID}") + set(CPACK_GENERATOR "TGZ") +endif() + +# Include CPack for packaging +include(CPack) \ No newline at end of file diff --git a/asam_cmp_capture_module/src/CMakeLists.txt b/asam_cmp_capture_module/src/CMakeLists.txt index 9f8f750..a4552b7 100644 --- a/asam_cmp_capture_module/src/CMakeLists.txt +++ b/asam_cmp_capture_module/src/CMakeLists.txt @@ -52,16 +52,11 @@ target_include_directories(${LIB_NAME} PUBLIC $ ) -set_target_properties(${LIB_NAME} PROPERTIES PUBLIC_HEADER "${SRC_PublicHeaders}") - opendaq_set_module_properties(${LIB_NAME} ${PROJECT_VERSION_MAJOR}) create_version_header(${LIB_NAME}) install(TARGETS ${LIB_NAME} - RUNTIME DESTINATION ${INSTALL_BIN_DIR} - LIBRARY DESTINATION ${INSTALL_LIB_DIR} - ARCHIVE DESTINATION ${INSTALL_LIB_DIR} - PUBLIC_HEADER DESTINATION include/${TARGET_FOLDER_NAME} + COMPONENT RUNTIME ) if (${REPO_OPTION_PREFIX}_ENABLE_TESTS) @@ -98,23 +93,14 @@ if (${REPO_OPTION_PREFIX}_ENABLE_TESTS) ) target_link_libraries(${PROJECT_NAME}_lib PUBLIC daq::opendaq - Pcap++ - asam_cmp - asam_cmp_common_lib + Pcap++ + asam_cmp + asam_cmp_common_lib ) target_include_directories(${PROJECT_NAME}_lib PUBLIC $ - $ - $ + $ + $ ) - set_target_properties(${PROJECT_NAME}_lib PROPERTIES PUBLIC_HEADER "${SRC_PublicHeaders}") - - install(TARGETS ${PROJECT_NAME}_lib - RUNTIME DESTINATION ${INSTALL_BIN_DIR} - LIBRARY DESTINATION ${INSTALL_LIB_DIR} - ARCHIVE DESTINATION ${INSTALL_LIB_DIR} - PUBLIC_HEADER DESTINATION include/${TARGET_FOLDER_NAME} - ) - -endif() \ No newline at end of file +endif() diff --git a/asam_cmp_data_sink/src/CMakeLists.txt b/asam_cmp_data_sink/src/CMakeLists.txt index e2911ae..6ac7d6c 100644 --- a/asam_cmp_data_sink/src/CMakeLists.txt +++ b/asam_cmp_data_sink/src/CMakeLists.txt @@ -29,6 +29,10 @@ set(SRC_PublicHeaders module_dll.h set(SRC_PrivateHeaders ) +if (MSVC) + add_compile_options(/bigobj) +endif() + prepend_include(${TARGET_FOLDER_NAME} SRC_PrivateHeaders) prepend_include(${TARGET_FOLDER_NAME} SRC_PublicHeaders) @@ -49,78 +53,56 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ ) -set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${SRC_PublicHeaders}") - opendaq_set_module_properties(${PROJECT_NAME} ${PROJECT_VERSION_MAJOR}) create_version_header(${PROJECT_NAME}) install(TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION ${INSTALL_BIN_DIR} - LIBRARY DESTINATION ${INSTALL_LIB_DIR} - ARCHIVE DESTINATION ${INSTALL_LIB_DIR} - PUBLIC_HEADER DESTINATION include/${TARGET_FOLDER_NAME} + COMPONENT RUNTIME ) -if (MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE /bigobj) -endif() - if (${REPO_OPTION_PREFIX}_ENABLE_TESTS) -set(SRC_Lib_Cpp data_sink_module.cpp - data_sink_module_fb.cpp - status_fb_impl.cpp - data_sink_fb.cpp - capture_fb.cpp - interface_fb.cpp - stream_fb.cpp -) - -set(SRC_Lib_PublicHeaders common.h - data_sink_module.h - data_sink_module_fb.h - status_fb_impl.h - status_handler.h - data_sink_fb.h - capture_fb.h - interface_fb.h - stream_fb.h -) - -set(SRC_Lib_PrivateHeaders -) - -prepend_include(${TARGET_FOLDER_NAME} SRC_Lib_PrivateHeaders) -prepend_include(${TARGET_FOLDER_NAME} SRC_Lib_PublicHeaders) - -add_library(${PROJECT_NAME}_lib STATIC - ${SRC_Lib_Cpp} - ${SRC_Lib_PublicHeaders} - ${SRC_Lib_PrivateHeaders} -) - -target_link_libraries(${PROJECT_NAME}_lib PUBLIC daq::opendaq - Pcap++ - asam_cmp - asam_cmp_common_lib -) - -target_include_directories(${PROJECT_NAME}_lib PUBLIC $ - $ - $ -) - -set_target_properties(${PROJECT_NAME}_lib PROPERTIES PUBLIC_HEADER "${SRC_PublicHeaders}") - -install(TARGETS ${PROJECT_NAME}_lib - RUNTIME DESTINATION ${INSTALL_BIN_DIR} - LIBRARY DESTINATION ${INSTALL_LIB_DIR} - ARCHIVE DESTINATION ${INSTALL_LIB_DIR} - PUBLIC_HEADER DESTINATION include/${TARGET_FOLDER_NAME} -) - -if (MSVC) - target_compile_options(${PROJECT_NAME}_lib PRIVATE /bigobj) -endif() + set(SRC_Lib_Cpp data_sink_module.cpp + data_sink_module_fb.cpp + status_fb_impl.cpp + data_sink_fb.cpp + capture_fb.cpp + interface_fb.cpp + stream_fb.cpp + ) + + set(SRC_Lib_PublicHeaders common.h + data_sink_module.h + data_sink_module_fb.h + status_fb_impl.h + status_handler.h + data_sink_fb.h + capture_fb.h + interface_fb.h + stream_fb.h + ) + + set(SRC_Lib_PrivateHeaders + ) + + prepend_include(${TARGET_FOLDER_NAME} SRC_Lib_PrivateHeaders) + prepend_include(${TARGET_FOLDER_NAME} SRC_Lib_PublicHeaders) + + add_library(${PROJECT_NAME}_lib STATIC + ${SRC_Lib_Cpp} + ${SRC_Lib_PublicHeaders} + ${SRC_Lib_PrivateHeaders} + ) + + target_link_libraries(${PROJECT_NAME}_lib PUBLIC daq::opendaq + Pcap++ + asam_cmp + asam_cmp_common_lib + ) + + target_include_directories(${PROJECT_NAME}_lib PUBLIC $ + $ + $ + ) endif()