Skip to content

Commit

Permalink
adapt cmake to build on linux
Browse files Browse the repository at this point in the history
- fix further clang-tidy issues
- integrate clang-tidy with cmake
- cmake package version checks
- github action ci: format, lint, build
  • Loading branch information
EwanMe committed Jan 27, 2024
1 parent 930a3ee commit 0ced6ee
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 84 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AccessModifierOffset: -4
BasedOnStyle: LLVM
ColumnLimit: 80
IndentWidth: 4
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ CheckOptions:
value: 1,
}
- { key: readability-function-cognitive-complexity.IgnoreMacros, value: 1 }
- {
key: readability-identifier-naming.TypeTemplateParameterIgnoredRegexp,
value: expr-type,
}
99 changes: 99 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CI
on:
pull_request:
types: [opened, reopened, synchronize]

env:
BUILD_TYPE: Release
JUCE_URL_LINUX: https://github.com/juce-framework/JUCE/archive/refs/tags/7.0.9.tar.gz
JUCE_URL_WIN: https://github.com/juce-framework/JUCE/archive/refs/tags/7.0.9.zip

jobs:
format-checking:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: RafikFarhad/clang-format-github-action@v3
with:
sources: 'src/**/*.h,src/**/*.cpp,src/*.cpp'

linux-build-and-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install packages
run: |
sudo apt update
sudo apt install -y \
curl \
clang-tidy-15 \
g++-13 \
ninja-build \
libasound2-dev \
libjack-jackd2-dev \
ladspa-sdk \
libcurl4-openssl-dev \
libfreetype6-dev \
libx11-dev \
libxcomposite-dev \
libxcursor-dev \
libxext-dev \
libxinerama-dev \
libxrandr-dev \
libxrender-dev \
libwebkit2gtk-4.0-dev
shell: bash

- name: Install JUCE
run: |
mkdir -p $GITHUB_WORKSPACE/juce
curl -s -L $JUCE_URL_LINUX | tar xzvf - -C $GITHUB_WORKSPACE/juce
shell: bash

- name: Configure CMake
run: |
export CXX=/usr/bin/g++-13
cmake -S $GITHUB_WORKSPACE -B ./build -G "Ninja" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_EXPORT_COMPILE_COMMANDS=on \
-DJUCE_PATH=$GITHUB_WORKSPACE/juce/JUCE-7.0.9 \
-DCMAKE_CXX_COMPILER=/usr/bin/g++-13
shell: bash

- name: Build
run: cmake --build ./build
shell: bash

windows-build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3

- name: Install packages
run: choco install -y ninja
shell: pwsh

- name: Install JUCE
run: |
Invoke-WebRequest -Uri $env:JUCE_URL_WIN -OutFile juce.zip
Expand-Archive -Path juce.zip -DestinationPath $env:GITHUB_WORKSPACE/juce -Force
Remove-Item juce.zip
shell: pwsh

- name: setup devcmd
uses: ilammy/msvc-dev-cmd@v1.13.0

- name: Configure CMake
run: |
cmake -S $GITHUB_WORKSPACE -B ./build -G "Ninja" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_EXPORT_COMPILE_COMMANDS=on \
-DJUCE_PATH=$GITHUB_WORKSPACE/juce/JUCE-7.0.9 \
-DCMAKE_CXX_COMPILER=cl \
-DCMAKE_C_COMPILER=cl
shell: cmd

- name: Build
run: cmake --build ./build
shell: cmd
13 changes: 0 additions & 13 deletions .github/workflows/clang-format.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

workflow_dispatch:

permissions:
permissions:
contents: write

jobs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/Builds
/build
/JuceLibraryCode
/.vs
122 changes: 99 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@ cmake_minimum_required(VERSION 3.15)

project(anyMidi VERSION 1.0.0)


