Browse Source

Added cmake flag for warnings as errors

Paul-Louis Ageneau 5 years ago
parent
commit
b44f90b87f

+ 2 - 2
.github/workflows/build-gnutls.yml

@@ -16,7 +16,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_GNUTLS=1
+      run: cmake -B build -DUSE_GNUTLS=1 -DWARNINGS_AS_ERRORS=1
     - name: make
       run: (cd build; make -j2)
     - name: test
@@ -30,7 +30,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_GNUTLS=1
+      run: cmake -B build -DUSE_GNUTLS=1 -DWARNINGS_AS_ERRORS=1
     - name: make
       run: (cd build; make -j2)
     - name: test

+ 1 - 1
.github/workflows/build-nice.yml

@@ -16,7 +16,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_GNUTLS=1 -DUSE_NICE=1
+      run: cmake -B build -DUSE_GNUTLS=1 -DUSE_NICE=1 -DWARNINGS_AS_ERRORS=1
     - name: make
       run: (cd build; make -j2)
     - name: test

+ 3 - 3
.github/workflows/build-openssl.yml

@@ -16,7 +16,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_GNUTLS=0
+      run: cmake -B build -DUSE_GNUTLS=0 -DWARNINGS_AS_ERRORS=1
     - name: make
       run: (cd build; make -j2)
     - name: test
@@ -30,7 +30,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -DUSE_GNUTLS=0
+      run: cmake -B build -DUSE_GNUTLS=0 -WARNINGS_AS_ERRORS=1
       env:
         OPENSSL_ROOT_DIR: /usr/local/opt/openssl
         OPENSSL_LIBRARIES: /usr/local/opt/openssl/lib
@@ -48,7 +48,7 @@ jobs:
     - name: submodules
       run: git submodule update --init --recursive
     - name: cmake
-      run: cmake -B build -G "NMake Makefiles" -DUSE_GNUTLS=0
+      run: cmake -B build -G "NMake Makefiles" -DUSE_GNUTLS=0 -WARNINGS_AS_ERRORS=1
     - name: nmake
       run: |
         cd build

+ 14 - 7
CMakeLists.txt

@@ -11,6 +11,7 @@ option(USE_SRTP "Enable SRTP for media support" OFF)
 option(NO_WEBSOCKET "Disable WebSocket support" OFF)
 option(NO_EXAMPLES "Disable examples" OFF)
 option(NO_TESTS "Disable tests build" OFF)
+option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
 
 if(USE_NICE)
 	option(USE_JUICE "Use libjuice" OFF)
@@ -214,13 +215,19 @@ add_library(LibDataChannel::LibDataChannelStatic ALIAS datachannel-static)
 install(TARGETS datachannel LIBRARY DESTINATION lib)
 install(FILES ${LIBDATACHANNEL_HEADERS} DESTINATION include/rtc)
 
-# Warnings as errors
-if(MSVC)
-  target_compile_options(datachannel PRIVATE /WX)
-  target_compile_options(datachannel-static PRIVATE /WX)
-else()
-  target_compile_options(datachannel PRIVATE -Wall -Wextra -Werror)
-  target_compile_options(datachannel-static PRIVATE -Wall -Wextra -Werror)
+if(NOT MSVC)
+	target_compile_options(datachannel PRIVATE -Wall -Wextra)
+	target_compile_options(datachannel-static PRIVATE -Wall -Wextra)
+endif()
+
+if(WARNINGS_AS_ERRORS)
+	if(MSVC)
+		target_compile_options(datachannel PRIVATE /WX)
+		target_compile_options(datachannel-static PRIVATE /WX)
+	else()
+		target_compile_options(datachannel PRIVATE -Werror)
+		target_compile_options(datachannel-static PRIVATE -Werror)
+	endif()
 endif()
 
 # Tests