[cmake] Make include(GNUInstallDirs) always below project(..)

Its defaulting logic must go after `project(..)` to work correctly,  but `project(..)` is often in a standalone condition making this
awkward, since the rest of the condition code may also need GNUInstallDirs.

The good thing is there are the various standalone booleans, which I had missed before. This makes splitting the conditional blocks less awkward.

Reviewed By: arichardson, phosek, beanz, ldionne, #libunwind, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D117639
This commit is contained in:
John Ericson 2022-01-19 06:45:07 +00:00
parent c65186c89f
commit df31ff1b29
12 changed files with 72 additions and 39 deletions

View File

@ -7,8 +7,6 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)
include(GNUInstallDirs)
set(FLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
@ -27,7 +25,14 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message("Building Flang as a standalone project.")
project(Flang)
set(FLANG_STANDALONE_BUILD ON)
else()
set(FLANG_STANDALONE_BUILD OFF)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if (FLANG_STANDALONE_BUILD)
set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
if (NOT MSVC_IDE)
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
@ -179,7 +184,6 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif()
else()
set(FLANG_STANDALONE_BUILD OFF)
option(FLANG_INCLUDE_TESTS
"Generate build targets for the Flang unit tests."
${LLVM_INCLUDE_TESTS})

View File

@ -10,8 +10,6 @@ endif()
#===============================================================================
cmake_minimum_required(VERSION 3.13.4)
include(GNUInstallDirs)
set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
# Add path for custom modules
@ -39,14 +37,17 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUIL
# In a standalone build, we don't have llvm to automatically generate the
# llvm-lit script for us. So we need to provide an explicit directory that
# the configurator should write the script into.
set(LIBCXX_STANDALONE_BUILD 1)
set(LIBCXX_STANDALONE_BUILD TRUE)
set(LLVM_LIT_OUTPUT_DIR "${LIBCXX_BINARY_DIR}/bin")
# Find the LLVM sources and simulate LLVM CMake options.
include(HandleOutOfTreeLLVM)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if (LIBCXX_STANDALONE_BUILD)
# Find the LLVM sources and simulate LLVM CMake options.
include(HandleOutOfTreeLLVM)
find_package(Python3 COMPONENTS Interpreter)
if(NOT Python3_Interpreter_FOUND)
message(SEND_ERROR "Python3 not found. Python3 is required")

View File

@ -10,8 +10,6 @@ endif()
cmake_minimum_required(VERSION 3.13.4)
include(GNUInstallDirs)
set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
# Add path for custom modules
@ -37,17 +35,21 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_B
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
set(LIBCXXABI_STANDALONE_BUILD TRUE)
# In a standalone build, we don't have llvm to automatically generate the
# llvm-lit script for us. So we need to provide an explicit directory that
# the configurator should write the script into.
set(LIBCXXABI_STANDALONE_BUILD 1)
set(LLVM_LIT_OUTPUT_DIR "${LIBCXXABI_BINARY_DIR}/bin")
# Find the LLVM sources and simulate LLVM CMake options.
include(HandleOutOfTreeLLVM)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if (LIBCXXABI_STANDALONE_BUILD)
# Find the LLVM sources and simulate LLVM CMake options.
include(HandleOutOfTreeLLVM)
find_package(Python3 COMPONENTS Interpreter)
if(NOT Python3_Interpreter_FOUND)
message(WARNING "Python3 not found, using python2 as a fallback")

View File

@ -8,8 +8,6 @@ endif()
cmake_minimum_required(VERSION 3.13.4)
include(GNUInstallDirs)
set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
# Add path for custom modules
@ -30,21 +28,28 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_B
# linking.
include(EnableLanguageNolink)
project(libunwind LANGUAGES NONE)
llvm_enable_language_nolink(C CXX ASM)
set(PACKAGE_NAME libunwind)
set(PACKAGE_VERSION 14.0.0git)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
# In a standalone build, we don't have llvm to automatically generate the
# llvm-lit script for us. So we need to provide an explicit directory that
# the configurator should write the script into.
set(LIBUNWIND_STANDALONE_BUILD 1)
set(LLVM_LIT_OUTPUT_DIR "${LIBUNWIND_BINARY_DIR}/bin")
set(LIBUNWIND_STANDALONE_BUILD TRUE)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if(LIBUNWIND_STANDALONE_BUILD)
llvm_enable_language_nolink(C CXX ASM)
# Find the LLVM sources and simulate LLVM CMake options.
include(HandleOutOfTreeLLVM)
# In a standalone build, we don't have llvm to automatically generate the
# llvm-lit script for us. So we need to provide an explicit directory that
# the configurator should write the script into.
set(LLVM_LIT_OUTPUT_DIR "${LIBUNWIND_BINARY_DIR}/bin")
else()
set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py")
endif()

View File

@ -1,12 +1,16 @@
cmake_minimum_required(VERSION 3.13.4)
include(GNUInstallDirs)
# 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)
project(lld)
set(LLD_BUILT_STANDALONE TRUE)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if(LLD_BUILT_STANDALONE)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Rely on llvm-config.
@ -140,8 +144,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
if(LLVM_HAVE_LIBXAR)
set(XAR_LIB xar)
endif()
set(LLD_BUILT_STANDALONE TRUE)
endif() # standalone
set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.13.4)
include(GNUInstallDirs)
# Add path for custom modules.
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
@ -13,6 +11,13 @@ set(CMAKE_MODULE_PATH
# using LLVM as an external library.
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
project(lldb)
set(LLDB_BUILT_STANDALONE TRUE)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if(LLDB_BUILT_STANDALONE)
include(LLDBStandalone)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")

View File

@ -108,5 +108,3 @@ include_directories(
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
set(LLDB_BUILT_STANDALONE 1)

View File

@ -2,7 +2,12 @@ cmake_minimum_required(VERSION 3.13.4)
project(Debugserver LANGUAGES C CXX ASM-ATT)
# Must go below project(..)
include(GNUInstallDirs)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(LLDB_BUILT_STANDALONE TRUE)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_SOURCE_DIR}/../../cmake"

View File

@ -2,8 +2,6 @@
cmake_minimum_required(VERSION 3.13.4)
include(GNUInstallDirs)
# 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)
@ -47,6 +45,9 @@ project(LLVM
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
LANGUAGES C CXX ASM)
# Must go after project(..)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
if (CYGWIN)

View File

@ -1,10 +1,15 @@
# MLIR project.
include(GNUInstallDirs)
# Check if MLIR is built as a standalone project.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
project(mlir)
set(MLIR_STANDALONE_BUILD TRUE)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if(MLIR_STANDALONE_BUILD)
cmake_minimum_required(VERSION 3.13.4)
find_package(LLVM CONFIG REQUIRED)

View File

@ -1,10 +1,14 @@
include(GNUInstallDirs)
# Check if this is a in tree build.
if (NOT DEFINED LLVM_MAIN_SRC_DIR)
project(Polly)
cmake_minimum_required(VERSION 3.13.4)
set(POLLY_STANDALONE_BUILD TRUE)
endif()
# Must go below project(..)
include(GNUInstallDirs)
if(POLLY_STANDALONE_BUILD)
# Where is LLVM installed?
find_package(LLVM CONFIG REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})

View File

@ -7,8 +7,6 @@
#===----------------------------------------------------------------------===##
cmake_minimum_required(VERSION 3.13.4)
include(GNUInstallDirs)
set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
@ -18,6 +16,9 @@ math(EXPR VERSION_PATCH "(${PARALLELSTL_VERSION_SOURCE} % 10)")
project(ParallelSTL VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} LANGUAGES CXX)
# Must go below project(..)
include(GNUInstallDirs)
set(PSTL_PARALLEL_BACKEND "serial" CACHE STRING "Threading backend to use. Valid choices are 'serial', 'omp', and 'tbb'. The default is 'serial'.")
set(PSTL_HIDE_FROM_ABI_PER_TU OFF CACHE BOOL "Whether to constrain ABI-unstable symbols to each translation unit (basically, mark them with C's static keyword).")
set(_PSTL_HIDE_FROM_ABI_PER_TU ${PSTL_HIDE_FROM_ABI_PER_TU}) # For __pstl_config_site