Commit Graph

90 Commits

Author SHA1 Message Date
Kim Gräsman ba654f182f [cmake] Print full source path of resource headers
This makes it easier to see where the resource headers come from.
2022-12-20 19:54:01 +01:00
Kim Gräsman 5220063727 [cmake] Print LLVM source dir when configuring
This makes it easier to spot which LLVM install was picked up.
2022-12-20 19:54:01 +01:00
Kim Gräsman 9bcfd0b1a1 [clang compat] [cmake] Use LLVM major ver for resource headers
The clang-resource-headers CMake target is not exported from the
packaged LLVM/Clang CMake modules, so we synthesize it by explicitly
copying resource/built-in headers from the package install root to the
build dir.

Clang 16 changed the structure not to use major.minor.patch but rather
just the major version (in line with LLVM versioning at large).

Adjust so we pick up the headers from the right place, and put them
where Clang libraries will be looking.
2022-11-13 13:02:04 +01:00
Kim Gräsman 0a714265c0 Add regex module
Move regular expression matching into a function in its own module.

No functional change.
2022-09-03 15:04:27 +02:00
Kim Gräsman e94a78b3a5 [cmake] Require C++17 as does LLVM 2022-08-28 14:52:23 +02:00
Kim Gräsman 3a793604c1 [cmake] Support LLVM external project build
This makes it possible to build IWYU as part of LLVM using the
LLVM_EXTERNAL_PROJECTS feature of the LLVM build system.

Add separate instructions for this build mode to README.

Based on original patch from @bc-lee:
https://github.com/include-what-you-use/include-what-you-use/pull/994
2022-04-25 18:44:26 +02:00
Kim Gräsman 59509beca4 [cmake] Use "standalone" instead of out-of-tree/in-tree
This is more consistent with other projects that can build as part of the
llvm-project tree or standalone, e.g. flang, lldb, compiler-rt.
2022-04-25 18:44:26 +02:00
Kim Gräsman 9c15de6da6 [cmake] Synthesize clang-headers target if it's missing
... not depending on a potentially-incidental condition.
2022-04-24 16:01:09 +02:00
Kim Gräsman 226efb43ad [cmake] Move Git revision lookup towards the top of the file
This is the same kind of activity as looking for LLVM/Clang packages, and
synthesizing targets, so let's do it up-front.

Move the compile-option setting together with the others.
2022-04-24 16:01:09 +02:00
Kim Gräsman d46f3a4b0c [cmake] Use target-specific definitions and include dirs
... instead of legacy add_definitions and include_directories.

Move compile options to after target is defined.

Batch abstract target properties with set_target_properties, looks nicer
than setting them individually.
2022-04-24 16:01:09 +02:00
Kim Gräsman 6a3d1bc31f [cmake] Update comment style
Use Google C++-like comment style: comments are full sentences, including
punctuation, except trailing comments which are less formal.
2022-04-24 16:01:09 +02:00
Kim Gräsman 35e84050dc [cmake] Use more consistent formatting
* Use hanging closing parentheses for multiline invocations consistently
* Shorten overlong lines to colwidth 80
* Consistent placing of PRIVATE keyword
* Add space after if
2022-04-24 16:01:09 +02:00
Kim Gräsman ca2b549a8b [cmake] Use more consistent naming
Use lower_case for internal stuff, UPPER_CASE for externally configurable
stuff (as it turns out, only IWYU_LINK_CLANG_DYLIB).
2022-04-24 16:01:09 +02:00
Kim Gräsman 718e698755 Link with all target libraries
In the parent commit, I forgot to update the build so that include-what-you-use
links with all targets, which led to link failures for builds against LLVM build
trees (as opposed to the Debian packages).

While troubleshooting this, I found a patch by @Romain-Geissler-1A that I had
previously misunderstood/overlooked:
https://github.com/include-what-you-use/include-what-you-use/pull/854#issuecomment-732487734

Borrowing the link dependencies from that patch to complete my accidental
plagiarism fixes the build again.
2021-07-25 11:04:54 +02:00
Kim Grasman a295184e3e Remove /EHsc from MSVC build args
Slightly different /EH flags are now provided by LLVM's CMake system,
and MSVC warns that they're inconsistent.

They're the same in spirit, so let LLVM decide.
2021-07-06 19:28:26 +02:00
Alexey Storozhev c7891200cf Run tests using CMake
Some benefits:
* test parallelization (`ctest -j N`);
* rerun only failed tests (`ctest --rerun-failed`);
* potentially better integration with other tools;
* probably better reports;
* much faster on 12-core CPU:
** ~7.7s with `run_iwyu_tests.py`
** ~11.2s with `ctest --progress`
** ~1.3s with `ctest -j 12 --progress`
** ~0.9s with `ctest -E 'cxx.badinc' -j 12 --progress`
2021-05-01 17:06:44 +02:00
Kim Grasman c5f3b0fe4c [cmake] Require C++14 for building IWYU
The LLVM headers require -std=c++14 to parse and several compilers are
not C++14 by default.

