Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.13.4) +if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) + set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +endif() +include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) + # If we are not building as a part of LLVM, build Clang as an # standalone project, using LLVM as an external library: if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) @@ -136,10 +142,6 @@ endif() # LLVM_INCLUDE_TESTS endif() # standalone -if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) - set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) -endif() - # Make sure that our source directory is on the current cmake module path so that # we can include cmake files from this directory. list(INSERT CMAKE_MODULE_PATH 0 Index: cmake/Modules/CMakePolicy.cmake =================================================================== --- /dev/null +++ cmake/Modules/CMakePolicy.cmake @@ -0,0 +1,12 @@ +# CMake policy settings shared between LLVM projects + +# CMP0114: ExternalProject step targets fully adopt their steps. +# New in CMake 3.19: https://cmake.org/cmake/help/latest/policy/CMP0114.html +if(POLICY CMP0114) + cmake_policy(SET CMP0114 OLD) +endif() +# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()` +# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html +if(POLICY CMP0116) + cmake_policy(SET CMP0116 OLD) +endif() Index: flang/CMakeLists.txt =================================================================== --- flang/CMakeLists.txt +++ flang/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.13.4) +if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) + set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +endif() +include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) + set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) # Flang requires C++17. @@ -233,10 +239,6 @@ ${FLANG_BINARY_DIR}/include ${FLANG_SOURCE_DIR}/include) -if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) - set(LLVM_COMMON_CMAKE_UTILS ${FLANG_SOURCE_DIR}/../cmake) -endif() - # Add Flang-centric modules to cmake path. list(INSERT CMAKE_MODULE_PATH 0 "${FLANG_SOURCE_DIR}/cmake/modules" Index: lld/CMakeLists.txt =================================================================== --- lld/CMakeLists.txt +++ lld/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.13.4) +if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) + set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +endif() +include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) + # If we are not building as a part of LLVM, build LLD as an # standalone project, using LLVM as an external library: if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) @@ -140,10 +146,6 @@ "`CMakeFiles'. Please delete them.") endif() -if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) - set(LLVM_COMMON_CMAKE_UTILS ${LLD_SOURCE_DIR}/../cmake) -endif() - # Add path for custom modules. list(INSERT CMAKE_MODULE_PATH 0 "${LLD_SOURCE_DIR}/cmake/modules" Index: lldb/CMakeLists.txt =================================================================== --- lldb/CMakeLists.txt +++ lldb/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.13.4) +if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) + set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +endif() +include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) + # Add path for custom modules. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} Index: lldb/cmake/modules/LLDBStandalone.cmake =================================================================== --- lldb/cmake/modules/LLDBStandalone.cmake +++ lldb/cmake/modules/LLDBStandalone.cmake @@ -1,9 +1,3 @@ -# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()` -# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html -if(POLICY CMP0116) - cmake_policy(SET CMP0116 OLD) -endif() - if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) endif() Index: llvm/CMakeLists.txt =================================================================== --- llvm/CMakeLists.txt +++ llvm/CMakeLists.txt @@ -2,16 +2,9 @@ cmake_minimum_required(VERSION 3.13.4) -# CMP0114: ExternalProject step targets fully adopt their steps. -# New in CMake 3.19: https://cmake.org/cmake/help/latest/policy/CMP0114.html -if(POLICY CMP0114) - cmake_policy(SET CMP0114 OLD) -endif() -# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()` -# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html -if(POLICY CMP0116) - cmake_policy(SET CMP0116 OLD) -endif() +set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) @@ -281,8 +274,6 @@ set(LLVM_GISEL_COV_PREFIX "${CMAKE_BINARY_DIR}/gisel-coverage-" CACHE STRING "Provide a filename prefix to collect the GlobalISel rule coverage") endif() -set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) - # Add path for custom modules list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake" Index: mlir/CMakeLists.txt =================================================================== --- mlir/CMakeLists.txt +++ mlir/CMakeLists.txt @@ -1,4 +1,11 @@ # MLIR project. +cmake_minimum_required(VERSION 3.13.4) + +if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) + set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) +endif() +include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) # Check if MLIR is built as a standalone project. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) @@ -10,8 +17,6 @@ include(GNUInstallDirs) if(MLIR_STANDALONE_BUILD) - cmake_minimum_required(VERSION 3.13.4) - find_package(LLVM CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) include(HandleLLVMOptions) @@ -46,10 +51,6 @@ set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) set(MLIR_TOOLS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) -if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) - set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) -endif() - # Make sure that our source directory is on the current cmake module path so # that we can include cmake files from this directory. list(INSERT CMAKE_MODULE_PATH 0