@@ -13,8 +13,15 @@ target_link_libraries(error PUBLIC fmt)
1313
1414# Check if this project is the main project
1515if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR )
16+ option (CHECK_FORMAT "Enable source code formatting check" OFF )
17+ option (CHECK_WARNING "Enable static analysis warning check" OFF )
18+ option (CHECK_COVERAGE "Enable test coverage check" OFF )
19+
1620 # Import Format.cmake to format source code
17- cpmaddpackage(
"gh:TheLartians/[email protected] " )
21+ if (CHECK_FORMAT)
22+ cpmaddpackage(
"gh:TheLartians/[email protected] " )
23+ add_dependencies (error fix-format)
24+ endif ()
1825
1926 if (BUILD_TESTING)
2027 enable_testing ()
@@ -30,21 +37,20 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
3037 endif ()
3138
3239 # Get all targets in this directory
33- get_property (
34- TARGETS
35- DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
36- PROPERTY BUILDSYSTEM_TARGETS)
40+ get_property (TARGETS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
3741
3842 foreach (TARGET IN LISTS TARGETS)
3943 # Statically analyze code by checking for warnings
40- if (MSVC )
41- target_compile_options (${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc)
42- else ()
43- target_compile_options (${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic)
44+ if (CHECK_WARNING)
45+ if (MSVC )
46+ target_compile_options (${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc)
47+ else ()
48+ target_compile_options (${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic)
49+ endif ()
4450 endif ()
4551
4652 # Enable support to check for test coverage
47- if (BUILD_TESTING AND NOT MSVC )
53+ if (BUILD_TESTING AND CHECK_COVERAGE AND NOT MSVC )
4854 target_compile_options (${TARGET} PRIVATE --coverage -O0)
4955 target_link_options (${TARGET} PRIVATE --coverage)
5056 endif ()
0 commit comments