llvm-project/libcxx/utils/CMakeLists.txt
Christopher Di Bella ab46648082 [libcxx] adds an include-what-you-use (IWYU) mapping file
This makes it possible for programmers to run IWYU and get more accurate
standard library inclusions. Prior to this commit, the following program
would be transformed thusly:

```cpp
// Before
 #include <algorithm>
 #include <vector>

void f() {
  auto v = std::vector{0, 1};
  std::find(std::ranges::begin(v), std::ranges::end(v), 0);
}
```

```cpp
// After
 #include <__algorithm/find.h>
 #include <__ranges/access.h>
 #include <vector>
...
```

There are two ways to fix this issue: to use [comment pragmas](https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md)
on every private include, or to write a canonical [mapping file](https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md)
that provides the tool with a manual on how libc++ is laid out. Due to
the complexity of libc++, this commit opts for the latter, to maximise
correctness and minimise developer burden.

To mimimise developer updates to the file, it makes use of wildcards
that match everything within listed subdirectories. A script has also
been added to ensure that the mapping is always fresh in CI, and makes
the process a single step.

Finally, documentation has been added to inform users that IWYU is
supported, and what they need to do in order to leverage the mapping
file.

Closes #56937.

Differential Revision: https://reviews.llvm.org/D138189
2022-11-22 01:09:49 +00:00

50 lines
2.4 KiB
CMake

add_custom_target(libcxx-generate-public-header-transitive-inclusion-tests
COMMAND "${Python3_EXECUTABLE}" "${LIBCXX_SOURCE_DIR}/utils/generate_header_inclusion_tests.py"
COMMENT "Generate tests checking for mandated transitive includes in public headers.")
add_custom_target(libcxx-generate-public-header-tests
COMMAND "${Python3_EXECUTABLE}" "${LIBCXX_SOURCE_DIR}/utils/generate_header_tests.py"
COMMENT "Generate tests for including public headers.")
add_custom_target(libcxx-generate-feature-test-macros
COMMAND "${Python3_EXECUTABLE}" "${LIBCXX_SOURCE_DIR}/utils/generate_feature_test_macro_components.py"
COMMENT "Generate the <version> header and tests for feature test macros.")
add_custom_target(libcxx-generate-extended-grapheme-cluster-tables
COMMAND
"${Python3_EXECUTABLE}"
"${LIBCXX_SOURCE_DIR}/utils/generate_extended_grapheme_cluster_table.py"
"${LIBCXX_SOURCE_DIR}/include/__format/extended_grapheme_cluster_table.h"
COMMENT "Generate the extended grapheme cluster header.")
add_custom_target(libcxx-generate-extended-grapheme-cluster-tests
COMMAND
"${Python3_EXECUTABLE}"
"${LIBCXX_SOURCE_DIR}/utils/generate_extended_grapheme_cluster_test.py"
"${LIBCXX_SOURCE_DIR}/test/libcxx/utilities/format/format.string/format.string.std/extended_grapheme_cluster.h"
COMMENT "Generate the extended grapheme cluster header.")
add_custom_target(libcxx-generate-escaped-output-table
COMMAND
"${Python3_EXECUTABLE}"
"${LIBCXX_SOURCE_DIR}/utils/generate_escaped_output_table.py"
"${LIBCXX_SOURCE_DIR}/include/__format/escaped_output_table.h"
COMMENT "Generate the escaped output header")
add_custom_target(libcxx-generate-iwyu-mapping
COMMAND
"${Python3_EXECUTABLE}"
"${LIBCXX_SOURCE_DIR}/utils/generate_iwyu_mapping.py"
COMMENT "Generate the mapping file for include-what-you-use")
add_custom_target(libcxx-generate-files
DEPENDS libcxx-generate-public-header-transitive-inclusion-tests
libcxx-generate-public-header-tests
libcxx-generate-feature-test-macros
libcxx-generate-extended-grapheme-cluster-tables
libcxx-generate-extended-grapheme-cluster-tests
libcxx-generate-escaped-output-table
libcxx-generate-iwyu-mapping
COMMENT "Create all the auto-generated files in libc++ and its tests.")