From fad8ffe6b8435029ebf6ffa2c3fbee3c39ace98c Mon Sep 17 00:00:00 2001 From: Valery Date: Tue, 14 Nov 2023 23:14:37 +0300 Subject: [PATCH] setup workflow --- .github/workflows/cmake-multi-platform.yml | 71 ++++++++++++++++++++++ CMakeLists.txt | 18 ++---- README.md | 1 + Tests/CMakeLists.txt | 19 +++--- array_core/CMakeLists.txt | 3 + common_utils/common_utils.cpp | 2 +- 6 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/cmake-multi-platform.yml diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml new file mode 100644 index 0000000..448314a --- /dev/null +++ b/.github/workflows/cmake-multi-platform.yml @@ -0,0 +1,71 @@ +# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml +name: Linux-Windows + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. + #Consider changing this to true when your workflow is stable. + fail-fast: false + + + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release] + c_compiler: [gcc, clang, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v3 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 0edfc58..6b1159a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,8 @@ project(${projectName} VERSION 0.01 LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) - if(WIN32) -set(CMAKE_EXE_LINKER_FLAGS " -static") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") endif(WIN32) add_subdirectory("ResourceManager") @@ -24,18 +23,9 @@ rm_embed_resources(RESOURCES "plotly_maker/plotly-2.27.0.min.js") add_executable(${projectName} main.cpp cxxopts.hpp ${RESOURCES}) -if(WIN32) -target_link_libraries(${projectName} - PRIVATE PlotlyMaker - -static-libgcc - -static-libstdc++ - PRIVATE CommonUtils) -endif(WIN32) -if(UNIX) -target_link_libraries(${projectName} - PRIVATE PlotlyMaker - PRIVATE CommonUtils) -endif(UNIX) +target_link_libraries(${projectName} "ArrayCore") + + diff --git a/README.md b/README.md index eabd9c7..c5df8db 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +![Workflow](https://github.com/github/docs/actions/workflows/cmake-multi-platform.yml/badge.svg?branch=main) # devtools DAVIS is utility for data visualization The visualization is based on Plotly javascript https://plotly.com/ diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 85e0ae7..508f191 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1,4 +1,5 @@ include(FetchContent) +include(CMakePrintHelpers) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git @@ -7,6 +8,15 @@ FetchContent_Declare( FetchContent_MakeAvailable(googletest) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Windows specific, for googletest +# Copy plotly java script to tests +MESSAGE("_____________________ Copy Plotlylib to Tests step ___________________________________________") +if(WIN32) +file(COPY ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.27.0.min.js DESTINATION + ${CMAKE_CURRENT_BINARY_DIR}/Debug/davis_htmls) +file(COPY ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.27.0.min.js DESTINATION + ${CMAKE_CURRENT_BINARY_DIR}/Release/davis_htmls) +endif(WIN32) + add_executable(${PROJECT_NAME}_plotly_tests PlotlyLibTest.cpp) target_link_libraries(${PROJECT_NAME}_plotly_tests PRIVATE gtest_main) target_link_libraries(${PROJECT_NAME}_plotly_tests PRIVATE ArrayCore) @@ -15,15 +25,8 @@ add_executable(${PROJECT_NAME}_core_tests ArrayCoreTest.cpp) target_link_libraries(${PROJECT_NAME}_core_tests PRIVATE gtest_main) target_link_libraries(${PROJECT_NAME}_core_tests PRIVATE ArrayCore) - include_directories(${CMAKE_SOURCE_DIR}) include(GoogleTest) gtest_discover_tests(${PROJECT_NAME}_plotly_tests _core_tests) -# Copy plotly java script to tests -add_custom_command( - TARGET ${PROJECT_NAME}_core_tests PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.27.0.min.js - ${CMAKE_CURRENT_BINARY_DIR}/davis_htmls/plotly-2.27.0.min.js - ) + diff --git a/array_core/CMakeLists.txt b/array_core/CMakeLists.txt index 43a39b7..279f250 100644 --- a/array_core/CMakeLists.txt +++ b/array_core/CMakeLists.txt @@ -3,6 +3,9 @@ project(${projectName} VERSION 0.01 LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) +if(WIN32) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") +endif(WIN32) set(SOURCE_FILES "../common_utils/common_utils.cpp" "../common_utils/common_constants.cpp" diff --git a/common_utils/common_utils.cpp b/common_utils/common_utils.cpp index c47072a..3bb7285 100644 --- a/common_utils/common_utils.cpp +++ b/common_utils/common_utils.cpp @@ -82,7 +82,7 @@ void mayBeCreateJsWorkingFolder() { struct stat sb; if (stat(kOutFolderName, &sb) != 0) { #ifdef _WIN32 - mkdir(kOutFolderName); + _mkdir(kOutFolderName); #elif __linux__ mode_t mode = 0755; mkdir(kOutFolderName, mode);