From 886131c6761944f35908aeefb5dd6eed7e4c0290 Mon Sep 17 00:00:00 2001 From: 5tan <5tan@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:11:39 +0200 Subject: [PATCH] Added windows CI --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++---- CMakeLists.txt | 2 +- examples/CMakeLists.txt | 10 +++---- examples/callbacks/CMakeLists.txt | 20 +++++++++---- examples/player_async/CMakeLists.txt | 6 +++- examples/player_sync/CMakeLists.txt | 6 +++- examples/qtmidieditor/CMakeLists.txt | 6 +++- examples/qtmidiplayer/CMakeLists.txt | 6 +++- examples/sequencing/CMakeLists.txt | 8 ++++-- include/cxxmidi/guts/player_base.hpp | 3 +- include/cxxmidi/output/default.hpp | 2 +- include/cxxmidi/output/windows.hpp | 14 ++++----- tests/CMakeLists.txt | 39 ++++++++++++++++++++----- tests/file.cpp | 1 + 14 files changed, 126 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 161fbd2..357b5af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,8 @@ jobs: extra_check: - '' include: + - os: windows-latest + compiler: g++ - os: ubuntu-latest compiler: clazy extra_check: clazy @@ -48,16 +50,31 @@ jobs: steps: - uses: actions/checkout@v4 + # - name: Install Ninja (windows) + # if: matrix.os == 'windows-latest' + # uses: seanmiddleditch/gha-setup-ninja@master + - name: Install dependencies (linux) if: matrix.os == 'ubuntu-latest' - run: sudo apt-get -y install libgl1-mesa-dev qt6-base-dev libgtest-dev libasound2-dev + run: sudo apt-get -y install libgl1-mesa-dev qt6-base-dev libgtest-dev libasound2-dev ninja-build - name: Install dependencies (macos) if: matrix.os == 'macos-latest' - run: brew install googletest qt6 + run: brew install googletest qt6 ninja + + - name: Install Qt6 (windows) + if: matrix.os == 'windows-latest' + uses: jurplel/install-qt-action@v4 + with: + version: '6.6.0' + host: 'windows' + target: 'desktop' + arch: 'win64_mingw' + dir: '${{ github.workspace }}/build/qt6/' + # set-env: 'true' - name: Install clang (linux) - if: matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang++' run: sudo apt-get -y install clang - name: Install clang (macos) @@ -76,9 +93,23 @@ jobs: if: matrix.extra_check == 'iwyu' run: sudo apt-get install -y iwyu + - name: Set up Cygwin + if: matrix.os == 'windows-latest' + uses: egor-tensin/setup-cygwin@v4 + with: + packages: cmake gcc-g++ ninja + + - name: Configure CMake + run: cmake -Bbuild -G Ninja . -DCMAKE_CXX_COMPILER="${{ matrix.compiler }}" ${{matrix.extra_check_flag}} + - name: Build - run: (mkdir build && cd build && cmake .. -DCMAKE_CXX_COMPILER="${{ matrix.compiler }}" ${{matrix.extra_check_flag}} && make) + run: cmake --build build - name: Test - if: matrix.extra_check == '' - run: (cd build && ctest) \ No newline at end of file + if: matrix.extra_check == '' && matrix.os != 'windows-latest' + run: ctest --test-dir build + + - name: Test (windows) + if: matrix.os == 'windows-latest' + shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}' + run: ${{ github.workspace }}\build\tests\tests.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index b572325..beaef61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10.2) +cmake_minimum_required(VERSION 3.14) project(cxxmidi VERSION 0.2.0 LANGUAGES CXX) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 01dc01c..d3b800a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory(callbacks) -add_subdirectory(qtmidieditor) -add_subdirectory(qtmidiplayer) -add_subdirectory(player_async) -add_subdirectory(player_sync) -add_subdirectory(sequencing) +# add_subdirectory(qtmidieditor) +# add_subdirectory(qtmidiplayer) +# add_subdirectory(player_async) +# add_subdirectory(player_sync) +# add_subdirectory(sequencing) diff --git a/examples/callbacks/CMakeLists.txt b/examples/callbacks/CMakeLists.txt index c10cdcd..56e499f 100644 --- a/examples/callbacks/CMakeLists.txt +++ b/examples/callbacks/CMakeLists.txt @@ -1,3 +1,5 @@ +set(THIS_TARGET "callbacks") + find_package(Threads REQUIRED) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") @@ -6,23 +8,29 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") # todo endif() -add_executable(callbacks main.cpp) +add_executable(${THIS_TARGET} main.cpp) -target_compile_options(callbacks PRIVATE -Wall -pedantic -Wextra) -target_compile_features(callbacks PRIVATE cxx_std_17) +if(MSVC) + target_compile_options(${THIS_TARGET} PRIVATE /W4) +else() + target_compile_options(${THIS_TARGET} PRIVATE -Wall -pedantic -Wextra) +endif() +target_compile_features(${THIS_TARGET} PRIVATE cxx_std_17) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - target_include_directories(callbacks PRIVATE ${ALSA_INCLUDE_DIRS}) + target_include_directories(${THIS_TARGET} PRIVATE ${ALSA_INCLUDE_DIRS}) elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") # todo endif() -target_link_libraries(callbacks +target_link_libraries(${THIS_TARGET} CxxMidi::CxxMidi Threads::Threads) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - target_link_libraries(callbacks ${ALSA_LIBRARIES}) + target_link_libraries(${THIS_TARGET} ${ALSA_LIBRARIES}) elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") # todo +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + target_link_libraries(${THIS_TARGET} winmm) endif() \ No newline at end of file diff --git a/examples/player_async/CMakeLists.txt b/examples/player_async/CMakeLists.txt index a9c5271..3ac64da 100644 --- a/examples/player_async/CMakeLists.txt +++ b/examples/player_async/CMakeLists.txt @@ -8,7 +8,11 @@ endif() add_executable(player_async main.cpp) -target_compile_options(player_async PRIVATE -Wall -pedantic -Wextra) +if(MSVC) + target_compile_options(player_async PRIVATE /W4) +else() + target_compile_options(player_async PRIVATE -Wall -pedantic -Wextra) +endif() target_compile_features(player_async PRIVATE cxx_std_17) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") diff --git a/examples/player_sync/CMakeLists.txt b/examples/player_sync/CMakeLists.txt index 2f168d9..19ef383 100644 --- a/examples/player_sync/CMakeLists.txt +++ b/examples/player_sync/CMakeLists.txt @@ -8,7 +8,11 @@ endif() add_executable(player_sync main.cpp) -target_compile_options(player_sync PRIVATE -Wall -pedantic -Wextra) +if(MSVC) + target_compile_options(player_sync PRIVATE /W4) +else() + target_compile_options(player_sync PRIVATE -Wall -pedantic -Wextra) +endif() target_compile_features(player_sync PRIVATE cxx_std_17) diff --git a/examples/qtmidieditor/CMakeLists.txt b/examples/qtmidieditor/CMakeLists.txt index a87ac67..97943ed 100644 --- a/examples/qtmidieditor/CMakeLists.txt +++ b/examples/qtmidieditor/CMakeLists.txt @@ -18,7 +18,11 @@ add_executable(qtmidieditor trackmodel.cpp trackview.cpp) -target_compile_options(qtmidieditor PRIVATE -Wall -pedantic -Wextra) +if(MSVC) + target_compile_options(qtmidieditor PRIVATE /W4) +else() + target_compile_options(qtmidieditor PRIVATE -Wall -pedantic -Wextra) +endif() target_compile_features(qtmidieditor PRIVATE cxx_std_17) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") diff --git a/examples/qtmidiplayer/CMakeLists.txt b/examples/qtmidiplayer/CMakeLists.txt index e9eb43e..2ad15fd 100644 --- a/examples/qtmidiplayer/CMakeLists.txt +++ b/examples/qtmidiplayer/CMakeLists.txt @@ -14,7 +14,11 @@ add_executable(qtmidiplayer main.cpp mainwindow.cpp) -target_compile_options(qtmidiplayer PRIVATE -Wall -pedantic -Wextra) +if(MSVC) + target_compile_options(qtmidiplayer PRIVATE /W4) +else() + target_compile_options(qtmidiplayer PRIVATE -Wall -pedantic -Wextra) +endif() target_compile_features(qtmidiplayer PRIVATE cxx_std_17) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") diff --git a/examples/sequencing/CMakeLists.txt b/examples/sequencing/CMakeLists.txt index 45b1880..a771226 100644 --- a/examples/sequencing/CMakeLists.txt +++ b/examples/sequencing/CMakeLists.txt @@ -8,7 +8,11 @@ endif() add_executable(sequencing main.cpp) -target_compile_options(sequencing PRIVATE -Wall -pedantic -Wextra) +if(MSVC) + target_compile_options(sequencing PRIVATE /W4) +else() + target_compile_options(sequencing PRIVATE -Wall -pedantic -Wextra) +endif() target_compile_features(sequencing PRIVATE cxx_std_17) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") @@ -25,4 +29,4 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") target_link_libraries(sequencing ${ALSA_LIBRARIES}) elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") # todo -endif() \ No newline at end of file +endif() diff --git a/include/cxxmidi/guts/player_base.hpp b/include/cxxmidi/guts/player_base.hpp index 7a40f05..7145647 100644 --- a/include/cxxmidi/guts/player_base.hpp +++ b/include/cxxmidi/guts/player_base.hpp @@ -141,7 +141,8 @@ void PlayerBase::SetupWindowsTimers() { UINT wTimerRes; if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) == TIMERR_NOERROR) { - wTimerRes = min(max(tc.wPeriodMin, 1 /* [ms] */), tc.wPeriodMax); + wTimerRes = + std::min(std::max(tc.wPeriodMin, 1u /* [ms] */), tc.wPeriodMax); timeBeginPeriod(wTimerRes); } diff --git a/include/cxxmidi/output/default.hpp b/include/cxxmidi/output/default.hpp index 9f8a626..0c31213 100644 --- a/include/cxxmidi/output/default.hpp +++ b/include/cxxmidi/output/default.hpp @@ -27,7 +27,7 @@ SOFTWARE. #include namespace cxxmidi { namespace output { -typedef output::windows Default; +typedef output::Windows Default; } // namespace output } // namespace cxxmidi #elif __APPLE__ // Mac OS X diff --git a/include/cxxmidi/output/windows.hpp b/include/cxxmidi/output/windows.hpp index cce9a26..d274785 100644 --- a/include/cxxmidi/output/windows.hpp +++ b/include/cxxmidi/output/windows.hpp @@ -43,7 +43,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. namespace cxxmidi { namespace output { -class Windows : public Output::Abstract { +class Windows : public output::Abstract { static const int RT_SYSEX_BUFFER_SIZE = 1024; static const int RT_SYSEX_BUFFER_COUNT = 4; @@ -83,7 +83,7 @@ class Windows : public Output::Abstract { } // namespace cxxmidi namespace cxxmidi { -namespace Output { +namespace output { Windows::Windows() { Initialize(); } @@ -141,7 +141,7 @@ void Windows::Initialize() { } void Windows::OpenPort(unsigned int portNumber_) { - if (_connected) { + if (connected_) { #ifndef CXXMIDI_QUIET std::cerr << "CxxMidi: a valid connection already exists" << std::endl; #endif @@ -164,15 +164,15 @@ void Windows::OpenPort(unsigned int portNumber_) { std::cerr << "CxxMidi: Windows MM output port init error" << std::endl; #endif - _connected = true; + connected_ = true; } void Windows::ClosePort() { - if (_connected) { + if (connected_) { WinMidiData *data = static_cast(api_data_); midiOutReset(data->outHandle); midiOutClose(data->outHandle); - _connected = false; + connected_ = false; } } @@ -262,7 +262,7 @@ void Windows::SendMessage(const std::vector *msg_) { } } -} // namespace Output +} // namespace output } // namespace cxxmidi #endif // INCLUDE_CXXMIDI_OUTPUT_WINDOWS_HPP_ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 631281f..09c3799 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,24 @@ +set(THIS_TARGET "tests") + find_package(Threads REQUIRED) -find_package(GTest REQUIRED) -add_executable(tests +if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + # https://google.github.io/googletest/quickstart-cmake.html + cmake_policy(SET CMP0135 NEW) + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + ) + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) + include(GoogleTest) +else() + find_package(GTest REQUIRED) +endif() + +add_executable(${THIS_TARGET} endianness.cpp file.cpp instrument.cpp @@ -11,12 +28,20 @@ add_executable(tests other.cpp player_base.cpp) -target_compile_options(tests PRIVATE -Wall -pedantic -Wextra) -target_compile_features(tests PRIVATE cxx_std_17) +if(MSVC) + target_compile_options(${THIS_TARGET} PRIVATE /W4) +else() + target_compile_options(${THIS_TARGET} PRIVATE -Wall -pedantic -Wextra) +endif() +target_compile_features(${THIS_TARGET} PRIVATE cxx_std_17) -target_link_libraries(tests +target_link_libraries(${THIS_TARGET} CxxMidi::CxxMidi - GTest::GTest + GTest::gtest_main Threads::Threads) -gtest_discover_tests(tests WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) \ No newline at end of file +if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + target_link_libraries(${THIS_TARGET} winmm) +endif() + +gtest_discover_tests(${THIS_TARGET} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} DISCOVERY_MODE PRE_TEST) \ No newline at end of file diff --git a/tests/file.cpp b/tests/file.cpp index b75dceb..860558b 100644 --- a/tests/file.cpp +++ b/tests/file.cpp @@ -22,6 +22,7 @@ SOFTWARE. #include +#include #include #include