Skip to content

Commit

Permalink
CMake: Refactor into subdirectories, projects
Browse files Browse the repository at this point in the history
Our CMakeLists.txt is pushing 1.5k lines of spaghetti and has become
unmaintainable. This change splits Surge into subprojects to try and:

- Increase readability (targets & properties instead of variables)
- Reduce and gain insight into dependencies
- Reduce redundancy, potential for regressions and merge conflicts
- Make building things optional via SURGE_BUILD_* cache variables

Behavior shouldn't have changed too noticeably. Some targets were merged
or renamed to declutter the IDE a bit. The pluginval stuff still needs
cleaning up, but I didn't want to make this even bigger.
  • Loading branch information
mvf committed Sep 15, 2021
1 parent 6776191 commit fa3c7f5
Show file tree
Hide file tree
Showing 21 changed files with 1,097 additions and 1,431 deletions.
1,479 changes: 131 additions & 1,348 deletions CMakeLists.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ git clone --branch lv2 https://github.com/lv2-porting-project/JUCE JUCE-lv2
then run a fresh CMake to (1) point to that JUCE fork and (2) activate LV2

```
cmake -Bbuild_lv2 -DCMAKE_BUILD_TYPE=Release -DJUCE_SUPPORTS_LV2=True -DSURGE_ALTERNATE_JUCE=/some/location/JUCE-lv2/
cmake -Bbuild_lv2 -DCMAKE_BUILD_TYPE=Release -DJUCE_SUPPORTS_LV2=True -DSURGE_JUCE_PATH=/some/location/JUCE-lv2/
cmake --build build_lv2 --config Release --target surge-xt_LV2 --parallel 4
cmake --build build_lv2 --config Release --target surge-fx_LV2 --parallel 4
```
Expand Down
22 changes: 12 additions & 10 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pr:

jobs:
- job: Build
variables:
defaultTargets: "surge-xt_Packaged surge-fx_Packaged"
strategy:
matrix:
macOS-unit-test:
Expand All @@ -27,29 +29,29 @@ jobs:
isMac: True
isMacFat: True
cmakeArguments: "-GXcode -DCMAKE_BUILD_TYPE=Debug -D\"CMAKE_OSX_ARCHITECTURES=x86_64\""
cmakeTarget: "ci-pull-req"
cmakeTarget: $(defaultTargets)
cmakeConfig: "Debug"
xcodePath: "/Applications/Xcode_12.2.app"
macOS-arm:
imageName: 'macos-10.15'
isMac: True
isMacFat: True
cmakeArguments: "-GXcode -DCMAKE_BUILD_TYPE=Debug -D\"CMAKE_OSX_ARCHITECTURES=arm64\""
cmakeTarget: "ci-pull-req"
cmakeTarget: $(defaultTargets)
cmakeConfig: "Debug"
xcodePath: "/Applications/Xcode_12.2.app"
windows-x64:
imageName: 'windows-2019'
isWindows: True
cmakeArguments: "-A x64 -DCMAKE_BUILD_TYPE=Debug"
cmakeConfig: "Debug"
cmakeTarget: "ci-pull-req"
cmakeTarget: $(defaultTargets)
windows-x86-vs2017:
imageName: 'vs2017-win2016'
isWindows: True
cmakeArguments: "-A Win32 -DCMAKE_BUILD_TYPE=Debug"
cmakeConfig: "Debug"
cmakeTarget: "ci-pull-req"
cmakeTarget: $(defaultTargets)
windows-unittest:
imageName: 'vs2017-win2016'
isWindows: True
Expand All @@ -68,7 +70,7 @@ jobs:
imageName: 'ubuntu-20.04'
isLinux: True
aptGetExtras: ""
cmakeArguments: "-GNinja -DCMAKE_BUILD_TYPE=Debug -DBUILD_SURGE_PYTHON_BINDINGS=True"
cmakeArguments: "-GNinja -DCMAKE_BUILD_TYPE=Debug -DSURGE_BUILD_PYTHON_BINDINGS=True"
cmakeTarget: "surgepy"
cmakeConfig: "Debug"
linux-clang-juce:
Expand All @@ -89,7 +91,7 @@ jobs:
imageName: 'ubuntu-18.04'
isLinux: True
cmakeArguments: "-GNinja -DCMAKE_BUILD_TYPE=Debug"
cmakeTarget: "ci-pull-req"
cmakeTarget: $(defaultTargets)
cmakeConfig: "Debug"
linux-unittest:
imageName: 'ubuntu-20.04'
Expand All @@ -102,7 +104,7 @@ jobs:
imageName: 'ubuntu-20.04'
isLinux: True
needsLV2: True
cmakeArguments: "-DCMAKE_BUILD_TYPE=Release -DJUCE_SUPPORTS_LV2=True -DSURGE_ALTERNATE_JUCE=libs/JUCE-lv2"
cmakeArguments: "-DCMAKE_BUILD_TYPE=Release -DJUCE_SUPPORTS_LV2=True -DSURGE_JUCE_PATH=$PWD/libs/JUCE-lv2"
cmakeConfig: "Release"
cmakeTarget: "surge-xt_LV2"

