diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95af8f1..5e003d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,3 +43,8 @@ jobs: with: modules_support_needed: true secrets: inherit + + tests: + name: ✅ Testing w/ Clang-Tidy enabled + uses: libhal/ci/.github/workflows/tests.yml@5.x.y + secrets: inherit diff --git a/CMakeLists.txt b/CMakeLists.txt index 360e42b..a74bc38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,6 @@ cmake_minimum_required(VERSION 4.0) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_COLOR_DIAGNOSTICS ON) set(CMAKE_CXX_SCAN_FOR_MODULES ON) -set(USE_CLANG_TIDY ON) project(strong_ptr LANGUAGES CXX) @@ -28,18 +27,20 @@ project(strong_ptr LANGUAGES CXX) if(CMAKE_CROSSCOMPILING) message(STATUS "Cross compiling, skipping clang-tidy") -else() - if(USE_CLANG_TIDY) - find_program(CLANG_TIDY_EXE NAMES clang-tidy) - if(CLANG_TIDY_EXE) - message(STATUS "Clang-tidy found: ${CLANG_TIDY_EXE}") - set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy;--fix") - else() - message(STATUS "Clang-tidy not found - continuing without clang-tidy") +elseif(LIBHAL_ENABLE_CLANG_TIDY) + find_program(CLANG_TIDY_EXE NAMES clang-tidy) + if(CLANG_TIDY_EXE) + message(STATUS "Clang-tidy found: ${CLANG_TIDY_EXE}") + set(CLANG_TIDY_CMD "${CLANG_TIDY_EXE};--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy") + if(LIBHAL_CLANG_TIDY_FIX) + list(APPEND CLANG_TIDY_CMD "--fix") endif() + set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_CMD}) else() - message(WARNING "Clang-tidy checks disabled") + message(STATUS "Clang-tidy not found - continuing without clang-tidy") endif() +else() + message(STATUS "Clang-tidy checks disabled (use -o enable_clang_tidy=True to enable)") endif() # ============================================================================== diff --git a/conanfile.py b/conanfile.py index ff761c8..6cc0dcc 100644 --- a/conanfile.py +++ b/conanfile.py @@ -39,6 +39,15 @@ class strong_ptr_conan(ConanFile): "CMakeLists.txt", "LICENSE", ".clang-tidy") shared = False + options = { + "enable_clang_tidy": [True, False], + "clang_tidy_fix": [True, False], + } + default_options = { + "enable_clang_tidy": False, + "clang_tidy_fix": False, + } + @property def _min_cppstd(self): return "23" @@ -111,6 +120,8 @@ def layout(self): def generate(self): tc = CMakeToolchain(self) tc.generator = "Ninja" + tc.variables["LIBHAL_ENABLE_CLANG_TIDY"] = self.options.enable_clang_tidy + tc.variables["LIBHAL_CLANG_TIDY_FIX"] = self.options.clang_tidy_fix tc.generate() deps = CMakeDeps(self)