diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a6d97e8d..74b6d73b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -630,73 +630,6 @@ ENDIF(WANT_DEBUG_FPE) # check for libsamplerate FIND_PACKAGE(Samplerate 0.1.8 MODULE REQUIRED) -# 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 - ) - set(THIRD_PARTY_COMPILE_ERROR_FLAGS - "-w" # Disable all warnings - ) - - if(CMAKE_COMPILER_IS_GNUCXX) - list(APPEND COMPILE_ERROR_FLAGS - # The following warning generates false positives that are difficult - # to work around, in particular when inlining calls to standard - # algorithms performed on single-element arrays. See, for example, - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111273. - "-Wno-array-bounds" # Permit out-of-bounds array subscripts - ) - - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11") - list(APPEND COMPILE_ERROR_FLAGS - # This has the same problems described above for "array-bounds". - "-Wno-stringop-overread" # Permit string functions overreading the source - ) - endif() - 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 - # Silence "class X needs to have DLL-interface to be used by clients of - # class Y" warnings. These aren't trivial to address, and don't pose a - # problem for us since we build all modules with the same compiler and - # options, and dynamically link the CRT. - "/wd4251" - ) - 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("$>,${THIRD_PARTY_COMPILE_ERROR_FLAGS},${COMPILE_ERROR_FLAGS}>") - IF(NOT CMAKE_BUILD_TYPE) message(STATUS "Setting build type to 'Release' as none was specified.") set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) @@ -778,6 +711,8 @@ add_sanitizer(memory "Clang" WANT_DEBUG_MSAN STATUS_DEBUG_MSAN -fno-omit-frame-p # not being found by PeakController add_sanitizer(undefined "GNU|Clang" WANT_DEBUG_UBSAN STATUS_DEBUG_UBSAN -fno-sanitize=vptr) +# Add warning and error flags +include(ErrorFlags) # use ccache include(CompileCache) diff --git a/cmake/modules/ErrorFlags.cmake b/cmake/modules/ErrorFlags.cmake new file mode 100644 index 000000000..57cc6ad49 --- /dev/null +++ b/cmake/modules/ErrorFlags.cmake @@ -0,0 +1,72 @@ +# Shim the SYSTEM property for older CMake versions - we rely on this property +# to determine which set of error flags to use. +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() + +# Allow the user to control whether to treat warnings as errors +option(USE_WERROR "Treat compiler warnings as errors" OFF) + +# Compute the appropriate flags for the current compiler and options +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + set(COMPILE_ERROR_FLAGS + "-Wall" # Enable most warnings by default + ) + set(THIRD_PARTY_COMPILE_ERROR_FLAGS + "-w" # Disable all warnings + ) + + if(CMAKE_COMPILER_IS_GNUCXX) + list(APPEND COMPILE_ERROR_FLAGS + # The following warning generates false positives that are difficult + # to work around, in particular when inlining calls to standard + # algorithms performed on single-element arrays. See, for example, + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111273. + "-Wno-array-bounds" # Permit out-of-bounds array subscripts + ) + + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11") + list(APPEND COMPILE_ERROR_FLAGS + # This has the same problems described above for "array-bounds". + "-Wno-stringop-overread" # Permit string functions overreading the source + ) + endif() + 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 + # Silence "class X needs to have DLL-interface to be used by clients of + # class Y" warnings. These aren't trivial to address, and don't pose a + # problem for us since we build all modules with the same compiler and + # options, and dynamically link the CRT. + "/wd4251" + ) + 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 the flags to the whole directory tree. We use the third-party flags for +# targets whose SYSTEM property is true, and the normal flags otherwise. +add_compile_options("$>,${THIRD_PARTY_COMPILE_ERROR_FLAGS},${COMPILE_ERROR_FLAGS}>") diff --git a/plugins/VstBase/CMakeLists.txt b/plugins/VstBase/CMakeLists.txt index 046f515ea..15d47200c 100644 --- a/plugins/VstBase/CMakeLists.txt +++ b/plugins/VstBase/CMakeLists.txt @@ -33,6 +33,7 @@ set(export_variables "LMMS_BUILD_WIN32" "PLUGIN_DIR" "LMMS_HAVE_LIBRT" + "USE_WERROR" ) SET(EXTERNALPROJECT_CMAKE_ARGS diff --git a/plugins/VstBase/RemoteVstPlugin.cpp b/plugins/VstBase/RemoteVstPlugin.cpp index 62cb7cfe5..f8bf39a37 100644 --- a/plugins/VstBase/RemoteVstPlugin.cpp +++ b/plugins/VstBase/RemoteVstPlugin.cpp @@ -842,7 +842,6 @@ void RemoteVstPlugin::initEditor() #endif #else - XEvent e; Atom prop_atom, val_atom; if (m_display == nullptr) @@ -2301,7 +2300,7 @@ void RemoteVstPlugin::guiEventLoop() { XNextEvent(m_display, &e); - if (e.type == ClientMessage && e.xclient.data.l[0] == m_wmDeleteMessage) + if (e.type == ClientMessage && static_cast(e.xclient.data.l[0]) == m_wmDeleteMessage) { hideEditor(); } diff --git a/plugins/VstBase/RemoteVstPlugin/CMakeLists.txt b/plugins/VstBase/RemoteVstPlugin/CMakeLists.txt index dd15bb0bd..3f861e2d5 100644 --- a/plugins/VstBase/RemoteVstPlugin/CMakeLists.txt +++ b/plugins/VstBase/RemoteVstPlugin/CMakeLists.txt @@ -1,4 +1,9 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) + +if(POLICY "CMP0092") + cmake_policy(SET CMP0092 NEW) # MSVC warning flags are not in CMAKE__FLAGS by default. +endif() + project(RemoteVstPlugin LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) @@ -22,6 +27,9 @@ FOREACH( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) SET("CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") ENDFOREACH() +# Add warning and error flags +include(ErrorFlags) + # Import of windows.h breaks min()/max() add_definitions(-DNOMINMAX)