diff --git a/cmake/SetCompilerOptions.cmake b/cmake/SetCompilerOptions.cmake index 366be1f3666..02b425b785c 100644 --- a/cmake/SetCompilerOptions.cmake +++ b/cmake/SetCompilerOptions.cmake @@ -32,107 +32,79 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) list( APPEND CFLAGS + -fdiagnostics-color=auto -fno-math-errno -fno-signed-zeros + -fno-tree-vectorize + -mstack-alignment=16 -Wall - -Wcast-qual - -Wdeclaration-after-statement -Wextra - -Wno-pointer-to-int-cast - -Wpedantic + -Wduplicated-branches + -Wduplicated-cond + -Werror=format-security + -Werror=implicit-function-declaration + -Werror=return-type + -Werror=vla + -Wjump-misses-init + -Wlogical-op + -Wnull-dereference -Wpointer-arith - -Wredundant-decls - -Wredundant-decls - -Wstrict-prototypes - -Wundef -Wwrite-strings) list( APPEND CXXFLAGS + -faligned-new + -fdiagnostics-color=auto -fno-math-errno -fno-signed-zeros + -fno-tree-vectorize + -funit-at-a-time + -mstack-alignment=16 + -Qunused-arguments -Wall -Wextra + # -Wdouble-promotion + -Wduplicated-cond + -Werror=format-security + -Werror=implicit-function-declaration + -Werror=return-type + -Werror=vla + -Wimplicit-fallthrough + -Wjump-misses-init + -Wlogical-op + -Wmissing-declarations + -Wnull-dereference + -Woverloaded-virtual -Wpointer-arith - -Wundef) - -if(ENABLE_LTO AND NOT CMAKE_CROSSCOMPILING) - list(APPEND CFLAGS -flto) - list(APPEND CXXFLAGS -flto) - list(APPEND LFLAGS -flto) -endif() - + -Wredundant-decls + -Wsuggest-override + -Wundef + # -Wall flags to disable + -Wno-unknown-pragmas # gcc doesn't recognize clang pragmas +) if(NOT ANDROID) list(APPEND CXXFLAGS "-Wshadow") endif() -if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") - list(APPEND CFLAGS -Wmissing-prototypes -Werror=missing-prototypes) -endif() - # # Add compiler specific flags. # if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - list( - APPEND - CFLAGS - -fdiagnostics-color=auto - -fno-tree-vectorize - -Wdouble-promotion - -Wduplicated-cond - -Wduplicated-branches - -Werror=format-security - -Werror=implicit-function-declaration - -Werror=return-type - -Werror=vla - -Wjump-misses-init - -Wlogical-op - -Wnull-dereference) - - list( - APPEND - CXXFLAGS - -faligned-new - -funit-at-a-time - -Wdouble-promotion - -Wduplicated-cond - -Wlogical-op - -Wmissing-declarations - -Wnull-dereference - -Woverloaded-virtual - -Wzero-as-null-pointer-constant) + list(APPEND CXXFLAGS -Wzero-as-null-pointer-constant) # This warning flag isn't enabled yet because it will require a large number # of changes to the code to eliminate all the warnings. - # add_compile_options($<${gnu_cxx}:$>) + # + # list(APPEND CXXFLAGS -Wold-style-cast) # This warning flag can't be enabled because the Qt5 moc compiler produces # files that contain "useless" casts. - # add_compile_options($<${gnu_cxx}:$>) - - # The Q_OBJECT macro gets included in every subclass that is based on QOBject, - # and has a couple of functions marked as "virtual" instead of "override". - # Apparently earlier version of GCC didn't warn about this because the errors - # were in the /usr/include directory. GCC11 does print these warnings. A ton - # of them. Disable this warning to make it easier to find real errors. - if(CXX_COMPILER_VERSION VERSION_LESS 11.0.0) - list(APPEND CXXFLAGS -Wsuggest-override) - endif() + # + # list(APPEND CXXFLAGS -Wuseless-cast) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - list( - APPEND - CFLAGS - -mllvm - -mstack-alignment=16 - -Qunused-arguments - -Werror=implicit-function-declaration - -Werror=return-type - -Wimplicit-fallthrough) - # The constant-logical-operand only gives use false positives for constant # logical operands meant to be optimized away. list(APPEND CXXFLAGS -Wno-constant-logical-operand) @@ -142,9 +114,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # lets rely on other compilers to report on unused values. list(APPEND CXXFLAGS -Wno-unused-value) - # clang complains about every unused -I unless you pass it this. - list(APPEND CXXFLAGS -Qunused-arguments) - # Clang on FreeBSD doesn't ignore warnings in system headers. A trivial test # shows that Clang defaults /usr/local/include to a system directory, but # somehow this gets messed up in MythTV builds. @@ -156,6 +125,12 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") endif() +if(ENABLE_LTO AND NOT CMAKE_CROSSCOMPILING) + list(APPEND CFLAGS -flto) + list(APPEND CXXFLAGS -flto) + list(APPEND LFLAGS -flto=auto) +endif() + # # Now test each flag and see if its valid. # diff --git a/mythtv/external/libmythdvdnav/CMakeLists.txt b/mythtv/external/libmythdvdnav/CMakeLists.txt index bc152c070e8..2dd6bdfce9e 100644 --- a/mythtv/external/libmythdvdnav/CMakeLists.txt +++ b/mythtv/external/libmythdvdnav/CMakeLists.txt @@ -4,6 +4,8 @@ # See the file LICENSE_FSF for licensing information. # +# This is set up to be a separate sub-project, but is currently +# included by the MythTV sub-project. project( DVDREAD VERSION 6.0.0 @@ -12,6 +14,17 @@ project( include(CheckIncludeFile) include(CheckSymbolExists) +# Remove some of the compilation flags that were added to MythTV by +# the -Wall flag. +string(APPEND CMAKE_C_FLAGS " -Wno-maybe-uninitialized") +string(APPEND CMAKE_C_FLAGS " -Wno-unneeded-internal-declaration") # clang +string(APPEND CMAKE_C_FLAGS " -Wno-unused-but-set-variable") +string(APPEND CMAKE_C_FLAGS " -Wno-unused-variable") +# Remove some of the compilation flags that were added to MythTV by +# the -Wextra flag. +string(APPEND CMAKE_C_FLAGS " -Wno-implicit-fallthrough") +string(APPEND CMAKE_C_FLAGS " -Wno-unused-parameter") + # # Compile this library as a static library on Android because of the circular # linking dependency issue with libmythtv (specifically the calls to the diff --git a/mythtv/libs/libmythmpeg2/CMakeLists.txt b/mythtv/libs/libmythmpeg2/CMakeLists.txt index 40c9a98c9d4..a0ccbbb800a 100644 --- a/mythtv/libs/libmythmpeg2/CMakeLists.txt +++ b/mythtv/libs/libmythmpeg2/CMakeLists.txt @@ -4,6 +4,10 @@ # See the file LICENSE_FSF for licensing information. # +# Remove some of the compilation flags that were added to MythTV by +# the -Wextra flag. +string(APPEND CMAKE_C_FLAGS " -Wno-implicit-fallthrough") + # # Declare the library #