some clang-tidy CMake integration improvements / fixed `SOVERSION` with multi-digit versions (#4391)

This commit is contained in:
Oliver Stöneberg 2022-08-22 20:13:13 +02:00 committed by GitHub
parent 66fca7ba91
commit 1262c98416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 16 deletions

View File

@ -1,21 +1,35 @@
if (NOT NPROC) if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
include(ProcessorCount) # clang-tidy and clang need to have the same version when precompiled headers are beign used
ProcessorCount(NPROC) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NPROC EQUAL 0) string(REGEX MATCHALL "[0-9]+" _clang_ver_parts "${CMAKE_CXX_COMPILER_VERSION}")
message(FATAL_ERROR "could not get processor count") LIST(GET _clang_ver_parts 0 _clang_major)
set(RUN_CLANG_TIDY_NAMES "run-clang-tidy-${_clang_major}")
message(STATUS "Clang and clang-tidy version need to match when precompiled headers are enabled - limiting search to '${RUN_CLANG_TIDY_NAMES}'")
else()
message(STATUS "Cannot use non-Clang compiler with clang-tidy when precompiled headers are enabled - skipping 'run-clang-tidy' target generation")
endif() endif()
else()
set(RUN_CLANG_TIDY_NAMES run-clang-tidy run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8)
endif() endif()
message(STATUS "NPROC=${NPROC}")
find_program(RUN_CLANG_TIDY NAMES run-clang-tidy run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8) if (RUN_CLANG_TIDY_NAMES)
message(STATUS "RUN_CLANG_TIDY=${RUN_CLANG_TIDY}") find_program(RUN_CLANG_TIDY NAMES ${RUN_CLANG_TIDY_NAMES})
if (RUN_CLANG_TIDY) message(STATUS "RUN_CLANG_TIDY=${RUN_CLANG_TIDY}")
# disable all compiler warnings since we are just interested in the tidy ones if (RUN_CLANG_TIDY)
add_custom_target(run-clang-tidy ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -quiet) include(ProcessorCount)
if (BUILD_GUI) ProcessorCount(NPROC)
add_dependencies(run-clang-tidy gui-build-deps) if(NPROC EQUAL 0)
if (BUILD_TESTS) message(FATAL_ERROR "could not get processor count")
add_dependencies(run-clang-tidy triage-build-ui-deps) endif()
message(STATUS "NPROC=${NPROC}")
# disable all compiler warnings since we are just interested in the tidy ones
add_custom_target(run-clang-tidy ${PYTHON_EXECUTABLE} ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -quiet)
if (BUILD_GUI)
add_dependencies(run-clang-tidy gui-build-deps)
if (BUILD_TESTS)
add_dependencies(run-clang-tidy triage-build-ui-deps)
endif()
endif() endif()
endif() endif()
endif() endif()

View File

@ -1,6 +1,6 @@
# Version for libraries CPP # Version for libraries CPP
SET(VERSION "2.9.99") SET(VERSION "2.9.99")
STRING(REGEX MATCHALL "[0-9]" VERSION_PARTS "${VERSION}") STRING(REGEX MATCHALL "[0-9]+" VERSION_PARTS "${VERSION}")
LIST(GET VERSION_PARTS 0 VERSION_MAJOR) LIST(GET VERSION_PARTS 0 VERSION_MAJOR)
LIST(GET VERSION_PARTS 1 VERSION_MINOR) LIST(GET VERSION_PARTS 1 VERSION_MINOR)
SET(SOVERSION "${VERSION_MAJOR}.${VERSION_MINOR}") SET(SOVERSION "${VERSION_MAJOR}.${VERSION_MINOR}")