Skip to content

Commit

Permalink
Fixed CMake to not include juce if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ffAudio committed Feb 3, 2024
1 parent a619fb7 commit 7700d21
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 59 deletions.
21 changes: 21 additions & 0 deletions CMakeIncludes/Juce.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[[

Adding this include will add juce to your project

]]

#Adds all the module sources so they appear correctly in the IDE
set_property(GLOBAL PROPERTY USE_FOLDERS YES)
option(JUCE_ENABLE_MODULE_SOURCE_GROUPS "Enable Module Source Groups" ON)

#set any of these to "ON" if you want to build one of the juce examples
#or extras (Projucer/AudioPluginHost, etc):
option(JUCE_BUILD_EXTRAS "Build JUCE Extras" OFF)
option(JUCE_BUILD_EXAMPLES "Build JUCE Examples" OFF)

FetchContent_Declare(juce
GIT_REPOSITORY https://github.com/juce-framework/JUCE.git
# GIT_TAG 7.0.9
GIT_SHALLOW ON)

FetchContent_MakeAvailable(juce)
80 changes: 35 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,63 +31,53 @@

cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

set (FGM_VERSION 1.4.0)
set(FGM_VERSION 1.4.0)

project (foleys_gui_magic
project(foleys_gui_magic
DESCRIPTION "PluginGuiMagic"
HOMEPAGE_URL "https://foleysfinest.com/PluginGuiMagic"
LANGUAGES CXX)

list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeIncludes")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeIncludes")

include (PGMPluginval)
option(FOLEYS_BUILD_EXAMPLES "Build the examples" ON)
option(FOLEYS_BUILD_TESTS "Build and run the unit tests" ON)
option(FOLEYS_RUN_PLUGINVAL "Run pluginval on the example plugins" ON)

option (FOLEYS_BUILD_EXAMPLES "Build the examples" ON)
option (FOLEYS_BUILD_TESTS "Build and run the unit tests" ON)
option (FOLEYS_RUN_PLUGINVAL "Run pluginval on the example plugins" ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_LIST_DIR}/logs")

set_property (GLOBAL PROPERTY USE_FOLDERS ON)
set_property (GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug)
set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_LIST_DIR}/logs")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

