TLDR
I want to build the LLVM project monorepo as a subdirectory to a larger CMake project. But the usual paradigm of add_subdirectory(llvm-project/llvm)
doesn't give the desired results. How can I add LLVM to my CMake project so that building the project also builds LLVM?
Background
I have project tree that looks like this (some files and subdirectories omitted for brevity) :
.
├── build/
├── CMakeLists.txt
├── cunit/
│ ├── CUnit/
│ │ └── CMakeLists.txt
│ └── CMakeLists.txt
├── hayai/
│ └── CMakeLists.txt
├── install/
├── llvm-project/
│ ├── clang/
│ ├── clang-tools-extra/
│ ├── compiler-rt/
│ ├── debuginfo-tests/
│ ├── libcxx/
│ ├── libcxxabi/
│ ├── libunwind/
│ ├── lld/
│ ├── lldb/
│ ├── llvm/
│ │ └── CMakeLists.txt
│ ├── openmp/
│ └── polly/
└── mylib/
└── CMakeLists.txt
As you can see, I have four subdirectories, all of which are CMake projects in their own right, and all of which build individually with no problems. Both CUnit and Hayai are unmodified. Mylib is the product of my research, and uses CUnit and Hayai as git submodules/dependencies. I have also modified the LLVM Project monorepo to use Mylib for instrumentation as part of my research, but it builds on its own. I would like to unify all four of these subprojects as one CMake-driven build.
The content of the top-level CMakeLists.txt is:
cmake_minimum_required(VERSION 3.2)
project (myproject)
set(CMAKE_BUILD_TYPE Debug)
add_subdirectory(cunit/CUnit)
add_subdirectory(hayai)
add_subdirectory(mylib)
add_subdirectory(llvm-project/llvm)
Problem
When I try to generate the build using the following command:
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_BUILD_TYPE=Debug -DBUILD_HAYAI_SAMPLES=false -DBUILD_HAYAI_TESTS=false
I get an error from CMake once it recurses into the LLVM subproject (shortened for brevity):
-- LLVM host triple: x86_64-unknown-linux-gnu
-- LLVM default target triple: x86_64-unknown-linux-gnu
-- Building with -fPIC
-- Constructing LLVMBuild project information
-- Linker detection: GNU ld
CMake Error: File ./llvm-project/llvm/include/llvm/module.modulemap.build does not exist.
CMake Error at ./llvm-project/llvm/include/llvm/CMakeLists.txt:7 (configure_file):
configure_file Problem configuring file
-- Targeting AArch64
-- Targeting AMDGPU
-- Targeting ARM
-- Targeting BPF
-- Targeting Hexagon
-- Targeting Lanai
-- Targeting Mips
-- Targeting MSP430
-- Targeting NVPTX
-- Targeting PowerPC
-- Targeting Sparc
-- Targeting SystemZ
-- Targeting X86
-- Targeting XCore
-- Configuring incomplete, errors occurred!
See also "./build/CMakeFiles/CMakeOutput.log".
See also "./build/CMakeFiles/CMakeError.log".
llvm-project/llvm/include/llvm/CMakeLists.txt contains:
add_subdirectory(IR)
add_subdirectory(Support)
# If we're doing an out-of-tree build, copy a module map for generated
# header files into the build area.
if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
configure_file(module.modulemap.build module.modulemap COPYONLY)
endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
I checked the two files at the end of the output, but neither had messages relevant to the problem.
Questions
- What does the error from CMake really mean? Why doesn't module.modulemap.build exist, or more accurately, why does it exist when building just LLVM?
- How can I fix this so that my top level project can build all four subprojects?
Potentially Related
- This StackOverflow question asks a similar question using a lot of the same keywords, but has a different task in mind: she/he wants to link to libraries from an existing LLVM build, not build LLVM itself.
- Likewise this StackOverflow question and the accepted answer's reference to this LLVM documentation page is about embedding LLVM libraries out of tree into a standalone project. It's not quite what I want since I need to build my entire modified LLVM compiler toolchain.
- This llvm-dev mailing list thread sounds like exactly what I'm doing, but the suggested answer doesn't work, as stated above.