set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(JUCE CONFIG REQUIRED)
set(JUCE_REQUIRED_VERSION 7.0.9)
if(CMAKE_PREFIX_PATH)
find_package(JUCE ${JUCE_REQUIRED_VERSION} CONFIG REQUIRED)
elseif(JUCE_PATH)
add_subdirectory(${JUCE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/JUCEBuild")

# Get JUCE version
file(READ "${JUCE_PATH}/CMakeLists.txt" CONTENTS)
if (${CONTENTS} MATCHES "project\\(JUCE[^)]+VERSION +([0-9]+\\.[0-9]+\\.[0-9]+)")
set(JUCE_VERSION ${CMAKE_MATCH_1} CACHE INTERNAL "Project version")
if(JUCE_VERSION STREQUAL JUCE_REQUIRED_VERSION)
message(STATUS "Found JUCE version: ${JUCE_VERSION}")
else()
message(FATAL_ERROR "Incorrect JUCE version. "
"Found ${JUCE_VERSION}, expected ${JUCE_REQUIRED_VERSION}")
endif()
else()
message(WARNING
"Version information not found in ${JUCE_PATH}/CMakeLists.txt, "
"assuming correct version ${JUCE_REQUIRED_VERSION} installed.")
endif()
else()
message(FATAL_ERROR
"No JUCE location provided. Please specify CMAKE_PREFIX_PATH for library "
"location or JUCE_PATH for source code location.")
endif()

juce_add_gui_app(anyMidi
VERSION 1.0.0
Expand All @@ -30,29 +54,81 @@ file(GLOB_RECURSE SRC_FILES

target_sources(anyMidi PRIVATE ${SRC_FILES})

#set_target_properties(tidy PROPERTIES
# CXX_CLANG_TIDY "clang-tidy;--header-filter=^(!?${CMAKE_SOURCE_DIR}\\Builds|${CMAKE_PREFIX_PATH})"
#)
if (UNIX)
# Run clang-tidy only on linux
foreach(version RANGE 15 17)
list(APPEND CLANG_TIDY_VERSIONS "clang-tidy-${version}")
endforeach()

find_program(CLANG_TIDY_BIN NAMES ${CLANG_TIDY_VERSIONS})

if(CLANG_TIDY_BIN)
message(STATUS "Found ${CLANG_TIDY_BIN}")
else()
message(FATAL_ERROR "Could not find clang-tidy with version >14")
endif()

set(HEADERS_TO_TIDY
".*src/core/AudioProcessor\.h"
".*src/core/ForwardFFT\.h"
".*src/core/MidiProcessor\.h"
".*src/ui/CustomLookAndFeel\.h"
".*src/ui/MainComponent\.h"
".*src/ui/UserInterface\.h"
)

string(JOIN "|" HEADER_FILTER ${HEADERS_TO_TIDY})

set_target_properties(anyMidi PROPERTIES
CXX_CLANG_TIDY "${CLANG_TIDY_BIN};-header-filter=^(${HEADER_FILTER})$"
)
endif()

set(PRIVATE_LIBS
anyMidiAssets
juce::juce_audio_basics
juce::juce_audio_devices
juce::juce_audio_formats
juce::juce_audio_processors
juce::juce_audio_utils
juce::juce_core
juce::juce_data_structures
juce::juce_dsp
juce::juce_events
juce::juce_graphics
juce::juce_gui_basics
juce::juce_gui_extra
)

set(PUBLIC_LIBS
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags
)

if(UNIX)
set(PRIVATE_LIBS curl ${PRIVATE_LIBS})
target_compile_options(anyMidi
PRIVATE
-I/usr/include/atk-1.0
-I/usr/include/cairo
-I/usr/include/harfbuzz
-I/usr/include/gdk-pixbuf-2.0
-I/usr/include/glib-2.0
-I/usr/include/gtk-3.0
-I/usr/include/libsoup-2.4
-I/usr/include/pango-1.0
-I/usr/include/webkitgtk-4.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include
)
endif()

target_include_directories(anyMidi SYSTEM PRIVATE
"${CMAKE_PREFIX_PATH}/include/JUCE-${JUCE_VERSION}/modules/")

target_link_libraries(anyMidi
PRIVATE
anyMidiAssets
juce::juce_audio_basics
juce::juce_audio_devices
juce::juce_audio_formats
juce::juce_audio_processors
juce::juce_audio_utils
juce::juce_core
juce::juce_data_structures
juce::juce_dsp
juce::juce_events
juce::juce_graphics
juce::juce_gui_basics
juce::juce_gui_extra
${PRIVATE_LIBS}
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags
${PUBLIC_LIBS}
)

juce_generate_juce_header(anyMidi)
4 changes: 2 additions & 2 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"ctestCommandArgs": "",
"variables": [
{
"name": "CMAKE_PREFIX_PATH",
"value": "C:\\lib\\JUCEbuild",
"name": "JUCE_PATH",
"value": "C:\\lib\\JUCE-7.0.9",
"type": "FILEPATH"
},
{
Expand Down
21 changes: 16 additions & 5 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,32 @@
*
*/

#include <JuceHeader.h>
#include <BinaryData.h>
#include <juce_core/juce_core.h>
#include <juce_gui_basics/juce_gui_basics.h>

#include "./core/AudioProcessor.h"
#include "./ui/CustomLookAndFeel.h"
#include "./ui/MainComponent.h"
#include "./util/Globals.h"

// NOLINTBEGIN(readability-identifier-naming)
namespace ProjectInfo {
const char *const projectName = "anyMidiStandalone";
const char *const companyName = "Hallvard Jensen";
const char *const versionString = "1.0.0";
const int versionNumber = 0x10000;
} // namespace ProjectInfo
// NOLINTEND(readability-identifier-naming)

class AnyMidiStandaloneApplication : public juce::JUCEApplication {
public:
AnyMidiStandaloneApplication() = default;

const juce::String getApplicationName() override {
const juce::String getApplicationName() override { // NOLINT
return ProjectInfo::projectName;
}
const juce::String getApplicationVersion() override {
const juce::String getApplicationVersion() override { // NOLINT
return ProjectInfo::versionString;
}

Expand Down Expand Up @@ -67,10 +78,10 @@ class AnyMidiStandaloneApplication : public juce::JUCEApplication {
DocumentWindow::closeButton) {
setUsingNativeTitleBar(false);
setTitleBarTextCentred(false);

// JUCE handles pointer safety
setContentOwned(new anyMidi::MainComponent(v), true); // NOLINT

setResizable(false, false);
centreWithSize(getWidth(), getHeight());
setLookAndFeel(layout);
Expand Down
4 changes: 1 addition & 3 deletions src/core/AudioProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
*
*/

#include <JuceHeader.h>

#include "../util/Globals.h"
#include "AudioProcessor.h"
#include "../util/Globals.h"

namespace {
double midiToFrequency(const int &note) {
Expand Down
10 changes: 8 additions & 2 deletions src/core/AudioProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

#pragma once

#include <JuceHeader.h>
#include <juce_audio_basics/juce_audio_basics.h>
#include <juce_audio_devices/juce_audio_devices.h>
#include <juce_core/juce_core.h>
#include <juce_data_structures/juce_data_structures.h>

#include "ForwardFFT.h"
#include "MidiProcessor.h"
Expand Down Expand Up @@ -81,7 +84,10 @@ class AudioProcessor : public juce::AudioSource,
static constexpr unsigned int numInputChannels{1};
static constexpr unsigned int numOutputChannels{0};

int numPartials_{6};
/// Optimized number of partials for the BSc project
static constexpr int defaultNumPartials{6};

int numPartials_{defaultNumPartials};
std::vector<double> noteFrequencies_; /// Lookup array to determine Midi
/// notes from frequencies.

Expand Down
Loading

0 comments on commit 0ced6ee

Please sign in to comment.