diff --git a/CMakeLists.txt b/CMakeLists.txt index 8aa338d..c1eaec8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,12 @@ set(CMAKE_CXX_STANDARD 23) include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/macros.cmake) +add_option(ENABLE_STATIC_ANALYSIS "Enables clang-tidy static analysis") + +if (ENABLE_STATIC_ANALYSIS) + set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;--allow-no-checks") +endif () + if(WIN32) add_compile_definitions(LIGHT_PLATFORM_WINDOWS) elseif(UNIX) diff --git a/conanfile.py b/conanfile.py index c9d4b3f..f582028 100644 --- a/conanfile.py +++ b/conanfile.py @@ -11,9 +11,11 @@ class LightRecipe(ConanFile): generators = "CMakeDeps" options = { + "enable_static_analysis": [True, False], } default_options = { + "enable_static_analysis": False, } def requirements(self): @@ -36,7 +38,9 @@ class LightRecipe(ConanFile): tc = CMakeToolchain(self) tc.variables["CMAKE_BUILD_TYPE"] = self.settings.build_type + tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = True + tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis repo = git.Repo(search_parent_directories=True) tc.cache_variables["GIT_HASH"] = repo.head.object.hexsha diff --git a/external/.clang-tidy b/external/.clang-tidy new file mode 100644 index 0000000..1d6a1fe --- /dev/null +++ b/external/.clang-tidy @@ -0,0 +1,3 @@ +# Disable all checks in this subdirectory +Checks: '-*' + diff --git a/tools/cmake/macros.cmake b/tools/cmake/macros.cmake index 2e0973e..791b662 100644 --- a/tools/cmake/macros.cmake +++ b/tools/cmake/macros.cmake @@ -39,3 +39,14 @@ macro (add_executable_module exename) target_include_directories(${exename} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(${exename} PUBLIC base) endmacro () + +macro (add_option option help) + option(${option} ${help}) + + if (${option}) + message(STATUS "${option}: ON") + add_compile_definitions(${option}=1) + else () + message(STATUS "${option}: OFF") + endif () +endmacro ()