File: CMakeLists.txt

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (116 lines) | stat: -rw-r--r-- 4,399 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# TODO: Re-enable the tests once the CI is back under control
return()

# The find_package changes these variables. This leaves the build in an odd
# state. Calling cmake a second time tries to write site config information in
# the system's libc++. Restoring these setting after testing fixes this issue.
set(LLVM_DIR_SAVE ${LLVM_DIR})
set(Clang_DIR_SAVE ${Clang_DIR})

# Since the Clang C++ ABI is not stable the Clang libraries and clang-tidy
# versions must match. Otherwise there likely will be ODR-violations. This had
# led to crashes and incorrect output of the clang-tidy based checks.
find_package(Clang ${CMAKE_CXX_COMPILER_VERSION})
if(NOT Clang_FOUND)
  message(STATUS "Clang-tidy tests are disabled since the "
                 "Clang development package is unavailable.")
  return()
endif()
if(NOT TARGET clangTidy)
  message(STATUS "Clang-tidy tests are disabled since the "
                 "Clang development package has no clangTidy target.")
  return()
endif()

set(LLVM_DIR "${LLVM_DIR_SAVE}" CACHE PATH "The directory containing a CMake configuration file for LLVM." FORCE)
set(Clang_DIR "${Clang_DIR_SAVE}" CACHE PATH "The directory containing a CMake configuration file for Clang." FORCE)

message(STATUS "Found system-installed LLVM ${LLVM_PACKAGE_VERSION} with headers in ${LLVM_INCLUDE_DIRS}")

set(CMAKE_CXX_STANDARD 20)

# Link only against clangTidy itself, not anything that clangTidy uses; otherwise we run setup code multiple times
# which results in clang-tidy crashing
set_target_properties(clangTidy PROPERTIES INTERFACE_LINK_LIBRARIES "")
# ClangTargets.cmake doesn't set the include paths, so we have to do it
target_include_directories(clangTidy INTERFACE
                           ${CLANG_INCLUDE_DIRS}
                           ${LLVM_INCLUDE_DIRS}
                          )
target_compile_options(clangTidy INTERFACE
                       -fno-rtti
                       -fno-sanitize=address,hwaddress,undefined,thread,leak # ignore any sanitizers
                      )

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  target_compile_options(clangTidy INTERFACE
                         -fno-sanitize=memory,dataflow
                        )
endif()

# In some cases even with the clangTidy target present the headers appear not to
# be on the system. Run a short test to see whether the header is present.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test.cpp" "
#if !__has_include(\"clang-tidy/ClangTidyCheck.h\")
  # error No clang-tidy headers
#endif
int main(){}
")
try_compile(HAS_CLANG_TIDY_HEADERS
  "${CMAKE_CURRENT_BINARY_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}/test.cpp"
   LINK_LIBRARIES clangTidy)

if(NOT HAS_CLANG_TIDY_HEADERS)
  message(STATUS "Clang-tidy tests are disabled since the "
                 "clang-tidy headers are not present.")
  return()
endif()

# The clangTidy plugin uses C++20, so ensure that we support C++20 when using libstdc++.
# This is required because some versions of libstdc++ used as a system library on build platforms
# we support do not support C++20 yet.
# Note it has not been tested whether version 11 works.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test.cpp" "
#include <version>
#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 12
  # error The libstdc++ version is too old.
#endif
int main(){}
")
try_compile(HAS_NEWER_STANDARD_LIBRARY
  "${CMAKE_CURRENT_BINARY_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}/test.cpp"
   LINK_LIBRARIES clangTidy)

if(NOT HAS_NEWER_STANDARD_LIBRARY)
  message(STATUS "Clang-tidy tests are disabled due to using "
                 "stdlibc++ older than version 12")
  return()
endif()
message(STATUS "Clang-tidy tests are enabled.")

set(SOURCES
    abi_tag_on_virtual.cpp
    header_exportable_declarations.cpp
    hide_from_abi.cpp
    proper_version_checks.cpp
    qualify_declval.cpp
    robust_against_adl.cpp
    uglify_attributes.cpp

    libcpp_module.cpp
   )

add_library(cxx-tidy MODULE ${SOURCES})
target_link_libraries(cxx-tidy clangTidy)

set_target_properties(cxx-tidy PROPERTIES
                      CXX_STANDARD 20
                      CXX_STANDARD_REQUIRED YES
                      CXX_EXTENSIONS NO)

set_target_properties(cxx-tidy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_SHARED_MODULE_SUFFIX_CXX .plugin) # Use a portable suffix to simplify how we can find it from Lit

add_dependencies(cxx-test-depends cxx-tidy)