Skip to content

Commit

Permalink
Added windows CI
Browse files Browse the repository at this point in the history
  • Loading branch information
5tan committed Aug 2, 2024
1 parent e6147c3 commit 16e715f
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 36 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
extra_check:
- ''
include:
- os: windows-latest
compiler: g++
- os: ubuntu-latest
compiler: clazy
extra_check: clazy
Expand All @@ -48,6 +50,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Ninja
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
Expand All @@ -56,6 +61,17 @@ jobs:
if: matrix.os == 'macos-latest'
run: brew install googletest qt6

- 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'
run: sudo apt-get -y install clang
Expand All @@ -76,9 +92,12 @@ jobs:
if: matrix.extra_check == 'iwyu'
run: sudo apt-get install -y iwyu

- 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)
run: ctest --test-dir build
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
10 changes: 5 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 14 additions & 6 deletions examples/callbacks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(THIS_TARGET "callbacks")

find_package(Threads REQUIRED)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
Expand All @@ -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()
6 changes: 5 additions & 1 deletion examples/player_async/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion examples/player_sync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
6 changes: 5 additions & 1 deletion examples/qtmidieditor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion examples/qtmidiplayer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions examples/sequencing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -25,4 +29,4 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
target_link_libraries(sequencing ${ALSA_LIBRARIES})
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# todo
endif()
endif()
3 changes: 2 additions & 1 deletion include/cxxmidi/guts/player_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion include/cxxmidi/output/default.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SOFTWARE.
#include <cxxmidi/output/windows.hpp>
namespace cxxmidi {
namespace output {
typedef output::windows Default;
typedef output::Windows Default;
} // namespace output
} // namespace cxxmidi
#elif __APPLE__ // Mac OS X
Expand Down
14 changes: 7 additions & 7 deletions include/cxxmidi/output/windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -83,7 +83,7 @@ class Windows : public Output::Abstract {
} // namespace cxxmidi

namespace cxxmidi {
namespace Output {
namespace output {

Windows::Windows() { Initialize(); }

Expand Down Expand Up @@ -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
Expand All @@ -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<WinMidiData *>(api_data_);
midiOutReset(data->outHandle);
midiOutClose(data->outHandle);
_connected = false;
connected_ = false;
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ void Windows::SendMessage(const std::vector<uint8_t> *msg_) {
}
}

} // namespace Output
} // namespace output
} // namespace cxxmidi

#endif // INCLUDE_CXXMIDI_OUTPUT_WINDOWS_HPP_
39 changes: 32 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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})
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)
1 change: 1 addition & 0 deletions tests/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SOFTWARE.

#include <gtest/gtest.h>

#include <array>
#include <cxxmidi/file.hpp>
#include <cxxmidi/note.hpp>

Expand Down

0 comments on commit 16e715f

Please sign in to comment.