Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress warnings in third-party code #7319

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
94 changes: 61 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function(enable_policy_if_exists id)
endif()
endfunction()

# Needed for the SWH Ladspa plugins. See below.
enable_policy_if_exists(CMP0074) # find_package() uses <PackageName>_ROOT variables.
enable_policy_if_exists(CMP0092) # MSVC warning flags are not in CMAKE_<LANG>_FLAGS by default.
# Needed for ccache support with MSVC
enable_policy_if_exists(CMP0141) # MSVC debug information format flags are selected by an abstraction.

Expand All @@ -43,6 +42,7 @@ INCLUDE(AddFileDependencies)
INCLUDE(CheckIncludeFiles)
INCLUDE(FindPkgConfig)
INCLUDE(GenerateExportHeader)
include(StaticDependencies)

STRING(TOUPPER "${CMAKE_PROJECT_NAME}" PROJECT_NAME_UCASE)

Expand Down Expand Up @@ -491,11 +491,9 @@ ENDIF(NOT LMMS_HAVE_ALSA)
IF(WANT_JACK)
IF(WANT_WEAKJACK)
SET(LMMS_HAVE_WEAKJACK TRUE)
SET(WEAKJACK_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/3rdparty/weakjack/weakjack)
SET(JACK_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/3rdparty/jack2/common)
SET(STATUS_JACK "OK (weak linking enabled)")
# use dlsym instead
SET(JACK_LIBRARIES ${CMAKE_DL_LIBS})
set(JACK_INCLUDE_DIRS "")
set(JACK_LIBRARIES weakjack)
SET(LMMS_HAVE_JACK TRUE)
SET(LMMS_HAVE_JACK_PRENAME TRUE)
SET(JACK_FOUND TRUE)
Expand Down Expand Up @@ -631,28 +629,63 @@ ENDIF(WANT_DEBUG_FPE)
# check for libsamplerate
FIND_PACKAGE(Samplerate 0.1.8 MODULE REQUIRED)

# set compiler flags
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
SET(WERROR_FLAGS "-Wall -Werror=unused-function -Wno-sign-compare -Wno-strict-overflow")
OPTION(USE_WERROR "Add -werror to the build flags. Stops the build on warnings" OFF)
IF(${USE_WERROR})
SET(WERROR_FLAGS "${WERROR_FLAGS} -Werror")
ENDIF()
# Shim the SYSTEM property for older CMake versions
if(CMAKE_VERSION VERSION_LESS "3.25")
define_property(TARGET
PROPERTY SYSTEM
INHERITED
BRIEF_DOCS "Shim of built-in SYSTEM property for CMake versions less than 3.25"
FULL_DOCS "Non-functional, but allows the property to be inherited properly."
"See the CMake documentation at https://cmake.org/cmake/help/latest/prop_tgt/SYSTEM.html."
)
endif()

