Skip to content

Commit

Permalink
Small CMake refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
leonp-s committed Jan 17, 2024
1 parent ecdf91b commit ac5f71e
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 83 deletions.
88 changes: 5 additions & 83 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.20)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

project(zones_convolver VERSION 1.0.0 LANGUAGES CXX
DESCRIPTION "Convolution engine used by the Zones platform"
Expand All @@ -7,94 +8,15 @@ project(zones_convolver VERSION 1.0.0 LANGUAGES CXX
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED true)

function(FetchJuce)
FetchContent_Declare(JUCE
GIT_REPOSITORY https://github.com/juce-framework/JUCE.git
GIT_TAG origin/master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
FIND_PACKAGE_ARGS 7.0.5)
FetchContent_MakeAvailable(JUCE)
endfunction()

function(FetchCatch2)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.3.2)
FetchContent_MakeAvailable(Catch2)
endfunction()

function(FetchMelatoninSparklines)
FetchContent_Declare(melatonin_audio_sparklines
GIT_REPOSITORY https://github.com/sudara/melatonin_audio_sparklines.git
GIT_TAG origin/main
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/melatonin_audio_sparklines)
FetchContent_MakeAvailable(melatonin_audio_sparklines)
juce_add_module(${melatonin_audio_sparklines_SOURCE_DIR})
endfunction()

function(FetchMelatoninTestHelpers)
FetchContent_Declare(melatonin_test_helpers
GIT_REPOSITORY https://github.com/zones-convolution/melatonin_test_helpers.git
GIT_TAG technical/juce-update
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/melatonin_test_helpers)
FetchContent_MakeAvailable(melatonin_test_helpers)
endfunction()

function(SetupTests)
enable_testing()
add_executable(zones_convolver_tests)
target_sources(zones_convolver_tests PRIVATE
tests/ConvolverUtilitiesTests.cpp
tests/ComplexBufferTests.cpp
)

# Avoid compiling external dependencies with warning flags, probably a better way of doing this...
add_library(test_dependencies INTERFACE)
target_link_libraries(test_dependencies
INTERFACE
melatonin_audio_sparklines
melatonin_test_helpers
Catch2::Catch2WithMain)

target_link_libraries(zones_convolver_tests PRIVATE
zones_convolver
test_dependencies
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags
)

target_compile_definitions(zones_convolver_tests
PUBLIC
JUCE_WEB_BROWSER=0
JUCE_VST3_CAN_REPLACE_VST2=0
)

target_compile_options(zones_convolver_tests
INTERFACE
-Wall
-Wextra
-Werror
-Wpedantic
)

target_compile_definitions(zones_convolver_tests PRIVATE PROJECT_ROOT="${CMAKE_SOURCE_DIR}")
include(${Catch2_SOURCE_DIR}/extras/Catch.cmake)
catch_discover_tests(zones_convolver_tests)
endfunction()

if (zones_convolver_IS_TOP_LEVEL)
include(FetchContent)

FetchJuce()
FetchCatch2()
FetchMelatoninSparklines()
FetchMelatoninTestHelpers()
include(AddJuce)
include(AddCatch2)
include(AddMelatonin)

juce_add_module(zones_convolver)
SetupTests()
add_subdirectory(test)
else ()
juce_add_module(zones_convolver)
endif ()
8 changes: 8 additions & 0 deletions cmake/AddCatch2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)

FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
7 changes: 7 additions & 0 deletions cmake/AddJuce.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FetchContent_Declare(JUCE
GIT_REPOSITORY https://github.com/juce-framework/JUCE.git
GIT_TAG origin/master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
FIND_PACKAGE_ARGS 7.0.5)
FetchContent_MakeAvailable(JUCE)
12 changes: 12 additions & 0 deletions cmake/AddMelatonin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FetchContent_Declare(melatonin_audio_sparklines
GIT_REPOSITORY https://github.com/sudara/melatonin_audio_sparklines.git
GIT_TAG origin/main
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/melatonin_audio_sparklines)
FetchContent_MakeAvailable(melatonin_audio_sparklines)
juce_add_module(${melatonin_audio_sparklines_SOURCE_DIR})

FetchContent_Declare(melatonin_test_helpers
GIT_REPOSITORY https://github.com/zones-convolution/melatonin_test_helpers.git
GIT_TAG technical/juce-update
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/melatonin_test_helpers)
FetchContent_MakeAvailable(melatonin_test_helpers)
35 changes: 35 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
enable_testing()

add_executable(unit_tests)
target_sources(unit_tests PRIVATE
ConvolverUtilitiesTests.cpp
ComplexBufferTests.cpp
)

target_link_libraries(unit_tests PRIVATE
zones_convolver
melatonin_audio_sparklines
melatonin_test_helpers
Catch2::Catch2WithMain
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags
)

target_compile_definitions(unit_tests
PUBLIC
JUCE_WEB_BROWSER=0
JUCE_VST3_CAN_REPLACE_VST2=0
)

target_compile_options(unit_tests
INTERFACE
-Wall
-Wextra
-Werror
-Wpedantic
)

include(CTest)
include(Catch)
catch_discover_tests(unit_tests)
File renamed without changes.
File renamed without changes.

0 comments on commit ac5f71e

Please sign in to comment.