Expand Down Expand Up @@ -228,7 +230,7 @@ jobs:
ls -l "${LOCALAPPDATA}/Surge XT/"
build/Release/surge-headless.exe
build/src/headless/Release/surge-headless.exe
condition: variables.isWindowsUnitTest
displayName: windows - run unit tests
Expand All @@ -244,7 +246,7 @@ jobs:
mkdir -p $XDG_DATA_HOME
rsync -r --delete "resources/data/" "$XDG_DATA_HOME/surge-xt/"
./build/surge-headless
./build/src/headless/surge-headless
condition: variables.isLinuxUnitTest
displayName: linux - run unit test
Expand All @@ -256,7 +258,7 @@ jobs:
mkdir "$HOME/Library/Application Support/Surge XT"
rsync -r --delete "resources/data/" "$HOME/Library/Application Support/Surge XT/"
./build/Release/surge-headless
./build/src/headless/Release/surge-headless
condition: variables.isMacUnitTest
displayName: macOS - run unit tests
Expand Down
40 changes: 0 additions & 40 deletions cmake/FindLibSndFile.cmake

This file was deleted.

9 changes: 9 additions & 0 deletions libs/strnatcmp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# vi:set sw=2 et:
project(strnatcmp)

add_library(${PROJECT_NAME}
strnatcmp.cpp
strnatcmp.h
)
add_library(surge::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
20 changes: 20 additions & 0 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# vi:set sw=2 et:
function(surge_install_resources scope dst)
add_custom_target(install-resources-${scope})
add_custom_command(
TARGET install-resources-${scope}
POST_BUILD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND echo "Installing resources to ${dst}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${dst}"
COMMAND rsync -r --delete "data/" "${dst}"
)
endfunction()

if(APPLE)
surge_install_resources(local "$ENV{HOME}/Library/Application Support/Surge XT/")
surge_install_resources(global "/Library/Application Support/Surge XT/")
elseif(UNIX)
surge_install_resources(local "$ENV{HOME}/.local/share/surge-xt/")
surge_install_resources(global "${CMAKE_INSTALL_PREFIX}/share/surge-xt/")
endif()
File renamed without changes.
File renamed without changes.
169 changes: 169 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# vi:set sw=2 et:
option(SURGE_BUILD_HEADLESS "Build Surge headless unit test runner" ON)
option(SURGE_BUILD_FX "Build Surge FX bank" ON)
option(SURGE_BUILD_XT "Build Surge XT synth" ON)
option(SURGE_BUILD_PYTHON_BINDINGS "Build Surge Python bindings with pybind11" OFF)
option(SURGE_COPY_AFTER_BUILD "Copy JUCE plugins after build" OFF)

set(SURGE_JUCE_PATH "${CMAKE_SOURCE_DIR}/libs/JUCE" CACHE STRING "Path to JUCE library source tree")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(cmake/lib.cmake)

message(STATUS "Using JUCE from ${SURGE_JUCE_PATH}")
add_subdirectory(${SURGE_JUCE_PATH} ${CMAKE_BINARY_DIR}/JUCE EXCLUDE_FROM_ALL)

add_library(simde INTERFACE)
target_include_directories(simde INTERFACE ${CMAKE_SOURCE_DIR}/libs/simde)
add_library(surge::simde ALIAS simde)

add_library(surge-juce INTERFACE)
target_compile_definitions(surge-juce INTERFACE
JUCE_ALLOW_STATIC_NULL_VARIABLES=0
JUCE_STRICT_REFCOUNTEDPOINTER=1

JUCE_VST3_CAN_REPLACE_VST2=0
JUCE_USE_CURL=0
JUCE_WEB_BROWSER=0
JUCE_USE_CAMERA=disabled

JUCE_DISPLAY_SPLASH_SCREEN=0
JUCE_REPORT_APP_USAGE=0

JUCE_MODAL_LOOPS_PERMITTED=0

JUCE_COREGRAPHICS_DRAW_ASYNC=1

JUCE_ALSA=1
JUCE_JACK=1

JUCE_WASAPI=1
JUCE_DIRECTSOUND=1

JUCE_CATCH_UNHANDLED_EXCEPTIONS=$<CONFIG:Debug>
)

set(SURGE_JUCE_FORMATS VST3 Standalone)
if(APPLE)
list(APPEND SURGE_JUCE_FORMATS AU)
endif()

if(SURGE_XT_BUILD_AUV3)
list(APPEND SURGE_JUCE_FORMATS AUv3)
endif()

if(DEFINED ENV{VST2SDK_DIR})
file(TO_CMAKE_PATH "$ENV{VST2SDK_DIR}" JUCE_VST2_DIR)
juce_set_vst2_sdk_path(${JUCE_VST2_DIR})
list(APPEND SURGE_JUCE_FORMATS VST)
message(STATUS "JUCE VST2 SDK Path is $ENV{VST2SDK_DIR}")
# VST2 headers are invalid UTF-8
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/wd4828>)
endif()

