Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# From: https://github.com/cpp-best-practices/cmake_template
additional_commands:
foo:
flags:
- BAR
- BAZ
kwargs:
DEPENDS: '*'
HEADERS: '*'
SOURCES: '*'
bullet_char: '*'
dangle_parens: true
enum_char: .
line_ending: unix
line_width: 120
max_pargs_hwrap: 3
separate_ctrl_name_with_space: false
separate_fn_name_with_space: false
tab_size: 2
autosort: true

markup:
enable_markup: false

lint:
disabled_codes: [C0307, W0105, C0111, E1126]

4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
- name: List Xcode installations
if: matrix.os == 'macos-14'
run: sudo ls -1 /Applications | grep "Xcode"
- name: Select Xcode 16.0
- name: Select Xcode 16.2
if: matrix.os == 'macos-14'
run: sudo xcode-select -s /Applications/Xcode_16.app/Contents/Developer
run: sudo xcode-select -s /Applications/Xcode_16.2.0.app/Contents/Developer
- uses: actions/checkout@v4

- name: Cache dependencies
Expand Down
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: 'v15.0.6' # Use the sha / tag you want to point at
rev: v20.1.0
hooks:
- id: clang-format
files: '.(c|h|hpp|cpp)$'
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: [pyyaml>=5.1]
- id: cmake-lint
additional_dependencies: [pyyaml>=5.1]
47 changes: 29 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Mandatory line, sets the minimum version of CMake that should be used with this repository.
# I specified 3.22 because I trust it. However, currently I have 3.26 installed on my machine.
# To verify your version run
Expand All @@ -21,31 +20,43 @@ set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs)
include(cmake/cpm.cmake)

# This commands downloads AND configures JUCE. It sets up some variables, like JUCE_SOURCE_DIR.
CPMAddPackage(
NAME JUCE
GIT_TAG 8.0.2
VERSION 8.0.2
GITHUB_REPOSITORY juce-framework/JUCE
SOURCE_DIR ${LIB_DIR}/juce
cpmaddpackage(
NAME
JUCE
GIT_TAG
8.0.6
VERSION
8.0.6
GITHUB_REPOSITORY
juce-framework/JUCE
SOURCE_DIR
${LIB_DIR}/juce
)

# Adds googletest.
CPMAddPackage(
NAME GOOGLETEST
GITHUB_REPOSITORY google/googletest
GIT_TAG v1.15.2
VERSION 1.15.2
SOURCE_DIR ${LIB_DIR}/googletest
OPTIONS
"INSTALL_GTEST OFF"
"gtest_force_shared_crt ON"
cpmaddpackage(
NAME
GOOGLETEST
GITHUB_REPOSITORY
google/googletest
VERSION
1.16.0
SOURCE_DIR
${LIB_DIR}/googletest
OPTIONS
"INSTALL_GTEST OFF"
"gtest_force_shared_crt ON"
)

# This command allows running tests from the "build" folder (the one where CMake generates the project to).
enable_testing()
# Add compiler warning utilities
include(cmake/CompilerWarnings.cmake)
include(cmake/Util.cmake)

# Adds all the targets configured in the "plugin" folder.
add_subdirectory(plugin)

# This command allows running tests from the "build" folder (the one where CMake generates the project to).
enable_testing()

# Adds all the targets configured in the "test" folder.
add_subdirectory(test)
15 changes: 13 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"name": "release",
"generator": "Ninja",
"inherits": "default",
"binaryDir": "release-build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
Expand All @@ -38,6 +38,18 @@
{
"name": "default",
"configurePreset": "default"
},
{
"name": "release",
"configurePreset": "release"
},
{
"name": "vs",
"configurePreset": "vs"
},
{
"name": "Xcode",
"configurePreset": "Xcode"
}
],
"testPresets": [
Expand All @@ -64,7 +76,6 @@
"name": "Xcode",
"inherits": "default",
"configurePreset": "Xcode",
// Use Debug by default
"configuration": "Debug"
}
]
Expand Down
106 changes: 106 additions & 0 deletions cmake/CompilerWarnings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# from here:
#
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md

set(MSVC_WARNINGS
/W4 # Baseline reasonable warnings
/w14242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
/w14263 # 'function': member function does not override any base class virtual member function
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may
# not be destructed correctly
/w14287 # 'operator': unsigned/negative constant mismatch
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside
# the for-loop scope
/w14296 # 'operator': expression is always 'boolean_value'
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
/w14545 # expression before comma evaluates to a function which is missing an argument list
/w14546 # function call before comma missing argument list
/w14547 # 'operator': operator before comma has no effect; expected operator with side-effect
/w14549 # 'operator': operator before comma has no effect; did you intend 'operator'?
/w14555 # expression has no effect; expected expression with side- effect
/w14619 # pragma warning: there is no warning number 'number'
/w14640 # Enable warning on thread un-safe static member initialization
/w14826 # Conversion from 'type1' to 'type2' is sign-extended. This may cause unexpected runtime behavior.
/w14905 # wide string literal cast to 'LPSTR'
/w14906 # string literal cast to 'LPWSTR'
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
/permissive- # standards conformance mode for MSVC compiler.
)

