diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf60065..61742c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -630,11 +630,65 @@ jobs: if-no-files-found: error path: | ${{ github.workspace }}/build/archive/* + +#------------------------------------------------------------------------------ +# BUILD INSIDE DOCKER INSIDE LLVM-SOURCE-TREE +#------------------------------------------------------------------------------ + in-source-tree: + runs-on: ubuntu-22.04 + name: ${{ matrix.config.name }} LLVM source tree + container: + image: andreasfertig/cppinsights-builder + continue-on-error: false + strategy: + fail-fast: false + matrix: + arch: + - amd64 + + config: + # GCC 13 / LLVM 18 + - { + name: "GCC 13 / LLVM 18 @ Ubuntu Release", + build_type: Release, + cxx: "g++-13", + llvm_version: "18.1.0", + llvm_config: "/usr/bin/llvm-config-18", + coverage: "No", + static: "Yes", + debug: "No", + libcxx: "No", + } + + steps: + - uses: actions/checkout@v4 + with: + path: cppinsights + + - uses: actions/checkout@v4 + name: Checkout Clang + with: + repository: llvm/llvm-project + ref: llvmorg-${{ env.LLVM_VERSION }} + path: llvm-project + fetch-tags: true + + - name: Configure + id: cmake_configure + shell: bash + run: | + mkdir build + cd build + + CXX=${{ matrix.config.cxx }} + cmake -G Ninja -D=CMAKE_BUILD_TYPE=Release -DLLVM_EXTERNAL_PROJECTS=cppinsights -DLLVM_EXTERNAL_CPPINSIGHTS_SOURCE_DIR=${GITHUB_WORKSPACE}/cppinsights -DINSIGHTS_STATIC=${{ matrix.config.static }} -DDEBUG=${{ matrix.config.debug }} -DINSIGHTS_COVERAGE=${{ matrix.config.coverage }} -DINSIGHTS_USE_LIBCPP=${{ matrix.config.libcxx }} ${GITHUB_WORKSPACE}/llvm-project/llvm + # For now a successful configure is enough + #------------------------------------------------------------------------------ # DEPLOY #------------------------------------------------------------------------------ deploy: - needs: [build, docker] + needs: [build, docker, in-source-tree] if: github.ref == 'refs/heads/main' name: Final Deploy continue-on-error: false diff --git a/CMakeLists.txt b/CMakeLists.txt index aee8b0b..6ef0b8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,8 +35,18 @@ set(INSIGHTS_LLVM_CONFIG "llvm-config" CACHE STRING "LLVM config executable to u set(INSIGHTS_MIN_LLVM_MAJOR_VERSION 18) set(INSIGHTS_MIN_LLVM_VERSION ${INSIGHTS_MIN_LLVM_MAJOR_VERSION}.0) -if(NOT DEFINED LLVM_VERSION_MAJOR) # used when build inside the clang tool/extra folder +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(BUILD_INSIGHTS_OUTSIDE_LLVM On) +else() + # used when build inside the clang tool/extra folder + set(BUILD_INSIGHTS_OUTSIDE_LLVM Off) + include_directories(BEFORE + ${LLVM_SOURCE_DIR}/include + ${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include + ${LLVM_BINARY_DIR}/include + ${LLVM_BINARY_DIR}/tools/clang/include + ) + endif() if(INSIGHTS_COVERAGE OR DEBUG) @@ -367,11 +377,6 @@ if (BUILD_INSIGHTS_OUTSIDE_LLVM) set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COVERAGE_LINK_FLAGS}") endif() - # copied from: llvm/tools/clang/cmake/modules/AddClang.cmake - macro(add_clang_tool name) - add_executable( ${name} ${ARGN} ) - endmacro(add_clang_tool) - # additional libs required when building insights outside llvm set(ADDITIONAL_LIBS ${LLVM_LDFLAGS} @@ -422,6 +427,12 @@ if (${LLVM_PACKAGE_VERSION} VERSION_LESS ${INSIGHTS_MIN_LLVM_VERSION}) message(FATAL_ERROR "LLVM version ${INSIGHTS_MIN_LLVM_VERSION} or higher required. Current version is: ${LLVM_PACKAGE_VERSION}.") endif() +# copied from: llvm/tools/clang/cmake/modules/AddClang.cmake +macro(add_clang_tool name) + add_executable( ${name} ${ARGN} ) +endmacro(add_clang_tool) + + if(WIN32) # First for the generic no-config case (e.g. with mingw) @@ -815,6 +826,7 @@ endif() message(STATUS "") message(STATUS "[ Build summary ]") +message(STATUS "BUILD_INSIGHTS_OUTSIDE_LLVM : ${BUILD_INSIGHTS_OUTSIDE_LLVM}") message(STATUS "CMAKE_GENERATOR : ${CMAKE_GENERATOR}") message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") message(STATUS "CMAKE_LINKER : ${CMAKE_LINKER}") diff --git a/Readme.md b/Readme.md index d55cce8..5d60106 100644 --- a/Readme.md +++ b/Readme.md @@ -130,6 +130,7 @@ See https://github.com/andreasfertig/cppinsights/issues/186 for an explanation o `extra/clang` and `extra/llvm` provide `/usr/lib/{libclangAST.so,libLLVM*.a,libLLVM.so}`. `libclangAST.so` needs `libLLVM.so` and there would be a conflict if `libLLVM*.a` (instead of `libLLVM.so`) are linked. See https://bugs.archlinux.org/task/60512 + ### Building outside Clang You need to have a Clang installation in the search path. @@ -144,23 +145,20 @@ The resulting binary (insights) can be found in the `build` folder. ### Building inside Clang -For building it inside the Clang source tree, assuming you have your source tree already prepared under `llvm-project`: +The easiest way to build C++ Insights inside the Clang source tree is using the `LLVM_EXTERNAL_PROJECTS` option. ``` -cd llvm-project/clang-tools-extra/ +git clone https://github.com/llvm/llvm-project.git git clone https://github.com/andreasfertig/cppinsights.git -echo "add_subdirectory(cppinsights)" >> CMakeLists.txt -``` - -To activate the C++ Insights build you have to set `-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"` for `cmake`: +mkdir build +cd build +cmake -G Ninja -D=CMAKE_BUILD_TYPE=Release -DLLVM_EXTERNAL_PROJECTS=cppinsights -DLLVM_EXTERNAL_CPPINSIGHTS_SOURCE_DIR= [INSIGHTS CMAKE OPTIONS] ../llvm-project/llvm -``` -cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -G "Unix Makefiles" ../llvm-project +ninja ``` -Then, build Clang as you normally do. ### cmake options