IWYU itself currently only needs C++11, but LLVM does not announce its
minimum required C++ standard anywhere in its CMake config, so open up
for C++14 in IWYU by specifying it explicitly.

Fixes #867 and #880.
2021-03-13 14:52:46 +01:00
Kim Grasman 75cb6d99ec [cmake] Move clang-resource-headers target up a bit
Try to get that hack out of the main flow of IWYU's target definitions.

No functional change.
2021-03-13 14:52:46 +01:00
Kim Grasman d2bb9462e9 [cmake] Clarify comment around dynamic linking
In 3e2ebc3729, the logic changed, but the
comment grew stale. Rephrase.

No functional change.
2020-11-21 21:26:40 +01:00
Romain Geissler 3e2ebc3729 Correctly detect link with LLVM/CLANG shared libraries. 2020-11-12 21:39:08 +01:00
Kim Grasman a78944dabc Fix clang-headers copy for locally built LLVM/Clang
LLVM_INSTALL_PREFIX is only set for the packaged LLVM.

When there's a local build dir, LLVM_LIBRARY_DIR points to the same
place (give or take some library suffix stuff that I will ignore for
now).

Using the latter makes the synthetic 'clang-headers' cmake target work
when the prefix path points to a local LLVM build tree.
2020-10-27 18:55:51 +01:00
Seth R Johnson a5a6f27dab Add quotes to cmake arguments
It's possible that some of these have spaces, leading to odd cmake
errors.
2020-03-30 21:44:29 +02:00
Seth R Johnson 9a643ecb19 Do not assume CMAKE_PREFIX_PATH is LLVM_ROOT
It is not atypical for a user's CMake prefix path to include multiple
paths. (This is the case when installing a package with Spack, for
example.) Instead of using CMAKE_PREFIX_PATH, use the LLVM prefix path
defined by `find_package(LLVM)`.
2020-03-30 21:44:29 +02:00
Kim Grasman baa5d2a778 Use new behavior for CMake policy CMP0077
This follows the LLVM default and suppresses a warning from CMake when
building with llvm-11.
2020-03-03 16:52:49 +01:00
Aaron Puchert 596f993624 Add man page as a brief reference documentation
The manual page is compiled from the builtin help and the extensive
documentation, condensed down to the essence. We leave details and
elaborated examples to the Markdown documentation.
2019-11-03 16:06:30 +01:00
Aaron Puchert 9cd3c89d54 Use GNUInstallDirs instead of hardcoding directories
This is just a way to get canonical directories for different types of
files, which where already used implicitly.

There should be no functional change.
2019-11-03 16:06:30 +01:00
Aaron Puchert 589cf3836e Link with clang-cpp if only that is available
Since LLVM 9, the Clang component libraries are also linked into
clang-cpp, which provides the full C++ API [1]. So we link with that
if it is available and the component libraries are not.

[1] http://releases.llvm.org/9.0.0/tools/clang/docs/ReleaseNotes.html#build-system-changes
2019-11-02 09:47:47 +01:00
Kim Grasman e9b04bcadd Synthesize clang-resource-headers for out-of-tree
The Clang packaging does not expose a CMake target for
clang-resource-headers.

But with some inside info on package structure, it's relatively
straightforward to create our own, which copies all builtin headers from
the package prefix into the build directory.

This makes it possible for IWYU to assume the resource headers are
always available in the build tree after build, which makes testing
more deterministic.
2019-10-24 21:16:12 +02:00
Kim Grasman 25a66aa698 Clang r355340: clang-headers was renamed clang-resource-headers
Use the new name for our dependency in the build system.
2019-10-24 21:16:12 +02:00
Alexander Grund 791a23fa51 Allow regular `make test` workflow
Use CMake to add invokations of tests
Can be invoked as `make test` or `ctest`
2019-10-06 17:26:27 +02:00
Kim Grasman a36b64085c Remove MSVS solution folder grouping
Clang itself no longer appears to use this solution folder, so there's
no need for IWYU to follow suit.

Gets rid of another "folder", but in this case it was actually the
correct terminology according to Visual Studio.

No functional change, but generated Visual Studio solutions will be
organized differently.
2019-07-17 19:02:28 +02:00
tomKPZ fe5275aa7b Explicitly link to clangSerialization
This is necessary to fix the below linker error on Linux with clang 8.

/usr/bin/ld: CMakeFiles/include-what-you-use.dir/iwyu_driver.cc.o:
undefined reference to symbol '_ZN5clang22PCHContainerOperationsC1Ev'
2019-04-08 16:48:47 +02:00
Kim Grasman 99f2eabedf Have IWYU depend on clang-headers target
This ensures the builtin headers are copied to the build directory
before include-what-you-use is built.

