Currently, cmake policies are manually maintained by each project. This is done via a set of cmake_policy()
commands following the initial cmake_minimum_required()
command at the top of each CMakeLists.txt project file.
Somewhat surprisingly, these sets are local to each project and independent of each other ā even for in-tree builds containing multiple sub-projects. This is because cmake policies are reset whenever cmake_minimum_required()
is called, which is the first command in each of our CMakeLists.txt project files.
In order to solve this problem, as well as improve maintainability, Iād like to propose the following:
-
For all projects except llvm, move
cmake_minimum_required()
inside the standalone build if-branch, i.e.,if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
, at the top of the CMakeLists.txt project file. This will prevent unnecessary callscmake_minimum_required()
for in-tree builds, and allow all sub-projects to use the same policies set by llvm. -
Move all
cmake_policy()
commands out of llvm/CMakeLists.txt and into a separate file, e.g., AddLLVM.cmake, which is always included in each project. This will guarantee all projects use the same set of policies even when built as a standalone or external project, e.g., runtimes.
Sub-projects can still override policies as needed by setting them after including AddLLVM.cmake, or by using cmake_policy(PUSH|POP)
for local changes.