set(GCC_CLANG_WARNINGS
-Wall
-Wextra # reasonable and standard
-Wshadow # warn the user if a variable declaration shadows one from a parent context
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps
# catch hard to track down memory errors
-Wold-style-cast # warn for c-style casts
-Wcast-align # warn for potential performance problem casts
-Wunused # warn on anything being unused
-Woverloaded-virtual # warn if you overload (not override) a virtual function
-Wpedantic # warn if non-standard C++ is used
-Wconversion # warn on type conversions that may lose data
-Wsign-conversion # warn on sign conversions
-Wnull-dereference # warn if a null dereference is detected
-Wdouble-promotion # warn if float is implicit promoted to double
-Wformat=2 # warn on security issues around functions that format output (ie printf)
-Wimplicit-fallthrough # warn on statements that fallthrough without an explicit annotation
-Wunused-variable
# flags recommended by JUCE
-Wstrict-aliasing
-Wuninitialized
-Wconversion
-Wsign-compare
-Wunreachable-code
-Wno-ignored-qualifiers
-Wswitch-enum
-Wdeprecated
-Wfloat-equal
-Wmissing-field-initializers
-Wzero-as-null-pointer-constant
-Wreorder
)

set(CLANG_WARNINGS
${GCC_CLANG_WARNINGS}
# flags recommended by JUCE
-Wshadow-all
-Wshorten-64-to-32
-Wconditional-uninitialized
-Wconstant-conversion
-Wbool-conversion
-Wextra-semi
-Wnullable-to-nonnull-conversion
-Wshift-sign-overflow
-Wint-conversion
-Wmissing-prototypes
-Winconsistent-missing-destructor-override
)

set(GCC_WARNINGS
${GCC_CLANG_WARNINGS}
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
-Wduplicated-cond # warn if if / else chain has duplicated conditions
-Wduplicated-branches # warn if if / else branches have duplicated code
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
-Wuseless-cast # warn if you perform a cast to the same type
)

message(TRACE "Warnings are treated as errors")
list(APPEND CLANG_WARNINGS -Werror)
list(APPEND GCC_WARNINGS -Werror)
list(APPEND MSVC_WARNINGS /WX)

if(MSVC)
set(PROJECT_WARNINGS_CXX ${MSVC_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(PROJECT_WARNINGS_CXX ${CLANG_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(PROJECT_WARNINGS_CXX ${GCC_WARNINGS})
else()
message(AUTHOR_WARNING "No compiler warnings set for CXX compiler: '${CMAKE_CXX_COMPILER_ID}'")
# TODO support Intel compiler
endif()

# use the same warning flags for C
set(PROJECT_WARNINGS_C "${PROJECT_WARNINGS_CXX}")
43 changes: 43 additions & 0 deletions cmake/Util.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Links libraries to the given target and marks their include directories as SYSTEM.
# Source:
# https://stackoverflow.com/questions/52135983/
# cmake-target-link-libraries-include-as-system-to-suppress-compiler-warnings
function(target_link_libraries_system target)
set(options PRIVATE PUBLIC INTERFACE)
cmake_parse_arguments(
TLLS
"${options}"
""
""
${ARGN}
)
foreach(op ${options})
if(TLLS_${op})
set(scope ${op})
endif()
endforeach(op)
set(libs ${TLLS_UNPARSED_ARGUMENTS})

foreach(lib ${libs})
get_target_property(lib_include_dirs ${lib} INTERFACE_INCLUDE_DIRECTORIES)
if(lib_include_dirs)
if(scope)
target_include_directories(
${target}
SYSTEM
${scope}
${lib_include_dirs}
)
else()
target_include_directories(${target} SYSTEM PRIVATE ${lib_include_dirs})
endif()
else()
message("Warning: ${lib} doesn't set INTERFACE_INCLUDE_DIRECTORIES. No include_directories set.")
endif()
if(scope)
target_link_libraries(${target} ${scope} ${lib})
else()
target_link_libraries(${target} ${lib})
endif()
endforeach()
endfunction(target_link_libraries_system)
6 changes: 2 additions & 4 deletions cmake/cpm.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(CPM_DOWNLOAD_VERSION 0.40.2)
set(CPM_DOWNLOAD_VERSION 0.40.8)

set(CPM_DOWNLOAD_LOCATION "${LIB_DIR}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")

Expand All @@ -7,8 +7,7 @@ get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endfunction()
Expand All @@ -25,4 +24,3 @@ else()
endif()

include(${CPM_DOWNLOAD_LOCATION})

Loading