Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: use {LLVM,Clang}Config.cmake #313

Merged
merged 1 commit into from
Mar 10, 2019
Merged

cmake: use {LLVM,Clang}Config.cmake #313

merged 1 commit into from
Mar 10, 2019

Conversation

MaskRay
Copy link
Owner

@MaskRay MaskRay commented Mar 10, 2019

Based on Daan De Meyer's #227

Clang/LLVM dependencies

Before, we tracked clang and llvm dependencies manually. When they were provided as static libraries *.a, we needed the full listing of used llvm* clang* dependencies.

After this change, we use lib/cmake/llvm/LLVMConfig.cmake and lib/cmake/clang/ClangConfig.cmake.

When static libraries are linked, ClangConfig.cmake tracks dependencies of clang* via INTERFACE_LINK_LIBRARIES:

set_target_properties(clangIndex PROPERTIES
  INTERFACE_LINK_LIBRARIES "clangAST;clangBasic;clangFormat;clangFrontend;clangLex;clangRewrite;clangSerialization;clangToolingCore;LLVMCore;LLVMSupport"
)

Only a small set of top-level dependencies need to be explicitly specified.

When shared libraries are linked, the dependency information for clang* is not tracked. ccls' direct dependencies need to be explicitly specified. This list is longer than the case of static libraries.

find_package(Clang REQUIRED)  # ClangConfig.cmake includes LLVMConfig.cmake

Include directories:

target_include_directories(ccls PRIVATE "src;${LLVM_INCLUDE_DIRS};${CLANG_INCLUDE_DIRS}")

LLVM_ENABLE_RTTI

lib/cmake/llvm/LLVMConfig.cmake sets this variable. Users no longer have to specify it.

We cannot use:

list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
include(AddLLVM)
llvm_update_compile_flags(ccls)

because it may wrongly sets -fno-exceptions -fno-rtti. I believe llvm_update_compile_flags only makes sense for llvm in-tree targets. ccls always enables exceptions (thus it doesn't follow LLVM_ENABLE_EH), but its RTTI follows LLVM_ENABLE_RTTI.

Based on Daan De Meyer's #227
@MaskRay MaskRay merged commit 1d7155e into master Mar 10, 2019
@MaskRay MaskRay deleted the cmake branch March 10, 2019 03:56
@mikeandmore
Copy link

Looks like ClangConfig.cmake is generated during compile time. In NIX, both clang and llvm provide static libraries, but ClangConfig insists that all static libraries are linked against the dynamic llvm library. Now, with this patch, there is no way to statically link llvm any more.

This sounds like a bug with Clang upstream. Why would the dependencies of the static library is a compile time configuration? This doesn't make sense to me.

@Mic92
Copy link

Mic92 commented May 30, 2019

In nixpkgs we compile llvm with the following options
and clang with the following options
This includes -DLLVM_ENABLE_RTTI=ON. It seems that some classes cannot be found in the libclang 7:

We get the following linker errors for 0.20190314.1:

[100%] Linking CXX executable ccls
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/indexer.cc.o:(.data.rel.ro+0xc0): undefined reference to `typeinfo for clang::index::IndexDataConsumer'
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/indexer.cc.o:(.data.rel.ro+0x160): undefined reference to `typeinfo for clang::ASTFrontendAction'
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/indexer.cc.o:(.data.rel.ro+0x2a0): undefined reference to `typeinfo for clang::PPCallbacks'
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/sema_manager.cc.o:(.data.rel.ro._ZTIN5clang3vfs15ProxyFileSystemE[_ZTIN5clang3vfs15ProxyFileSystemE]+0x10): undefined reference to `typeinfo for clang::vfs::FileSystem'
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/sema_manager.cc.o:(.data.rel.ro+0x60): undefined reference to `typeinfo for clang::DiagnosticConsumer'
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/sema_manager.cc.o:(.data.rel.ro+0xc0): undefined reference to `typeinfo for clang::PreambleCallbacks'
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/sema_manager.cc.o:(.data.rel.ro+0x200): undefined reference to `typeinfo for clang::PPCallbacks'
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/messages/textDocument_completion.cc.o:(.data.rel.ro+0x60): undefined reference to `typeinfo for clang::CodeCompleteConsumer'
/nix/store/2dfjlvp38xzkyylwpavnh61azi0d168b-binutils-2.31.1/bin/ld: CMakeFiles/ccls.dir/src/messages/textDocument_signatureHelp.cc.o:(.data.rel.ro+0x60): undefined reference to `typeinfo for
clang::CodeCompleteConsumer'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

As an example these are the symbols/references found for ASTFrontendAction in all libclang

$ nm -gCA /nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/*.a | grep ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangARCMigrate.a:ARCMT.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangARCMigrate.a:ARCMT.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangARCMigrate.a:ARCMT.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangARCMigrate.a:ObjCMT.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangARCMigrate.a:ObjCMT.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangARCMigrate.a:ObjCMT.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangCodeGen.a:CodeGenAction.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangCodeGen.a:CodeGenAction.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangCodeGen.a:CodeGenAction.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangDaemon.a:ClangdUnit.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangDaemon.a:ClangdUnit.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangDoc.a:ClangDoc.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangDoc.a:ClangDoc.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangDoc.a:ClangDoc.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:ASTUnit.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:ASTUnit.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:ASTUnit.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:CompilerInstance.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:FrontendAction.cpp.o:0000000000000000 T clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:FrontendAction.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:FrontendAction.cpp.o:0000000000000000 V vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:FrontendActions.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:FrontendActions.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:FrontendActions.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:PrecompiledPreamble.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:PrecompiledPreamble.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangFrontend.a:PrecompiledPreamble.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangIncludeFixer.a:IncludeFixer.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangIncludeFixer.a:IncludeFixer.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangIncludeFixerPlugin.a:IncludeFixerPlugin.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangIncludeFixerPlugin.a:IncludeFixerPlugin.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangIndex.a:IndexingAction.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangIndex.a:IndexingAction.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangIndex.a:IndexingAction.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangMove.a:ClangMove.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangMove.a:ClangMove.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangMove.a:ClangMove.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangRewriteFrontend.a:FrontendActions.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangRewriteFrontend.a:FrontendActions.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangRewriteFrontend.a:FrontendActions.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangStaticAnalyzerFrontend.a:FrontendActions.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangStaticAnalyzerFrontend.a:FrontendActions.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangStaticAnalyzerFrontend.a:FrontendActions.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangStaticAnalyzerFrontend.a:ModelInjector.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangTidy.a:ClangTidy.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangTidy.a:ClangTidy.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangTidy.a:ClangTidy.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangTidyPlugin.a:ClangTidyPlugin.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangTidyPlugin.a:ClangTidyPlugin.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libclangTidyPlugin.a:ClangTidyPlugin.cpp.o:                 U vtable for clang::ASTFrontendAction
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libfindAllSymbols.a:FindAllSymbolsAction.cpp.o:                 U clang::ASTFrontendAction::ExecuteAction()
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libfindAllSymbols.a:FindAllSymbolsAction.cpp.o:0000000000000000 W clang::ASTFrontendAction::usesPreprocessorOnly() const
/nix/store/mvibpl88y47qiq0frmg8bk55jxzax1q1-clang-7.1.0/lib/libfindAllSymbols.a:FindAllSymbolsAction.cpp.o:                 U vtable for clang::ASTFrontendAction

cc @dtzWill

Any idea what is missing here?

@Mic92
Copy link

Mic92 commented May 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants