Skip to content

Commit

Permalink
[cmake] Allow to enable / disable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jun 29, 2023
1 parent 2e73ca0 commit 7972547
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option(LIBREMIDI_NO_JACK "Disable JACK back-end" OFF)
option(LIBREMIDI_NO_ALSA "Disable ALSA back-end" OFF)
option(LIBREMIDI_NO_EXPORTS "Disable dynamic symbol exporting" OFF)
option(LIBREMIDI_EXAMPLES "Enable examples" OFF)
option(LIBREMIDI_TESTS "Enable tests" ON)

include(CheckSymbolExists)
include(CheckCXXSourceCompiles)
Expand Down Expand Up @@ -225,35 +226,37 @@ if(LIBREMIDI_EXAMPLES)
endif()
endif()

find_package(Catch2 QUIET)
if(TARGET Catch2::Catch2WithMain AND Catch2_FOUND)
message(STATUS "libremidi : compiling tests")
target_compile_features(libremidi ${_public} cxx_std_20)
if(LIBREMIDI_TESTS)
find_package(Catch2 QUIET)
if(TARGET Catch2::Catch2WithMain AND Catch2_FOUND)
message(STATUS "libremidi : compiling tests")
target_compile_features(libremidi ${_public} cxx_std_20)

add_executable(midiin_test tests/unit/midi_in.cpp)
target_link_libraries(midiin_test PRIVATE libremidi Catch2::Catch2WithMain)
add_executable(midiin_test tests/unit/midi_in.cpp)
target_link_libraries(midiin_test PRIVATE libremidi Catch2::Catch2WithMain)

add_executable(midiout_test tests/unit/midi_out.cpp)
target_link_libraries(midiout_test PRIVATE libremidi Catch2::Catch2WithMain)
add_executable(midiout_test tests/unit/midi_out.cpp)
target_link_libraries(midiout_test PRIVATE libremidi Catch2::Catch2WithMain)

add_executable(midifile_read_test tests/unit/midifile_read.cpp)
target_link_libraries(midifile_read_test PRIVATE libremidi Catch2::Catch2WithMain)
target_compile_definitions(midifile_read_test PRIVATE "LIBREMIDI_TEST_CORPUS=\"${CMAKE_CURRENT_SOURCE_DIR}/tests/corpus\"")
add_executable(midifile_read_test tests/unit/midifile_read.cpp)
target_link_libraries(midifile_read_test PRIVATE libremidi Catch2::Catch2WithMain)
target_compile_definitions(midifile_read_test PRIVATE "LIBREMIDI_TEST_CORPUS=\"${CMAKE_CURRENT_SOURCE_DIR}/tests/corpus\"")

add_executable(midifile_write_test tests/unit/midifile_write.cpp)
target_link_libraries(midifile_write_test PRIVATE libremidi Catch2::Catch2WithMain)
target_compile_definitions(midifile_write_test PRIVATE "LIBREMIDI_TEST_CORPUS=\"${CMAKE_CURRENT_SOURCE_DIR}/tests/corpus\"")
add_executable(midifile_write_test tests/unit/midifile_write.cpp)
target_link_libraries(midifile_write_test PRIVATE libremidi Catch2::Catch2WithMain)
target_compile_definitions(midifile_write_test PRIVATE "LIBREMIDI_TEST_CORPUS=\"${CMAKE_CURRENT_SOURCE_DIR}/tests/corpus\"")

add_executable(midifile_write_tracks_test tests/integration/midifile_write_tracks.cpp)
target_link_libraries(midifile_write_tracks_test PRIVATE libremidi Catch2::Catch2WithMain)
add_executable(midifile_write_tracks_test tests/integration/midifile_write_tracks.cpp)
target_link_libraries(midifile_write_tracks_test PRIVATE libremidi Catch2::Catch2WithMain)

include(CTest)
include(Catch)
catch_discover_tests(midiin_test)
catch_discover_tests(midiout_test)
catch_discover_tests(midifile_read_test)
catch_discover_tests(midifile_write_test)
catch_discover_tests(midifile_write_tracks_test)
else()
message(STATUS "libremidi : not compiling tests")
include(CTest)
include(Catch)
catch_discover_tests(midiin_test)
catch_discover_tests(midiout_test)
catch_discover_tests(midifile_read_test)
catch_discover_tests(midifile_write_test)
catch_discover_tests(midifile_write_tracks_test)
else()
message(STATUS "libremidi : not compiling tests")
endif()
endif()

0 comments on commit 7972547

Please sign in to comment.