File tree Expand file tree Collapse file tree 5 files changed +43
-6
lines changed
Expand file tree Collapse file tree 5 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -8,17 +8,21 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
88# Export compile_commands.json for clangd and clang-tidy
99set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
1010
11- # Add custom "Sanitize" build type for multi-config generators (e.g., Visual Studio)
11+ # Add custom "Sanitize" build type
1212if (CMAKE_CONFIGURATION_TYPES )
1313 list (APPEND CMAKE_CONFIGURATION_TYPES Sanitize)
1414 list (REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES )
1515 set (CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES} " CACHE STRING "" FORCE)
1616endif ()
1717
18- # Load sanitizer flags if needed
18+ # Load sanitizers
1919list (APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR} /cmake" )
2020include (Sanitizers)
2121
22+ # Load warnings
23+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR} /cmake" )
24+ include (Warnings)
25+
2226# === Libraries ===
2327add_subdirectory (src)
2428
@@ -31,13 +35,13 @@ target_link_libraries(${PROJECT_NAME}
3135 PRIVATE arithmetic
3236)
3337
38+ enable_strict_warnings(${PROJECT_NAME} )
3439target_link_with_sanitizers(${PROJECT_NAME} )
3540
3641# === Unit Testing ===
3742option (ENABLE_TESTING "Build tests" ON )
3843
3944if (ENABLE_TESTING)
40- message (STATUS "✅ Enabled unit tests" )
4145 enable_testing ()
4246 add_subdirectory (tests)
4347endif ()
Original file line number Diff line number Diff line change @@ -10,13 +10,12 @@ if(CMAKE_BUILD_TYPE STREQUAL "Sanitize")
1010 add_library (sanitizers INTERFACE )
1111 target_compile_options (sanitizers INTERFACE ${SANITIZER_FLAGS} )
1212 target_link_options (sanitizers INTERFACE ${SANITIZER_FLAGS} )
13-
1413 message (STATUS "✅ Sanitize build: enabled with flags: ${SANITIZER_FLAGS} " )
1514endif ()
1615
1716function (target_link_with_sanitizers target )
1817 if (TARGET sanitizers)
19- message ( STATUS "✅ Enabled sanitizers for target ${target} " )
20- target_link_libraries ( ${target} PRIVATE sanitizers )
18+ target_link_libraries ( ${target} PRIVATE sanitizers )
19+ message ( STATUS "✅ Enabled sanitizers for target ${target} " )
2120 endif ()
2221endfunction ()
Original file line number Diff line number Diff line change 1+ # Standard warnings
2+ add_library (warnings INTERFACE )
3+
4+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU" )
5+ target_compile_options (warnings INTERFACE
6+ -Wall
7+ -Wextra
8+ -Wpedantic
9+ -Wconversion
10+ -Wsign-conversion
11+ )
12+ endif ()
13+
14+ # Warnings as errors
15+ add_library (strict_warnings INTERFACE )
16+
17+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU" )
18+ target_compile_options (strict_warnings INTERFACE -Werror)
19+ target_link_libraries (strict_warnings PRIVATE warnings)
20+ endif ()
21+
22+ # Function to apply warnings
23+ function (enable_warnings target )
24+ target_link_libraries (${target} PRIVATE warnings)
25+ message (STATUS "⚠️ Enabled warnings for target ${target} " )
26+ endfunction ()
27+
28+ # Function to apply warnings as errors
29+ function (enable_strict_warnings target )
30+ target_link_libraries (${target} PRIVATE strict_warnings)
31+ message (STATUS "⚠️ Enabled warnings as errors for target ${target} " )
32+ endfunction ()
Original file line number Diff line number Diff line change @@ -6,4 +6,5 @@ target_include_directories(arithmetic
66 PUBLIC ${PROJECT_SOURCE_DIR} /include
77)
88
9+ enable_strict_warnings(arithmetic)
910target_link_with_sanitizers(arithmetic)
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ target_link_libraries(unit_tests
2222 PRIVATE gtest_main arithmetic
2323)
2424
25+ enable_warnings(unit_tests)
2526target_link_with_sanitizers(unit_tests)
2627
2728# Automatically discover and register all test cases
You can’t perform that action at this time.
0 commit comments