set (CMAKE_CXX_VISIBILITY_PRESET hidden)
set (CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

# universal binaries on Mac
set (CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING
"Architectures to build on MacOS. Set to arm64\;x86_64 to build universal (fat) binaries, or just one of those for faster build times.")

# static linking on Windows
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# JUCE
include (FetchContent)

FetchContent_Declare (
juce
GIT_REPOSITORY https://github.com/juce-framework/JUCE.git
GIT_TAG origin/master
GIT_SHALLOW ON)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

set (JUCE_ENABLE_MODULE_SOURCE_GROUPS ON)
set (JUCE_BUILD_EXTRAS OFF)
set (JUCE_BUILD_EXAMPLES OFF)
include(FetchContent)

FetchContent_MakeAvailable (juce)
# JUCE if needed
if (FOLEYS_BUILD_EXAMPLES OR FOLEYS_BUILD_EXAMPLES)
include(Juce)
endif ()

add_subdirectory (modules)
add_subdirectory(modules)

if(FOLEYS_BUILD_TESTS)
if (FOLEYS_BUILD_TESTS)
enable_testing()
add_subdirectory (Tests)
add_subdirectory(Tests)

if(foleys_gui_magic_IS_TOP_LEVEL)
include (CTest)
endif()
endif()
if (foleys_gui_magic_IS_TOP_LEVEL)
include(CTest)
endif ()
endif ()

# this must be AFTER the enable_testing() call above!
if (FOLEYS_BUILD_EXAMPLES)
Expand All @@ -96,11 +86,11 @@ endif ()

# install rules

set (FGM_INSTALL_DEST "${CMAKE_INSTALL_LIBDIR}/cmake/foleys_gui_magic"
set(FGM_INSTALL_DEST "${CMAKE_INSTALL_LIBDIR}/cmake/foleys_gui_magic"
CACHE STRING
"Directory below INSTALL_PREFIX where the foleys_gui_magic CMake package files will be installed to")

install (DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
DESTINATION "${FGM_INSTALL_DEST}/.."
COMPONENT foleys_gui_magic
PATTERN Tests/* EXCLUDE
Expand All @@ -111,27 +101,27 @@ install (DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
PATTERN CMakeLists.txt EXCLUDE
PATTERN "${CMAKE_CURRENT_BINARY_DIR}/" EXCLUDE)

include (CMakePackageConfigHelpers)
include(CMakePackageConfigHelpers)

#write_basic_package_version_file (foleys_gui_magic-config-version.cmake
# VERSION "${FGM_VERSION}"
# COMPATIBILITY SameMajorVersion
# ARCH_INDEPENDENT)

configure_package_config_file (CMakeIncludes/config.cmake foleys_gui_magic-config.cmake
configure_package_config_file(CMakeIncludes/config.cmake foleys_gui_magic-config.cmake
INSTALL_DESTINATION "${FGM_INSTALL_DEST}"
NO_SET_AND_CHECK_MACRO)

install (FILES "${CMAKE_CURRENT_BINARY_DIR}/foleys_gui_magic-config-version.cmake"
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/foleys_gui_magic-config-version.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/foleys_gui_magic-config.cmake"
DESTINATION "${FGM_INSTALL_DEST}"
COMPONENT foleys_gui_magic)

include (CPackComponent)
include(CPackComponent)

cpack_add_component (foleys_gui_magic
cpack_add_component(foleys_gui_magic
GROUP Foleys
INSTALL_TYPES Developer)

export (PACKAGE foleys_gui_magic)
export(PACKAGE foleys_gui_magic)

Original file line number Diff line number Diff line change
Expand Up @@ -904,13 +904,13 @@ class ListBoxItem : public GuiItem,

~ListBoxItem() override
{
if (auto* m = dynamic_cast<juce::ChangeBroadcaster*>(listBox.getModel()))
if (auto* m = dynamic_cast<juce::ChangeBroadcaster*>(listBox.getListBoxModel()))
m->removeChangeListener (this);
}

void update() override
{
if (auto* m = dynamic_cast<juce::ChangeBroadcaster*>(listBox.getModel()))
if (auto* m = dynamic_cast<juce::ChangeBroadcaster*>(listBox.getListBoxModel()))
m->removeChangeListener (this);

auto modelID = configNode.getProperty ("list-box-model", juce::String()).toString();
Expand Down
20 changes: 8 additions & 12 deletions modules/foleys_gui_magic/State/foleys_RadioButtonManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ namespace foleys
{


RadioButtonHandler::RadioButtonHandler (juce::Button& buttonToControl, RadioButtonManager& manager)
: button (buttonToControl),
radioButtonManager (manager)
RadioButtonHandler::RadioButtonHandler (juce::Button& buttonToControl, RadioButtonManager& manager) : button (buttonToControl), radioButtonManager (manager)
{
radioButtonManager.addButton (&button);
button.addListener (this);
Expand Down Expand Up @@ -71,7 +69,7 @@ void RadioButtonHandler::setRadioGroupValue (juce::var value, juce::RangedAudioP
{
auto currentValue = parameter->convertFrom0to1 (parameter->getValue());
// other than setToggleState this seems not to trigger circular updates
button.getToggleStateValue() = (currentValue == static_cast<float>(value));
button.getToggleStateValue() = juce::approximatelyEqual (currentValue, static_cast<float> (value));
}
}

Expand All @@ -97,7 +95,7 @@ void RadioButtonHandler::parameterValueChanged (int parameterIndex, float newVal

auto value = parameter->convertFrom0to1 (newValue);
// other than setToggleState this seems not to trigger circular updates
button.getToggleStateValue() = (value == static_cast<float>(radioButtonValue));
button.getToggleStateValue() = juce::approximatelyEqual (value, static_cast<float> (radioButtonValue));
}

// ==============================================================================
Expand All @@ -108,23 +106,21 @@ void RadioButtonManager::buttonActivated (juce::Button* button)
if (groupID == 0)
return;

for (auto& otherButton : buttons)
for (auto& otherButton: buttons)
if (otherButton && button != otherButton && otherButton->getRadioGroupId() == groupID)
otherButton->getToggleStateValue() = false;
}

void RadioButtonManager::addButton (juce::Button* button)
{
if (std::find(buttons.begin(), buttons.end(), button) == buttons.end())
buttons.push_back(button);
if (std::find (buttons.begin(), buttons.end(), button) == buttons.end())
buttons.push_back (button);
}

void RadioButtonManager::removeButton (juce::Button* button)
{
buttons.erase (std::remove_if (buttons.begin(), buttons.end(), [button](const auto& other)
{ return other == button || other == nullptr; }),
buttons.end());
buttons.erase (std::remove_if (buttons.begin(), buttons.end(), [button] (const auto& other) { return other == button || other == nullptr; }), buttons.end());
}


} // namespace foleys
} // namespace foleys

0 comments on commit 7700d21

Please sign in to comment.