# Add warning and error flags
option(USE_WERROR "Treat compiler warnings as errors" OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(COMPILE_ERROR_FLAGS
"-Wall" # Enable most warnings by default
"-Werror=unused-function" # Unused functions are an error
# TODO: Fix the code and remove the following:
"-Wno-sign-compare" # Permit comparisons between signed and unsigned integers
"-Wno-strict-overflow" # Permit optimisations assuming no signed overflow
)
set(THIRD_PARTY_COMPILE_ERROR_FLAGS
"-w" # Disable all warnings
)

# Due to a regression in gcc-4.8.X, we need to disable array-bounds check
IF (CMAKE_COMPILER_IS_GNUCXX AND ((CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.8.0") OR (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8.0") OR LMMS_BUILD_WIN32))
SET(WERROR_FLAGS "${WERROR_FLAGS} -Wno-array-bounds -Wno-attributes")
ENDIF()
ELSEIF(MSVC)
# Remove any existing /W flags
string(REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
STRING(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
SET(WERROR_FLAGS "/W2")
IF(${USE_WERROR})
SET(WERROR_FLAGS "${WERROR_FLAGS} /WX")
ENDIF()
ENDIF()
# TODO: Is this still necessary?
if(CMAKE_COMPILER_IS_GNUCXX)
list(APPEND COMPILE_ERROR_FLAGS
"-Wno-array-bounds" # Permit out-of-bounds array subscripts
"-Wno-attributes" # Permit unrecognised attributes
)
endif()

if(USE_WERROR)
list(APPEND COMPILE_ERROR_FLAGS
"-Werror" # Treat warnings as errors
)
endif()
elseif(MSVC)
set(COMPILE_ERROR_FLAGS
"/W2" # Enable some warnings by default
"/external:W0" # Don't emit warnings for third-party code
"/external:anglebrackets" # Consider headers included with angle brackets to be third-party
"/external:templates-" # Still emit warnings from first-party instantiations of third-party templates
)
set(THIRD_PARTY_COMPILE_ERROR_FLAGS
"/W0" # Disable all warnings
)

if(USE_WERROR)
list(APPEND COMPILE_ERROR_FLAGS
"/WX" # Treat warnings as errors
)
endif()
endif()
add_compile_options("$<IF:$<BOOL:$<TARGET_PROPERTY:SYSTEM>>,${THIRD_PARTY_COMPILE_ERROR_FLAGS},${COMPILE_ERROR_FLAGS}>")

IF(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
Expand All @@ -662,8 +695,6 @@ IF(NOT CMAKE_BUILD_TYPE)
"MinSizeRel" "RelWithDebInfo")
ENDIF()

SET(CMAKE_C_FLAGS "${WERROR_FLAGS} ${CMAKE_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${WERROR_FLAGS} ${CMAKE_CXX_FLAGS}")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DLMMS_DEBUG")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DLMMS_DEBUG")

Expand Down Expand Up @@ -705,12 +736,9 @@ ENDIF()
# we somehow have to make LMMS-binary depend on MOC-files
ADD_FILE_DEPENDENCIES("${CMAKE_BINARY_DIR}/lmmsconfig.h")

IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
IF(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes")
ELSE(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DPIC")
ENDIF(WIN32)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -DPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DPIC")
elseif(MSVC)
# Use UTF-8 as the source and execution character set
add_compile_options("/utf-8")
Expand Down
141 changes: 141 additions & 0 deletions cmake/modules/StaticDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# StaticLinking.cmake - adds features similar to interface properties that are
# only transitive over static dependencies.
#
# Copyright (c) 2024 Dominic Clark
#
# Redistribution and use is allowed according to the terms of the New BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

define_property(TARGET
PROPERTY STATIC_COMPILE_DEFINITIONS
BRIEF_DOCS "Compile definitions to be used by targets linking statically to this one"
FULL_DOCS "Behaves similarly to INTERFACE_COMPILE_DEFINITIONS, but only over static dependencies."
"Effectively becomes private once an executable module is reached."
)

define_property(TARGET
PROPERTY STATIC_LINK_LIBRARIES
BRIEF_DOCS "Link libraries to be included in targets linking statically to this one"
FULL_DOCS "Behaves similarly to INTERFACE_LINK_LIBRARIES, but only over static dependencies."
"Effectively becomes private once an executable module is reached."
)

# Link a target statically to a set of libraries. Forward the given arguments to
# `target_link_libraries`, but also perform two additional functions. Firstly,
# ensure that the given libraries will be linked into any module that also
# links the given target (allowing, for example, object libraries and private
# static libraries to be used transitively). Secondly, add any static compile
# definitions from the given libraries to the set of compile definitions used
# to build the given target.
#
# This function must be used in order for static requirements as defined in this
# module to be inherited transitively. Using `target_link_libraries` instead
# will break the chain for static link libraries and static compile definitions.
#
# Usage:
# target_static_libraries(
# <target> # The target to which to add the libraries
# [<PRIVATE|PUBLIC|INTERFACE>] # Optionally, the scope to use for the following libraries
# <item>... # The libraries to which to link
# [<PRIVATE|PUBLIC|INTERFACE> <item>...]...
# )
function(target_static_libraries target)
# Target types that have a link step
set(linked_target_types "MODULE_LIBRARY" "SHARED_LIBRARY" "EXECUTABLE")
# Possible scopes for dependencies
set(scopes "PRIVATE" "PUBLIC" "INTERFACE")

get_target_property(target_type "${target}" TYPE)
set(scope "")

# Iterate over the dependencies (and possibly scopes) that we were given
foreach(dependency IN LISTS ARGN)
# If we have a scope, store it so we can apply it to upcoming libraries
if(dependency IN_LIST scopes)
set(scope "${dependency}")
continue()
endif()

# Link the target to the current dependency. (Note: `${scope}` is
# unquoted so that the argument disappears if no scope was given.)
target_link_libraries("${target}" ${scope} "${dependency}")

# Store the dependency so it can be linked in with this target later
set_property(
TARGET "${target}"
APPEND
PROPERTY STATIC_LINK_LIBRARIES
"${dependency}"
)

# If the dependency is a target, it may have some of our custom
# properties defined on it, so we have a bit more work to do
if(TARGET "${dependency}")
# Ensure it makes sense to link statically to this dependency
get_target_property(dependency_type "${dependency}" TYPE)
if(dependency_type IN_LIST linked_target_types)
message(SEND_ERROR "Cannot link statically to shared module ${dependency}")
endif()

# Transitively include static definitions and libraries
set(defs "$<TARGET_GENEX_EVAL:${dependency},$<TARGET_PROPERTY:${dependency},STATIC_COMPILE_DEFINITIONS>>")
set(libs "$<TARGET_GENEX_EVAL:${dependency},$<TARGET_PROPERTY:${dependency},STATIC_LINK_LIBRARIES>>")
set_property(
TARGET "${target}"
APPEND
PROPERTY STATIC_COMPILE_DEFINITIONS
"${defs}"
)
set_property(
TARGET "${target}"
APPEND
PROPERTY STATIC_LINK_LIBRARIES
"${libs}"
)

# Add the dependency's transitive static compile definitions.
# (Note: definitions are private so dynamically linked dependents
# won't pick them up; a static dependent will have them set when
# this function is called for it.)
target_compile_definitions("${target}" PRIVATE "${defs}")

# If the target has a link step, add the transitive static
# dependencies. (Note: we use `LINK_ONLY` so the caller can still
# control usage requirements through the normal use of scopes. Only
# transitive dependencies are needed here: the direct dependency was
# added earlier on. We have to append to `LINK_LIBRARIES` directly,
# rather than use `target_link_libraries(PRIVATE)`, in order to
# remain compatible with the scopeless signature of that command.)
if(target_type IN_LIST linked_target_types)
set_property(
TARGET "${target}"
APPEND
PROPERTY LINK_LIBRARIES
"$<LINK_ONLY:${libs}>"
)
endif()
endif()
endforeach()
endfunction()

# Add compile definitions to a target only for use with dependents linking
# statically to it.
#
# Behaves like `target_compile_definitions(INTERFACE)`, except the definitions
# will not be inherited beyond any executable module into which the target is
# actually linked. The definitions are added to the `STATIC_COMPILE_DEFINITIONS`
# property on the target.
#
# Usage:
# target_static_definitions(
# <target> # The target to which to add the definitions
# <definition>... # The definitions to add to the target
# )
function(target_static_definitions target)
set_property(
TARGET "${target}"
APPEND
PROPERTY STATIC_COMPILE_DEFINITIONS
"${ARGN}"
)
endfunction()
2 changes: 1 addition & 1 deletion include/AudioJack.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef LMMS_HAVE_WEAKJACK
#include <jack/jack.h>
#else
#include "weak_libjack.h"
#include <weak_libjack.h>
#endif

#include <atomic>
Expand Down
4 changes: 2 additions & 2 deletions include/LocklessRingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#include <QMutex>
#include <QWaitCondition>

#include "lmms_basics.h"
#include "../src/3rdparty/ringbuffer/include/ringbuffer/ringbuffer.h"
#include <ringbuffer/ringbuffer.h>

#include "lmms_basics.h"

namespace lmms
{
Expand Down
3 changes: 2 additions & 1 deletion include/Lv2Proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
#include <memory>
#include <optional>

#include <ringbuffer/ringbuffer.h>

#include "LinkedModelGroups.h"
#include "LmmsSemaphore.h"
#include "Lv2Basics.h"
#include "Lv2Features.h"
#include "Lv2Options.h"
#include "Lv2Worker.h"
#include "Plugin.h"
#include "../src/3rdparty/ringbuffer/include/ringbuffer/ringbuffer.h"
#include "TimePos.h"


Expand Down
2 changes: 1 addition & 1 deletion include/MidiJack.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <jack/jack.h>
#include <jack/midiport.h>
#else
#include "weak_libjack.h"
#include <weak_libjack.h>
#endif

#include <QThread>
Expand Down
2 changes: 1 addition & 1 deletion plugins/CarlaBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(LMMS_HAVE_WEAKCARLA)
SET(CARLA_NATIVE_LIB carla_native-plugin)

ADD_LIBRARY(${CARLA_NATIVE_LIB} SHARED DummyCarla.cpp)
TARGET_INCLUDE_DIRECTORIES(${CARLA_NATIVE_LIB} PUBLIC ${CARLA_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES(${CARLA_NATIVE_LIB} SYSTEM PUBLIC ${CARLA_INCLUDE_DIRS})
INSTALL(TARGETS ${CARLA_NATIVE_LIB}
LIBRARY DESTINATION "${PLUGIN_DIR}/optional"
RUNTIME DESTINATION "${PLUGIN_DIR}/optional"
Expand Down
10 changes: 5 additions & 5 deletions plugins/CarlaBase/Carla.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@

// carla/source/includes
#include "carlabase_export.h"
#include "CarlaDefines.h"
#include <CarlaDefines.h>
#if CARLA_VERSION_HEX >= 0x010911
#include "CarlaNativePlugin.h"
#include <CarlaNativePlugin.h>
#else
#include "CarlaBackend.h"
#include "CarlaNative.h"
#include "CarlaUtils.h"
#include <CarlaBackend.h>
#include <CarlaNative.h>
#include <CarlaUtils.h>
CARLA_EXPORT
const NativePluginDescriptor* carla_get_native_patchbay_plugin();

Expand Down
2 changes: 1 addition & 1 deletion plugins/CarlaBase/DummyCarla.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// A dummy Carla interface
#define BUILDING_CARLA
#include "CarlaNativePlugin.h"
#include <CarlaNativePlugin.h>

#ifndef CARLA_PLUGIN_EXPORT
#define CARLA_PLUGIN_EXPORT CARLA_EXPORT
Expand Down
25 changes: 12 additions & 13 deletions plugins/FreeBoy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
INCLUDE(BuildPlugin)
INCLUDE_DIRECTORIES(game-music-emu/gme)
include(BuildPlugin)

BUILD_PLUGIN(freeboy
FreeBoy.cpp
FreeBoy.h
GbApuWrapper.cpp
GbApuWrapper.h
add_library(gme STATIC
game-music-emu/gme/Gb_Apu.cpp
game-music-emu/gme/Gb_Apu.h
game-music-emu/gme/Gb_Oscs.cpp
game-music-emu/gme/Blip_Buffer.cpp
game-music-emu/gme/Gb_Oscs.h
game-music-emu/gme/blargg_common.h
game-music-emu/gme/Blip_Buffer.h
game-music-emu/gme/Multi_Buffer.cpp
game-music-emu/gme/blargg_source.h
game-music-emu/gme/Multi_Buffer.h
)
target_include_directories(gme PUBLIC game-music-emu/gme)
set_target_properties(gme PROPERTIES SYSTEM TRUE)

build_plugin(freeboy
FreeBoy.cpp
FreeBoy.h
GbApuWrapper.cpp
GbApuWrapper.h
MOCFILES FreeBoy.h
EMBEDDED_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.png"
)
target_link_libraries(freeboy gme)
Loading
Loading