All CMake based, build LLVM/clang under windows but got linker problems with clang libraries

i’ve already posted that on reddit/llvm: Reddit - Dive into anything

i built LLVM on windows 10, based on these instructions with VS2022(latest)

https://llvm.org/docs/CMake.html

1. git clone https://github.com/llvm/llvm-project
2. cd llvm-project
3. git checkout llvmorg-17.0.6
4. cd ..
5. mkdir _build
6. _build
7. cmake -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\projects\llvm_dev\_install -DLLVM_TARGETS_TO_BUILD=X86 ..\llvm-project\llvm
8. cmake --build .
9. cmake --build . --target install

builds without errors, clang++.exe and others run etc. so the build seems ok

this is the files-tree in my _install folder after building:

* tree: https://pastebin.com/rXJScrSa
* flat: https://pastebin.com/xriB7v8j

then i’ve based my CMakeLists.txt on the sample from here Building LLVM with CMake — LLVM 18.0.0git documentation

cmake_minimum_required(VERSION 3.20.0)
project(llvm-orc-jit)

set (CMAKE_CXX_STANDARD 17)

find_package(LLVM REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})

# Now build our tools
add_executable(llvm-orc-jit main.cc jit.h ccompiler.h)

# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core orcjit jitlink)

# Link against LLVM libraries
target_link_libraries(llvm-orc-jit ${llvm_libs})

my small example to get rid of the linker errors

#include <clang/Basic/Diagnostic.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <llvm/Support/raw_ostream.h>

#include <memory>

int main()
{
    auto DO = llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions>(new clang::DiagnosticOptions());
    DO->ShowColors = 1;

    // Setup stderr custom diagnostic consumer.
    auto DC = std::make_unique<clang::TextDiagnosticPrinter>(llvm::errs(), DO.get());

    // Create custom diagnostics engine.
    // The engine will NOT take ownership of the DiagnosticConsumer object.
    auto DE = std::make_unique<clang::DiagnosticsEngine>(
        nullptr /* DiagnosticIDs */, std::move(DO), DC.get(),
        false /* own DiagnosticConsumer */);
}

these are my linker errors - i think im missing all the clang libraries

2>main.obj : error LNK2019: unresolved external symbol "public: __cdecl clang::DiagnosticsEngine::DiagnosticsEngine(class llvm::IntrusiveRefCntPtr<class clang::DiagnosticIDs>,class llvm::IntrusiveRefCntPtr<class clang::DiagnosticOptions>,class clang::DiagnosticConsumer *,bool)" (??0DiagnosticsEngine@clang@@QEAA@V?$IntrusiveRefCntPtr@VDiagnosticIDs@clang@@@llvm@@V?$IntrusiveRefCntPtr@VDiagnosticOptions@clang@@@3@PEAVDiagnosticConsumer@1@_N@Z) referenced in function "class std::unique_ptr<class clang::DiagnosticsEngine,struct std::default_delete<class clang::DiagnosticsEngine> > __cdecl std::make_unique<class clang::DiagnosticsEngine,std::nullptr_t,class llvm::IntrusiveRefCntPtr<class clang::DiagnosticOptions>,class clang::TextDiagnosticPrinter *,bool,0>(std::nullptr_t &&,class llvm::IntrusiveRefCntPtr<class clang::DiagnosticOptions> &&,class clang::TextDiagnosticPrinter * &&,bool &&)" (??$make_unique@VDiagnosticsEngine@clang@@$$TV?$IntrusiveRefCntPtr@VDiagnosticOptions@clang@@@llvm@@PEAVTextDiagnosticPrinter@2@_N$0A@@std@@YA?AV?$unique_ptr@VDiagnosticsEngine@clang@@U?$default_delete@VDiagnosticsEngine@clang@@@std@@@0@$$QEA$$T$$QEAV?$IntrusiveRefCntPtr@VDiagnosticOptions@clang@@@llvm@@$$QEAPEAVTextDiagnosticPrinter@clang@@$$QEA_N@Z)
2>main.obj : error LNK2019: unresolved external symbol "public: __cdecl clang::DiagnosticsEngine::~DiagnosticsEngine(void)" (??1DiagnosticsEngine@clang@@QEAA@XZ) referenced in function "public: void * __cdecl clang::DiagnosticsEngine::`scalar deleting destructor'(unsigned int)" (??_GDiagnosticsEngine@clang@@QEAAPEAXI@Z)
2>main.obj : error LNK2019: unresolved external symbol "public: __cdecl clang::TextDiagnosticPrinter::TextDiagnosticPrinter(class llvm::raw_ostream &,class clang::DiagnosticOptions *,bool)" (??0TextDiagnosticPrinter@clang@@QEAA@AEAVraw_ostream@llvm@@PEAVDiagnosticOptions@1@_N@Z) referenced in function "class std::unique_ptr<class clang::TextDiagnosticPrinter,struct std::default_delete<class clang::TextDiagnosticPrinter> > __cdecl std::make_unique<class clang::TextDiagnosticPrinter,class llvm::raw_fd_ostream &,class clang::DiagnosticOptions *,0>(class llvm::raw_fd_ostream &,class clang::DiagnosticOptions * &&)" (??$make_unique@VTextDiagnosticPrinter@clang@@AEAVraw_fd_ostream@llvm@@PEAVDiagnosticOptions@2@$0A@@std@@YA?AV?$unique_ptr@VTextDiagnosticPrinter@clang@@U?$default_delete@VTextDiagnosticPrinter@clang@@@std@@@0@AEAVraw_fd_ostream@llvm@@$$QEAPEAVDiagnosticOptions@clang@@@Z)

how do i integrate the clang libs without going the old deprecated way of directly setting include and lib dirs?

thanks for any help

so after reading trough some examples

target_include_directories(llvm-orc-jit PRIVATE ${CLANG_INCLUDE_DIRS} )
target_link_libraries(llvm-orc-jit clangTooling clangCodeGen clangSupport LLVMX86Info LLVMX86TargetMCA LLVMX86CodeGen)

made my linker happy