Procházet zdrojové kódy

cmake: build with -Wall -Wextra

Anonymous Maarten před 3 měsíci
rodič
revize
96d3c84b11

+ 1 - 0
.github/workflows/main.yml

@@ -32,6 +32,7 @@ jobs:
           -DCMAKE_BUILD_TYPE=Release \
           -DCMAKE_INSTALL_PREFIX=prefix_cmake \
           -DPHYSFS_INSTALL_MAN=ON \
+          -DPHYSFS_WERROR=ON \
           ${{ matrix.platform.flags }}
     - name: Build (CMake)
       run: |

+ 5 - 0
CMakeLists.txt

@@ -27,6 +27,8 @@ set(PHYSFS_SOVERSION 1)
 set(PHYSFS_M_SRCS)
 set(PHYSFS_CPP_SRCS)
 
+option(PHYSFS_WERROR "Treat warnings as errors" OFF)
+
 if(WIN32)
     list(APPEND OPTIONAL_LIBRARY_LIBS advapi32 shell32)
 endif()
@@ -179,6 +181,7 @@ option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
 if(PHYSFS_BUILD_STATIC)
     add_library(physfs-static STATIC ${PHYSFS_SRCS})
     add_library(PhysFS::PhysFS-static ALIAS physfs-static)
+    sdl_add_warning_options(physfs-static WARNING_AS_ERROR ${PHYSFS_WERROR})
     set_property(TARGET physfs-static PROPERTY EXPORT_NAME PhysFS-static)
     # Don't rename this on Windows, since DLLs will also produce an import
     #  library named "physfs.lib" which would conflict; Unix tend to like the
@@ -205,6 +208,7 @@ option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
 if(PHYSFS_BUILD_SHARED)
     add_library(physfs-shared SHARED ${PHYSFS_SRCS})
     add_library(PhysFS::PhysFS-shared ALIAS physfs-shared)
+    sdl_add_warning_options(physfs-shared WARNING_AS_ERROR ${PHYSFS_WERROR})
     set_property(TARGET physfs-shared PROPERTY OUTPUT_NAME "physfs")
     set_property(TARGET physfs-shared PROPERTY MACOSX_RPATH 1)
     set_property(TARGET physfs-shared PROPERTY VERSION ${PHYSFS_VERSION})
@@ -239,6 +243,7 @@ mark_as_advanced(PHYSFS_BUILD_TEST)
 if(PHYSFS_BUILD_TEST)
     add_executable(test_physfs test/test_physfs.c)
     target_link_libraries(test_physfs PRIVATE PhysFS::PhysFS ${OTHER_LDFLAGS})
+    sdl_add_warning_options(test_physfs WARNING_AS_ERROR ${PHYSFS_WERROR})
 
     find_path(READLINE_H readline/readline.h)
     find_path(HISTORY_H readline/history.h)

+ 1 - 1
extras/PrivateSdlFunctions.cmake

@@ -302,7 +302,7 @@ function(sdl_add_warning_options TARGET)
     if(MSVC)
         target_compile_options(${TARGET} PRIVATE /W2)
     else()
-        target_compile_options(${TARGET} PRIVATE -Wall)
+        target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wno-unused-parameter)
     endif()
     if(ARGS_WARNING_AS_ERROR)
         if(MSVC)