From 0e9ed6694518c0ed4ffe0d4fbcf550463071b511 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Mon, 29 Jul 2024 16:49:38 -0700 Subject: [PATCH] Introduce cmake variable MIOPEN_USE_CLANG_TIDY While clang-tidy is useful for development to find issues, it is not always appropriate. When the clang-tidy used to build does not match the clang-tidy used in development the build can fail if the clang-tidy is not the same version as what development used. It also roughly doubles the build. Introduce the cmake variable MIOPEN_USE_CLANG_TIDY to give the user the choice to use it our not. Set the default to ON to match the current behavior. Signed-off-by: Tom Rix --- CMakeLists.txt | 37 ++++++++++++++++++--------------- addkernels/CMakeLists.txt | 4 +++- speedtests/CMakeLists.txt | 4 +++- src/CMakeLists.txt | 4 +++- test/CMakeLists.txt | 4 +++- tools/sqlite2txt/CMakeLists.txt | 4 +++- 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e53dd871c9..474308f48f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -685,24 +685,27 @@ rocm_create_package( ) include(EnableCompilerWarnings) -set(MIOPEN_TIDY_ERRORS ERRORS * -readability-inconsistent-declaration-parameter-name) -if(CMAKE_CXX_COMPILER MATCHES ".*clang\\+\\+") - set(MIOPEN_TIDY_CHECKS -modernize-use-override -readability-non-const-parameter) -# Enable tidy on hip -elseif(MIOPEN_BACKEND STREQUAL "HIP" OR MIOPEN_BACKEND STREQUAL "HIPNOGPU") - set(MIOPEN_TIDY_ERRORS ALL) -endif() +option(MIOPEN_USE_CLANG_TIDY "Use clang tidy to find problems" ON) +if(MIOPEN_USE_CLANG_TIDY) + set(MIOPEN_TIDY_ERRORS ERRORS * -readability-inconsistent-declaration-parameter-name) + if(CMAKE_CXX_COMPILER MATCHES ".*clang\\+\\+") + set(MIOPEN_TIDY_CHECKS -modernize-use-override -readability-non-const-parameter) + # Enable tidy on hip + elseif(MIOPEN_BACKEND STREQUAL "HIP" OR MIOPEN_BACKEND STREQUAL "HIPNOGPU") + set(MIOPEN_TIDY_ERRORS ALL) + endif() -include(ClangTidy) -enable_clang_tidy( - CHECKS - ${MIOPEN_TIDY_CHECKS} - ${MIOPEN_TIDY_ERRORS} - HEADER_FILTER - "\.hpp$" - EXTRA_ARGS - -DMIOPEN_USE_CLANG_TIDY -) + include(ClangTidy) + enable_clang_tidy( + CHECKS + ${MIOPEN_TIDY_CHECKS} + ${MIOPEN_TIDY_ERRORS} + HEADER_FILTER + "\.hpp$" + EXTRA_ARGS + -DMIOPEN_USE_CLANG_TIDY + ) +endif() include(CppCheck) enable_cppcheck( diff --git a/addkernels/CMakeLists.txt b/addkernels/CMakeLists.txt index 30c54ee491..8d73ac59ca 100644 --- a/addkernels/CMakeLists.txt +++ b/addkernels/CMakeLists.txt @@ -32,4 +32,6 @@ if(HAS_LIB_STD_FILESYSTEM) target_link_libraries(addkernels PRIVATE stdc++fs) endif() -clang_tidy_check(addkernels) +if(MIOPEN_USE_CLANG_TIDY) + clang_tidy_check(addkernels) +endif() diff --git a/speedtests/CMakeLists.txt b/speedtests/CMakeLists.txt index 3a00a7013a..7566dc2542 100644 --- a/speedtests/CMakeLists.txt +++ b/speedtests/CMakeLists.txt @@ -8,7 +8,9 @@ endif() function(add_speedtest_executable TEST_NAME) add_executable (${TEST_NAME} EXCLUDE_FROM_ALL ${ARGN}) - clang_tidy_check(${TEST_NAME}) + if(MIOPEN_USE_CLANG_TIDY) + clang_tidy_check(${TEST_NAME}) + endif() target_link_libraries(${TEST_NAME} ${CMAKE_THREAD_LIBS_INIT}) # Cmake does not add flags correctly for gcc if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea6bbc77f0..7e7d4722a8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -773,7 +773,9 @@ endif() rocm_set_soversion(MIOpen ${MIOpen_SOVERSION}) -clang_tidy_check(MIOpen) +if(MIOPEN_USE_CLANG_TIDY) + clang_tidy_check(MIOpen) +endif() if(HAS_LIB_STD_FILESYSTEM) target_link_libraries(MIOpen PRIVATE stdc++fs) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 434fdfe5df..acf6c8199f 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -345,7 +345,9 @@ function(add_test_executable TEST_NAME) if(WIN32) target_compile_definitions(${TEST_NAME} PRIVATE NOMINMAX) endif() - clang_tidy_check(${TEST_NAME}) + if(MIOPEN_USE_CLANG_TIDY) + clang_tidy_check(${TEST_NAME}) + endif() target_link_libraries(${TEST_NAME} Threads::Threads) # Cmake does not add flags correctly for gcc if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") diff --git a/tools/sqlite2txt/CMakeLists.txt b/tools/sqlite2txt/CMakeLists.txt index 3b3ba47801..f1e645edf9 100644 --- a/tools/sqlite2txt/CMakeLists.txt +++ b/tools/sqlite2txt/CMakeLists.txt @@ -8,4 +8,6 @@ if (NOT WIN32) target_link_libraries(sqlite2txt dl) endif() -clang_tidy_check(sqlite2txt) +if(MIOPEN_USE_CLANG_TIDY) + clang_tidy_check(sqlite2txt) +endif()