The clang-headers target is not exposed in packaged LLVM, so this is
only relevant for in-tree builds. In out-of-tree builds, we can rely on
the builtin headers to be installed on the system.
2018-09-17 20:57:38 +02:00
Kim Grasman 0174b54501 Introduce IWYU_IN_TREE CMake variable
No functional change.
2018-09-17 20:57:38 +02:00
Kim Grasman c8e6a8a1af Build to $build/bin instead of $build
This makes the layout the same for out-of-tree and in-tree build dirs
for IWYU.
2018-09-17 20:42:59 +02:00
Philip Pfaffe 55bd620831 [CMake] Improve linking against the LLVM libraries.
When built against trunk LLVM with SHARED_LIBS enabled, LLMVOption is
missing from the libraries. Instead of hardcoding LLVM libnames, use the
appropriate macro to resolve libraries from components.

Since r337336 LLVM exports its LLVM_LINK_LLVM_DYLIB option, which means
that the add_llvm_executable() macro will automatically pick correctly
between the components set by LLVM_LINK_COMPONENTS and the singleton LLVM shared
library. Thus we can simplify linking a lot.
2018-07-20 20:27:42 +02:00
Kim Grasman 23f592039a Set CMake policy CMP0048 unconditionally
Now that we require CMake 3.4.3, we no longer need to check if CMP0048
is available before setting it to NEW.

Also move the policy setting and project declaration so we only create a
project for out-of-tree builds. In-tree builds will become part of the
LLVM project, which already has this policy set.
2018-07-08 11:30:28 +02:00
Kim Grasman 0003739b52 Use LLVM and Clang CMake modules
This is a breaking change.

Now that Debian packaging has been fixed, configuring IWYU should be as
easy as:

  $ cmake -DCMAKE_PREFIX_PATH=/usr/lib/llvm-7 ../include-what-you-use

to link with published LLVM/Clang libraries and:

  $ cmake -DCMAKE_PREFIX_PATH=/llvm-trunk/build ../include-what-you-use

to link with locally built libraries.

IWYU now prefers dynamic linking of LLVM if available, to avoid
accidentally linking LLVM both statically and dynamically.

Out-of-tree is now the only supported configuration, but we keep in-tree
around for convenience.
2018-05-28 21:02:46 +02:00
Kim Grasman c6e4125389 Use PRIVATE in target_link_libraries
LLVM introduced PRIVATE scope for target_link_libraries for executables
in r319840. Since executables don't export link dependencies, this makes
sense.

CMake does not allow mixing target_link_libraries invocations
with/without scope specifiers, so add PRIVATE in IWYU's CMakeLists.txt
2017-12-10 12:09:21 +01:00
Kim Grasman 56e0661c98 Add library dependency for backtrace
The out-of-tree build on my FreeBSD 11 machine failed with an unresolved
symbol for `backtrace`.

Use CMake's find provider for backtrace to satisfy the dependency.
2017-09-16 22:01:28 +02:00
Volodymyr Sapsai bdcdaef51b Update to reflect changes in LLVM.
LLVM r304864 extracted new library libLLVMBinaryFormat out of
libLLVMSupport and libLLVMCore depends on it.
2017-06-08 23:16:58 -07:00
Kim Grasman 89f8d1e9f8 Fix out-of-tree build for MSVC
We don't build with MSVC out-of-tree regularly, so a number of
compatibility issues with LLVM had snuck in:

- Suppressed warnings in header LLVM files
- Extended object format support (/bigobj)
- Use of noexcept requires sane C++ exception semantics (/EHSc)
- Clang's MSVCToolChain.cpp now uses functions from version.dll, so add it
  to linker deps

While dabbling with this, we also found it was necessary to CMake with
-DCMAKE_BUILD_TYPE=Release to match LLVM's release-built libraries.
Mention this in the user docs.
2017-02-19 12:13:13 +01:00
Kim Grasman b5d3e7250a Add /bigobj for MSVC builds
We enabled extended object format to work around 'too many sections' for
MinGW, but not for MSVC.

Do so now.
2017-01-24 20:34:08 +01:00
Volodymyr Sapsai 6310a26330 Update to reflect changes in LLVM.
LLVM r280732 added new library libLLVMDemangle and libLLVMSupport depends on it.
2016-09-07 20:05:38 -07:00
Volodymyr Sapsai 7554b31b32 Update CMake minimum required version to 3.4.3 to sync with LLVM+Clang.
Change resolves issue #327.
2016-07-03 21:40:34 -07:00
EugeneZelenko 2bd1323d60 Install mapping files in share/include-what-you-use 2016-05-19 11:38:11 -07:00
Volodymyr Sapsai db6b6edafa Update to reflect libLLVMProfileData changes in Clang.
Clang r262515 added dependency on library LLVMProfileData in clangFrontend
(for example, in CompilerInvocation.cpp).
2016-03-05 17:37:42 -08:00
Kim Grasman 81ecdafe4d Silence CMake CMP0048 warning 2016-02-09 21:44:15 +01:00
Kim Grasman f7d23b8b9b Fix #262: Don't fail the build in SVN checkout
Based on patch by JVApen, thanks!
2016-02-09 06:04:24 +01:00
Kim Grasman 901083ac17 Fix #256: Enable bigobjs for MSYS 2016-01-18 21:28:32 +01:00