Skip to content

Commit

Permalink
Fixed Windows library extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
bialger committed Feb 13, 2024
1 parent dbd988e commit 0727270
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ jobs:
shell: bash
run: |
if [ "${{ matrix.config.cxx }}" == "g++" ]; then
cmake -S . -B cmake-build-release -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"
cmake -S . -B cmake-build-debug -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles"
cmake -S . -B cmake-build-release -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Release -DGITHUB_ACTIONS=True -G "Unix Makefiles"
cmake -S . -B cmake-build-debug -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Debug -DGITHUB_ACTIONS=True -G "Unix Makefiles"
else
cmake -S . -B cmake-build-release -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Release
cmake -S . -B cmake-build-debug -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Debug
cmake -S . -B cmake-build-release -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Release -DGITHUB_ACTIONS=True
cmake -S . -B cmake-build-debug -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Debug -DGITHUB_ACTIONS=True
fi
- name: Build main target
Expand Down
121 changes: 121 additions & 0 deletions .github/workflows/ci_tests.yml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: "CI tests"

on: [ push ]

jobs:
build:
name: Tests and application run on ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {
name: "Windows Latest MSVC", artifact: "Windows-MSVC.tar.xz",
os: windows-latest,
build_type: "Release", cc: "cl", cxx: "cl",
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
}
- {
name: "Windows Latest MinGW", artifact: "Windows-MinGW.tar.xz",
os: windows-latest,
build_type: "Release", cc: "gcc", cxx: "g++"
}
- {
name: "Ubuntu Latest GCC", artifact: "Linux.tar.xz",
os: ubuntu-latest,
build_type: "Release", cc: "gcc", cxx: "g++"
}
- {
name: "macOS Latest Clang", artifact: "macOS.tar.xz",
os: macos-latest,
build_type: "Release", cc: "clang", cxx: "clang++"
}

steps:
- uses: actions/checkout@v3

- name: Configure
shell: cmake -P {0}
run: |
set(ENV{CC} ${{ matrix.config.cc }})
set(ENV{CXX} ${{ matrix.config.cxx }})

if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
execute_process(
COMMAND "${{ matrix.config.environment_script }}" && set
OUTPUT_FILE environment_script_output.txt
)
file(STRINGS environment_script_output.txt output_lines)
foreach(line IN LISTS output_lines)
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
endif()
endforeach()
endif()

- name: Create CMake cache
shell: bash
run: |
if [ "${{ matrix.config.cxx }}" == "g++" ]; then
cmake -S . -B cmake-build-release -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"
cmake -S . -B cmake-build-debug -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles"
else
cmake -S . -B cmake-build-release -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Release
cmake -S . -B cmake-build-debug -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_BUILD_TYPE=Debug
fi

- name: Build main target
run: |
cmake --build cmake-build-release --target cpp_tests

- name: Build tests target
run: |
cmake --build cmake-build-debug --target cpp_tests_tests

- name: Run program
shell: bash
working-directory: ./cmake-build-release
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
cd Debug
./cpp_tests.exe --help
else
cd bin
./cpp_tests --help
fi

- name: Run tests
shell: bash
working-directory: ./cmake-build-debug
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
cd Debug
./cpp_tests_tests.exe
else
cd tests
./cpp_tests_tests
fi

memory-leaks:
name: Find memory leaks in tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install valgrind
run: |
sudo apt-get update && sudo apt-get -y install valgrind

- name: Create CMake cache
run: |
cmake -S . -B cmake-build -DCMAKE_BUILD_TYPE=Debug

- name: Build tests target
run: |
cmake --build cmake-build --target cpp_tests_tests

- name: Run valgrind
working-directory: ./cmake-build/tests
run: |
valgrind --leak-check=full --track-origins=yes --error-exitcode=1 ./cpp_tests_tests
16 changes: 12 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ target_link_libraries(
GTest::gtest_main
)

set(MSVC_LIBRARY_EXTENSION lib)
set(MINGW_LIBRARY_EXTENSION a)

if (NOT GITHUB_ACTIONS)
set(MSVC_LIBRARY_EXTENSION dll)
set(MINGW_LIBRARY_EXTENSION dll)
endif ()

if(WIN32)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_custom_command(TARGET ${PROJECT_NAME}_tests POST_BUILD
COMMAND "cp" ARGS "${CMAKE_BINARY_DIR}/bin/Debug/gtest.dll" "${CMAKE_BINARY_DIR}/Debug/gtest.dll"
COMMAND "cp" ARGS "${CMAKE_BINARY_DIR}/bin/Debug/gtest_main.dll" "${CMAKE_BINARY_DIR}/Debug/gtest_main.dll"
COMMAND "cp" ARGS "${CMAKE_BINARY_DIR}/bin/Debug/gtest.${MSVC_LIBRARY_EXTENSION}" "${CMAKE_BINARY_DIR}/Debug/gtest.${MSVC_LIBRARY_EXTENSION}"
COMMAND "cp" ARGS "${CMAKE_BINARY_DIR}/bin/Debug/gtest_main.${MSVC_LIBRARY_EXTENSION}" "${CMAKE_BINARY_DIR}/Debug/gtest_main.${MSVC_LIBRARY_EXTENSION}"
COMMENT "Copying to output directory")
else ()
add_custom_command(TARGET ${PROJECT_NAME}_tests POST_BUILD
COMMAND "cp" ARGS "${CMAKE_BINARY_DIR}/bin/libgtest.dll" "${CMAKE_BINARY_DIR}/libgtest.dll"
COMMAND "cp" ARGS "${CMAKE_BINARY_DIR}/bin/libgtest_main.dll" "${CMAKE_BINARY_DIR}/libgtest_main.dll"
COMMAND "cp" ARGS "${CMAKE_BINARY_DIR}/bin/libgtest.${MINGW_LIBRARY_EXTENSION}" "${CMAKE_BINARY_DIR}/libgtest.${MINGW_LIBRARY_EXTENSION}"
COMMAND "cp" ARGS "${CMAKE_BINARY_DIR}/bin/libgtest_main.${MINGW_LIBRARY_EXTENSION}" "${CMAKE_BINARY_DIR}/libgtest_main.${MINGW_LIBRARY_EXTENSION}"
COMMENT "Copying to output directory")
endif()
endif()
Expand Down

0 comments on commit 0727270

Please sign in to comment.