if(JUCE_SUPPORTS_LV2)
list(APPEND SURGE_JUCE_FORMATS LV2)
message( STATUS "Including JUCE LV2 support. You will need a different JUCE than the submodule" )
message( STATUS "Turning off deprecation warning to error since JUCE LV2 uses deprecated APIs" )
add_compile_options(-Wno-error=deprecated-declarations)
endif()

if(BUILD_USING_MY_ASIO_LICENSE)
message(STATUS "** BUILD WITH YOUR ASIO LICENSE **" )
message(STATUS " Downloading ASIO SDK from Steinberg" )
message(STATUS " The resulting Surge Standalones are not licensed for distribution" )

if(DEFINED ENV{ASIOSDK_DIR})
file(TO_CMAKE_PATH "$ENV{ASIOSDK_DIR}" ASIOSDK_DIR)
message(STATUS "ASIO SDK found at ${ASIOSDK_DIR}")
else()
message(STATUS "Fetching ASIO SDK")
set(ASIOSDK_DIR ${CMAKE_BINARY_DIR}/asio/asiosdk)
add_custom_target(surge-get-local-asio)
add_custom_command(
TARGET surge-get-local-asio
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/asio
COMMAND ${CMAKE_COMMAND} -D ASIO_SDK_DESTINATION=${CMAKE_BINARY_DIR}/asio -P cmake/get-asio.cmake
)
add_dependencies(surge-juce surge-get-local-asio)
endif()
target_compile_definitions(surge-juce INTERFACE JUCE_ASIO=1)
target_include_directories(surge-juce INTERFACE ${ASIOSDK_DIR}/common)
set(JUCE_ASIO_SUPPORT TRUE)
endif()

message(STATUS "Building Surge JUCE as ${SURGE_JUCE_FORMATS}")

add_subdirectory(common)

if(SURGE_BUILD_HEADLESS)
add_subdirectory(headless)
endif()

if(SURGE_BUILD_FX)
add_subdirectory(surge_effects_bank)
endif()

if(SURGE_BUILD_XT)
add_subdirectory(gui)
add_subdirectory(surge_synth_juce)
endif()

if(SURGE_BUILD_PYTHON_BINDINGS)
add_subdirectory(python_bindings)
endif()

if(SURGE_BUILD_FX AND SURGE_BUILD_XT AND NOT CMAKE_CROSSCOMPILING)
surge_make_installers()
endif()

# FIXME: Plugin validation {{{
if (APPLE)
message( STATUS "Validate me! Please!" )
add_custom_target(stage-pluginval)
add_custom_command(TARGET stage-pluginval
POST_BUILD
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND cmake -E make_directory pluginval
COMMAND curl -L "https://github.com/Tracktion/pluginval/releases/download/latest_release/pluginval_macOS.zip" -o pluginval/pluginval.zip
COMMAND cd pluginval && unzip -o pluginval.zip
)
add_custom_target(surge-xt-pluginval-vst3)
add_dependencies(surge-xt-pluginval-vst3 surge-xt_VST3)
add_dependencies(surge-xt-pluginval-vst3 stage-pluginval)
add_custom_command(TARGET surge-xt-pluginval-vst3
POST_BUILD
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND pluginval/pluginval.app/Contents/MacOS/pluginval --validate-in-process --output-dir "." --validate "${SURGE_FX_OUTPUT_DIR}/VST3/Surge XT.vst3" || exit 1
)

add_custom_target(surge-xt-pluginval-au)
add_dependencies(surge-xt-pluginval-au surge-xt_AU)
add_dependencies(surge-xt-pluginval-au stage-pluginval)
add_custom_command(TARGET surge-xt-pluginval-au
POST_BUILD
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND pluginval/pluginval.app/Contents/MacOS/pluginval --validate-in-process --output-dir "." --validate "${SURGE_XT_OUTPUT_DIR}/AU/Surge XT.component" || exit 1
)

add_custom_target(surge-fx-pluginval-vst3)
add_dependencies(surge-fx-pluginval-vst3 surge-fx_VST3)
add_dependencies(surge-fx-pluginval-vst3 stage-pluginval)
add_custom_command(TARGET surge-fx-pluginval-vst3
POST_BUILD
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND pluginval/pluginval.app/Contents/MacOS/pluginval --validate-in-process --output-dir "." --validate "${SURGE_FX_OUTPUT_DIR}/VST3/${SURGE_FX_PRODUCT_NAME}.vst3" || exit 1
)

add_custom_target(surge-fx-pluginval-au)
add_dependencies(surge-fx-pluginval-au surge-fx_AU)
add_dependencies(surge-fx-pluginval-au stage-pluginval)
add_custom_command(TARGET surge-fx-pluginval-au
POST_BUILD
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND pluginval/pluginval.app/Contents/MacOS/pluginval --validate-in-process --output-dir "." --validate "${SURGE_FX_OUTPUT_DIR}/AU/${SURGE_FX_PRODUCT_NAME}.component" || exit 1
)
endif()
# }}}

File renamed without changes.
Loading

0 comments on commit fa3c7f5

Please sign in to comment.