mirror of https://github.com/FreeRDP/FreeRDP
[clang] unify tool detection
This commit is contained in:
parent
aa9a9564ac
commit
fc47a019df
|
@ -6,38 +6,10 @@ set (WITH_VERBOSE_WINPR_ASSERT OFF CACHE BOOL "qa default")
|
|||
set (BUILD_SHARED_LIBS OFF CACHE BOOL "qa default")
|
||||
|
||||
set (BUILD_WITH_CLANG_TIDY OFF CACHE BOOL "qa default")
|
||||
find_program(CLANG_EXE
|
||||
NAMES
|
||||
clang-20
|
||||
clang-19
|
||||
clang-18
|
||||
clang-17
|
||||
clang-16
|
||||
clang-15
|
||||
clang-14
|
||||
clang-13
|
||||
clang-12
|
||||
clang-11
|
||||
clang-10
|
||||
clang
|
||||
REQUIRED
|
||||
)
|
||||
set (CMAKE_C_COMPILER "${CLANG_EXE}" CACHE STRING "qa default")
|
||||
|
||||
find_program(CLANG_XX_EXE
|
||||
NAMES
|
||||
clang++-20
|
||||
clang++-19
|
||||
clang++-18
|
||||
clang++-17
|
||||
clang++-16
|
||||
clang++-15
|
||||
clang++-14
|
||||
clang++-13
|
||||
clang++-12
|
||||
clang++-11
|
||||
clang++-10
|
||||
clang++
|
||||
REQUIRED
|
||||
)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ClangDetectTool.cmake)
|
||||
clang_detect_tool(CLANG_EXE clang REQUIRED)
|
||||
clang_detect_tool(CLANG_XX_EXE clang++ REQUIRED)
|
||||
|
||||
set (CMAKE_C_COMPILER "${CLANG_EXE}" CACHE STRING "qa default")
|
||||
set (CMAKE_CXX_COMPILER "${CLANG_XX_EXE}" CACHE STRING "qa default")
|
||||
|
|
|
@ -16,38 +16,10 @@ set (CMAKE_C_FLAGS "-Weverything -Wno-exit-time-destructors -Wno-cast-align -Wno
|
|||
set (CMAKE_CXX_FLAGS "-Weverything -Wno-exit-time-destructors -Wno-cast-align -Wno-documentation -Wno-documentation-unknown-command -Wno-padded -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-covered-switch-default -Wno-declaration-after-statement" CACHE STRING "qa default")
|
||||
|
||||
set (BUILD_WITH_CLANG_TIDY ON CACHE BOOL "qa default")
|
||||
find_program(CLANG_EXE
|
||||
NAMES
|
||||
clang-20
|
||||
clang-19
|
||||
clang-18
|
||||
clang-17
|
||||
clang-16
|
||||
clang-15
|
||||
clang-14
|
||||
clang-13
|
||||
clang-12
|
||||
clang-11
|
||||
clang-10
|
||||
clang
|
||||
REQUIRED
|
||||
)
|
||||
set (CMAKE_C_COMPILER "${CLANG_EXE}" CACHE STRING "qa default")
|
||||
|
||||
find_program(CLANG_XX_EXE
|
||||
NAMES
|
||||
clang++-20
|
||||
clang++-19
|
||||
clang++-18
|
||||
clang++-17
|
||||
clang++-16
|
||||
clang++-15
|
||||
clang++-14
|
||||
clang++-13
|
||||
clang++-12
|
||||
clang++-11
|
||||
clang++-10
|
||||
clang++
|
||||
REQUIRED
|
||||
)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ClangDetectTool.cmake)
|
||||
clang_detect_tool(CLANG_EXE clang REQUIRED)
|
||||
clang_detect_tool(CLANG_XX_EXE clang++ REQUIRED)
|
||||
|
||||
set (CMAKE_C_COMPILER "${CLANG_EXE}" CACHE STRING "qa default")
|
||||
set (CMAKE_CXX_COMPILER "${CLANG_XX_EXE}" CACHE STRING "qa default")
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
function (clang_detect_tool VAR NAME OPTS)
|
||||
set(NAMES "")
|
||||
foreach(CNT RANGE 12 22)
|
||||
list(APPEND NAMES "${NAME}-${CNT}")
|
||||
endforeach()
|
||||
list(REVERSE NAMES)
|
||||
list(APPEND NAMES ${NAME})
|
||||
|
||||
find_program(${VAR}
|
||||
NAMES ${NAMES}
|
||||
${OPTS}
|
||||
)
|
||||
if (NOT ${VAR})
|
||||
message(WARNING "clang tool ${NAME} (${VAR}) not detected, skipping")
|
||||
unset(${VAR})
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${${VAR}} "--version"
|
||||
OUTPUT_VARIABLE _CLANG_TOOL_VERSION
|
||||
RESULT_VARIABLE _CLANG_TOOL_VERSION_FAILED
|
||||
)
|
||||
|
||||
if (_CLANG_TOOL_VERSION_FAILED)
|
||||
message(WARNING "A problem was encounterd with ${${VAR}}")
|
||||
message(WARNING "${_CLANG_TOOL_VERSION_FAILED}")
|
||||
unset(${VAR})
|
||||
return()
|
||||
endif()
|
||||
|
||||
string(REGEX MATCH "([7-9]|[1-9][0-9])\\.[0-9]\\.[0-9]" CLANG_TOOL_VERSION
|
||||
"${_CLANG_TOOL_VERSION}")
|
||||
|
||||
if (NOT CLANG_TOOL_VERSION)
|
||||
message(WARNING "problem parsing ${NAME} version for ${${VAR}}")
|
||||
unset(${VAR})
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(_CLANG_TOOL_MINIMUM_VERSION "12.0.0")
|
||||
if (${CLANG_TOOL_VERSION} VERSION_LESS ${_CLANG_TOOL_MINIMUM_VERSION})
|
||||
message(WARNING "clang-format version ${CLANG_TOOL_VERSION} not supported")
|
||||
message(WARNING "Minimum version required: ${_CLANG_TOOL_MINIMUM_VERSION}")
|
||||
unset(${VAR})
|
||||
return()
|
||||
endif()
|
||||
endfunction()
|
|
@ -1,52 +1,12 @@
|
|||
# get all project files
|
||||
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.c *.h *.m *.java)
|
||||
# minimum version required
|
||||
set(_CLANG_FORMAT_MINIMUM_VERSION 10.0.0)
|
||||
|
||||
find_program(CLANG_FORMAT
|
||||
NAMES
|
||||
clang-format-20
|
||||
clang-format-19
|
||||
clang-format-18
|
||||
clang-format-17
|
||||
clang-format-16
|
||||
clang-format-15
|
||||
clang-format-14
|
||||
clang-format-13
|
||||
clang-format-12
|
||||
clang-format-11
|
||||
clang-format-10
|
||||
clang-format
|
||||
)
|
||||
include(ClangDetectTool)
|
||||
clang_detect_tool(CLANG_FORMAT clang-format)
|
||||
|
||||
if (NOT CLANG_FORMAT)
|
||||
message(WARNING "clang-format not found in path! code format target not available.")
|
||||
else()
|
||||
execute_process(
|
||||
COMMAND ${CLANG_FORMAT} "--version"
|
||||
OUTPUT_VARIABLE _CLANG_FORMAT_VERSION
|
||||
RESULT_VARIABLE _CLANG_FORMAT_VERSION_FAILED
|
||||
)
|
||||
|
||||
if (_CLANG_FORMAT_VERSION_FAILED)
|
||||
message(WARNING "A problem was encounterd with ${CLANG_FORMAT}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
string(REGEX MATCH "([7-9]|[1-9][0-9])\\.[0-9]\\.[0-9]" CLANG_FORMAT_VERSION
|
||||
"${_CLANG_FORMAT_VERSION}")
|
||||
|
||||
if (NOT CLANG_FORMAT_VERSION)
|
||||
message(WARNING "problem parsing clang-format version for ${CLANG_FORMAT}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if (${CLANG_FORMAT_VERSION} VERSION_LESS ${_CLANG_FORMAT_MINIMUM_VERSION})
|
||||
message(WARNING "clang-format version ${CLANG_FORMAT_VERSION} not supported")
|
||||
message(WARNING "Minimum version required: ${_CLANG_FORMAT_MINIMUM_VERSION}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
add_custom_target(
|
||||
clangformat
|
||||
COMMAND ${CLANG_FORMAT}
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
option(BUILD_WITH_CLANG_TIDY "Build with clang-tidy for extra warnings" OFF)
|
||||
|
||||
if (BUILD_WITH_CLANG_TIDY)
|
||||
find_program(CLANG_TIDY_EXE
|
||||
NAMES
|
||||
clang-tidy-20
|
||||
clang-tidy-19
|
||||
clang-tidy-18
|
||||
clang-tidy-17
|
||||
clang-tidy-16
|
||||
clang-tidy-15
|
||||
clang-tidy-14
|
||||
clang-tidy-13
|
||||
clang-tidy-12
|
||||
clang-tidy-11
|
||||
clang-tidy-10
|
||||
clang-tidy
|
||||
REQUIRED
|
||||
)
|
||||
include(ClangDetectTool)
|
||||
clang_detect_tool(CLANG_TIDY_EXE clang-tidy REQUIRED)
|
||||
|
||||
set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" --config-file=${CMAKE_SOURCE_DIR}/.clang-tidy)
|
||||
|
||||
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY_COMMAND}" --extra-arg=-std=gnu11)
|
||||
|
|
Loading…
Reference in New Issue