Skip to content

Commit d7fb17b

Browse files
committed
build(error): modify declaration on how to check for warnings
1 parent 94c9734 commit d7fb17b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

error/CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@ cmake_minimum_required(VERSION 3.0)
22

33
project(error)
44

5-
if(MSVC)
6-
set(WARNING_FLAGS /WX /permissive- /W4 /w14640 /EHsc)
7-
else()
8-
set(WARNING_FLAGS -WError -Wall -Wextra -Wnon-virtual-dtor -Wpedantic)
9-
endif()
10-
115
include(cmake/CPM.cmake)
126

137
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
148
cpmaddpackage("gh:TheLartians/Format.cmake@1.7.3")
159
set(SUPPORT_TESTING TRUE)
10+
set(CHECK_WARNINGS TRUE)
1611
endif()
1712

1813
if(SUPPORT_TESTING AND BUILD_TESTING)
@@ -33,11 +28,21 @@ cpmaddpackage("gh:fmtlib/fmt#10.0.0")
3328
add_library(error src/error.cpp)
3429
target_include_directories(error PUBLIC include)
3530
target_link_libraries(error PUBLIC fmt)
36-
target_compile_options(error PRIVATE ${WARNING_FLAGS})
3731

3832
if(SUPPORT_TESTING AND BUILD_TESTING)
3933
add_executable(error_test test/error_test.cpp)
4034
target_link_libraries(error_test PRIVATE error Catch2::Catch2WithMain)
41-
target_compile_options(error_test PRIVATE ${WARNING_FLAGS})
4235
catch_discover_tests(error_test)
4336
endif()
37+
38+
set(TARGETS error error_test)
39+
foreach(TARGET IN LISTS TARGETS)
40+
# Statically analyze code by checking for warnings.
41+
if(CHECK_WARNINGS)
42+
if(MSVC)
43+
target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc)
44+
else()
45+
target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic)
46+
endif()
47+
endif()
48+
endforeach()

0 commit comments

Comments
 (0)