Skip to content

Commit

Permalink
Merge pull request #1 from kabeor/release/16.x
Browse files Browse the repository at this point in the history
Update LLVM release/16.x
  • Loading branch information
kabeor authored May 8, 2023
2 parents d904e8d + 94c3e21 commit d993874
Show file tree
Hide file tree
Showing 227 changed files with 66,024 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmake/Modules/CMakePolicy.cmake
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 11 additions & 0 deletions cmake/Modules/EnableLanguageNolink.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
macro(llvm_enable_language_nolink)
# Set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY to disable linking
# in the compiler sanity checks. When bootstrapping the toolchain,
# the toolchain itself is still incomplete and sanity checks that include
# linking may fail.
set(__SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
enable_language(${ARGV})
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__SAVED_TRY_COMPILE_TARGET_TYPE})
unset(__SAVED_TRY_COMPILE_TARGET_TYPE)
endmacro()
19 changes: 19 additions & 0 deletions cmake/Modules/ExtendPath.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Extend the path in `base_path` with the path in `current_segment`, returning
# the result in `joined_path`. If `current_segment` is an absolute path then
# just return it, in effect overriding `base_path`, and issue a warning.
#
# Note that the code returns a relative path (avoiding introducing leading
# slashes) if `base_path` is empty.
function(extend_path joined_path base_path current_segment)
if("${current_segment}" STREQUAL "")
set(temp_path "${base_path}")
elseif("${base_path}" STREQUAL "")
set(temp_path "${current_segment}")
elseif(IS_ABSOLUTE "${current_segment}")
message(WARNING "Since \"${current_segment}\" is absolute, it overrides base path: \"${base_path}\".")
set(temp_path "${current_segment}")
else()
set(temp_path "${base_path}/${current_segment}")
endif()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()
155 changes: 155 additions & 0 deletions cmake/Modules/FindGRPC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
option(ENABLE_GRPC_REFLECTION "Link to gRPC Reflection library" OFF)

# FIXME(kirillbobyrev): Check if gRPC and Protobuf headers can be included at
# configure time.
find_package(Threads REQUIRED)
if (GRPC_INSTALL_PATH)
# This setup requires gRPC to be built from sources using CMake and installed
# to ${GRPC_INSTALL_PATH} via -DCMAKE_INSTALL_PREFIX=${GRPC_INSTALL_PATH}.
# Libraries will be linked according to gRPC build policy which generates
# static libraries when BUILD_SHARED_LIBS is Off and dynamic libraries when
# it's On (NOTE: This is a variable passed to gRPC CMake build invocation,
# LLVM's BUILD_SHARED_LIBS has no effect).
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED HINTS ${GRPC_INSTALL_PATH})
message(STATUS "Using protobuf ${Protobuf_VERSION}")
find_package(gRPC CONFIG REQUIRED HINTS ${GRPC_INSTALL_PATH})
message(STATUS "Using gRPC ${gRPC_VERSION}")

include_directories(${Protobuf_INCLUDE_DIRS})

# gRPC CMake CONFIG gives the libraries slightly odd names, make them match
# the conventional system-installed names.
set_target_properties(protobuf::libprotobuf PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(protobuf ALIAS protobuf::libprotobuf)
set_target_properties(gRPC::grpc++ PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(grpc++ ALIAS gRPC::grpc++)
if (ENABLE_GRPC_REFLECTION)
set_target_properties(gRPC::grpc++_reflection PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(grpc++_reflection ALIAS gRPC::grpc++_reflection)
endif()

set(GRPC_CPP_PLUGIN $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
set(PROTOC ${Protobuf_PROTOC_EXECUTABLE})
else()
# This setup requires system-installed gRPC and Protobuf.
# We always link dynamically in this mode. While the static libraries are
# usually installed, the CMake files telling us *which* static libraries to
# link are not.
if (NOT BUILD_SHARED_LIBS)
message(NOTICE "gRPC and Protobuf will be linked dynamically. If you want static linking, build gRPC from sources with -DBUILD_SHARED_LIBS=Off.")
endif()
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin)
find_program(PROTOC protoc)
if (NOT GRPC_CPP_PLUGIN OR NOT PROTOC)
message(FATAL_ERROR "gRPC C++ Plugin and Protoc must be on $PATH for gRPC-enabled build.")
endif()
# On macOS the libraries are typically installed via Homebrew and are not on
# the system path.
set(GRPC_OPTS "")
set(PROTOBUF_OPTS "")
set(GRPC_INCLUDE_PATHS "")
if (${APPLE})
find_program(HOMEBREW brew)
# If Homebrew is not found, the user might have installed libraries
# manually. Fall back to the system path.
if (HOMEBREW)
execute_process(COMMAND ${HOMEBREW} --prefix grpc
OUTPUT_VARIABLE GRPC_HOMEBREW_PATH
RESULT_VARIABLE GRPC_HOMEBREW_RETURN_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${HOMEBREW} --prefix protobuf
OUTPUT_VARIABLE PROTOBUF_HOMEBREW_PATH
RESULT_VARIABLE PROTOBUF_HOMEBREW_RETURN_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${HOMEBREW} --prefix abseil
OUTPUT_VARIABLE ABSL_HOMEBREW_PATH
RESULT_VARIABLE ABSL_HOMEBREW_RETURN_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE)
# If either library is not installed via Homebrew, fall back to the
# system path.
if (GRPC_HOMEBREW_RETURN_CODE EQUAL "0")
list(APPEND GRPC_INCLUDE_PATHS ${GRPC_HOMEBREW_PATH}/include)
list(APPEND GRPC_OPTS PATHS ${GRPC_HOMEBREW_PATH}/lib NO_DEFAULT_PATH)
endif()
if (PROTOBUF_HOMEBREW_RETURN_CODE EQUAL "0")
list(APPEND GRPC_INCLUDE_PATHS ${PROTOBUF_HOMEBREW_PATH}/include)
list(APPEND PROTOBUF_OPTS PATHS ${PROTOBUF_HOMEBREW_PATH}/lib NO_DEFAULT_PATH)
endif()
if (ABSL_HOMEBREW_RETURN_CODE EQUAL "0")
list(APPEND GRPC_INCLUDE_PATHS ${ABSL_HOMEBREW_PATH}/include)
endif()
endif()
endif()
if(NOT TARGET grpc++)
find_library(GRPC_LIBRARY grpc++ ${GRPC_OPTS} REQUIRED)
add_library(grpc++ UNKNOWN IMPORTED GLOBAL)
message(STATUS "Using grpc++: " ${GRPC_LIBRARY})
set_target_properties(grpc++ PROPERTIES IMPORTED_LOCATION ${GRPC_LIBRARY})
target_include_directories(grpc++ INTERFACE ${GRPC_INCLUDE_PATHS})
if (ENABLE_GRPC_REFLECTION)
find_library(GRPC_REFLECTION_LIBRARY grpc++_reflection ${GRPC_OPTS} REQUIRED)
add_library(grpc++_reflection UNKNOWN IMPORTED GLOBAL)
set_target_properties(grpc++_reflection PROPERTIES IMPORTED_LOCATION ${GRPC_REFLECTION_LIBRARY})
endif()
find_library(PROTOBUF_LIBRARY protobuf ${PROTOBUF_OPTS} REQUIRED)
message(STATUS "Using protobuf: " ${PROTOBUF_LIBRARY})
add_library(protobuf UNKNOWN IMPORTED GLOBAL)
set_target_properties(protobuf PROPERTIES IMPORTED_LOCATION ${PROTOBUF_LIBRARY})
endif()
endif()

if (ENABLE_GRPC_REFLECTION)
set(REFLECTION_LIBRARY grpc++_reflection)
endif()

# Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
# Libraries that use these headers should adjust the include path.
# If the "GRPC" argument is given, services are also generated.
# The DEPENDS list should name *.proto source files that are imported.
# They may be relative to the source dir or absolute (for generated protos).
function(generate_proto_sources GeneratedSource ProtoFile)
cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "DEPENDS")
get_filename_component(ProtoSourceAbsolutePath "${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
get_filename_component(Basename ${ProtoSourceAbsolutePath} NAME_WLE)

set(GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/${Basename}.pb.cc")
set(GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/${Basename}.pb.h")
set(Flags
--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
--proto_path="${ProtoSourcePath}")
if (PROTO_GRPC)
list(APPEND Flags
--grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
--plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}")
list(APPEND GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/${Basename}.grpc.pb.cc")
list(APPEND GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/${Basename}.grpc.pb.h")
endif()
add_custom_command(
OUTPUT ${GeneratedProtoSource} ${GeneratedProtoHeader}
COMMAND ${PROTOC}
ARGS ${Flags} "${ProtoSourceAbsolutePath}"
DEPENDS "${ProtoSourceAbsolutePath}")

set(${GeneratedSource} ${GeneratedProtoSource} PARENT_SCOPE)

# Ensure dependency headers are generated before dependent protos are built.
# DEPENDS arg is a list of "Foo.proto". While they're logically relative to
# the source dir, the generated headers we need are in the binary dir.
foreach(ImportedProto IN LISTS PROTO_DEPENDS)
# Foo.proto -> Foo.pb.h
STRING(REGEX REPLACE "\\.proto$" ".pb.h" ImportedHeader "${ImportedProto}")
# Foo.pb.h -> ${CMAKE_CURRENT_BINARY_DIR}/Foo.pb.h
get_filename_component(ImportedHeader "${ImportedHeader}"
ABSOLUTE
BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
# Compilation of each generated source depends on ${BINARY}/Foo.pb.h.
foreach(Generated IN LISTS GeneratedProtoSource)
# FIXME: CMake docs suggest OBJECT_DEPENDS isn't needed, but I can't get
# the recommended add_dependencies() approach to work.
set_source_files_properties("${Generated}"
PROPERTIES OBJECT_DEPENDS "${ImportedHeader}")
endforeach(Generated)
endforeach(ImportedProto)
endfunction()
66 changes: 66 additions & 0 deletions cmake/Modules/FindLibEdit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#.rst:
# FindLibEdit
# -----------
#
# Find libedit library and headers
#
# The module defines the following variables:
#
# ::
#
# LibEdit_FOUND - true if libedit was found
# LibEdit_INCLUDE_DIRS - include search path
# LibEdit_LIBRARIES - libraries to link
# LibEdit_VERSION_STRING - version number

find_package(PkgConfig QUIET)
pkg_check_modules(PC_LIBEDIT QUIET libedit)

find_path(LibEdit_INCLUDE_DIRS NAMES histedit.h HINTS ${PC_LIBEDIT_INCLUDE_DIRS})
find_library(LibEdit_LIBRARIES NAMES edit HINTS ${PC_LIBEDIT_LIBRARY_DIRS})

include(CheckIncludeFile)
if(LibEdit_INCLUDE_DIRS AND EXISTS "${LibEdit_INCLUDE_DIRS}/histedit.h")
include(CMakePushCheckState)
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})
check_include_file(histedit.h HAVE_HISTEDIT_H)
cmake_pop_check_state()
if (HAVE_HISTEDIT_H)
file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
libedit_major_version_str
REGEX "^#define[ \t]+LIBEDIT_MAJOR[ \t]+[0-9]+")
string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MAJOR[ \t]+([0-9]+)" "\\1"
libedit_major_version "${libedit_major_version_str}")

file(STRINGS "${LibEdit_INCLUDE_DIRS}/histedit.h"
libedit_minor_version_str
REGEX "^#define[ \t]+LIBEDIT_MINOR[ \t]+[0-9]+")
string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MINOR[ \t]+([0-9]+)" "\\1"
libedit_minor_version "${libedit_minor_version_str}")

set(LibEdit_VERSION_STRING "${libedit_major_version}.${libedit_minor_version}")
else()
set(LibEdit_INCLUDE_DIRS "")
set(LibEdit_LIBRARIES "")
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibEdit
FOUND_VAR
LibEdit_FOUND
REQUIRED_VARS
LibEdit_INCLUDE_DIRS
LibEdit_LIBRARIES
VERSION_VAR
LibEdit_VERSION_STRING)
mark_as_advanced(LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES)

if (LibEdit_FOUND AND NOT TARGET LibEdit::LibEdit)
add_library(LibEdit::LibEdit UNKNOWN IMPORTED)
set_target_properties(LibEdit::LibEdit PROPERTIES
IMPORTED_LOCATION ${LibEdit_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${LibEdit_INCLUDE_DIRS})
endif()
53 changes: 53 additions & 0 deletions cmake/Modules/FindPrefixFromConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Find the prefix from the `*Config.cmake` file being generated.
#
# When generating an installed `*Config.cmake` file, we often want to be able
# to refer to the ancestor directory which contains all the installed files.
#
# We want to do this without baking in an absolute path when the config file is
# generated, in order to allow for a "relocatable" binary distribution that
# doesn't need to know what path it ends up being installed at when it is
# built.
#
# The solution that we know the relative path that the config file will be at
# within that prefix, like `"${prefix_var}/lib/cmake/${project}"`, so we count
# the number of components in that path to figure out how many parent dirs we
# need to traverse from the location of the config file to get to the prefix
# dir.
#
# out_var:
# variable to set the "return value" of the function, which is the code to
# include in the config file under construction.
#
# prefix_var:
# Name of the variable to define in the returned code (not directory for the
# faller!) that will contain the prefix path.
#
# path_to_leave:
# Path from the prefix to the config file, a relative path which we wish to
# go up and out from to find the prefix directory.
function(find_prefix_from_config out_var prefix_var path_to_leave)
if(IS_ABSOLUTE "${path_to_leave}")
# Because the path is absolute, we don't care about `path_to_leave`
# because we can just "jump" to the absolute path rather than work
# our way there relatively.
set(config_code
"# Installation prefix is fixed absolute path"
"set(${prefix_var} \"${CMAKE_INSTALL_PREFIX}\")")
else()
# `path_to_leave` is relative. Relative to what? The install prefix.
# We therefore go up enough parent directories to get back to the
# install prefix, and avoid hard-coding any absolute paths.
set(config_code
"# Compute the installation prefix from this LLVMConfig.cmake file location."
"get_filename_component(${prefix_var} \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
# Construct the proper number of get_filename_component(... PATH)
# calls to compute the installation prefix.
string(REGEX REPLACE "/" ";" _count "${path_to_leave}")
foreach(p ${_count})
list(APPEND config_code
"get_filename_component(${prefix_var} \"\${${prefix_var}}\" PATH)")
endforeach(p)
endif()
string(REPLACE ";" "\n" config_code "${config_code}")
set("${out_var}" "${config_code}" PARENT_SCOPE)
endfunction()
33 changes: 33 additions & 0 deletions cmake/Modules/GNUInstallPackageDir.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Mimick `GNUInstallDirs` for one more install directory, the one where
# project's installed cmake subdirs go.

# These functions are internal functions vendored in from GNUInstallDirs (with
# new names), so we don't depend on unstable implementation details. They are
# also simplified to only handle the cases we need.
#
# The purpose would appear to be making `CACHE PATH` vars in a way that
# bypasses the legacy oddity that `-D<PATH>` gets canonicalized, despite
# non-canonical `CACHE PATH`s being perfectly valid.

macro(_GNUInstallPackageDir_cache_convert_to_path var description)
get_property(_GNUInstallPackageDir_cache_type CACHE ${var} PROPERTY TYPE)
if(_GNUInstallPackageDir_cache_type STREQUAL "UNINITIALIZED")
file(TO_CMAKE_PATH "${${var}}" _GNUInstallPackageDir_cmakepath)
set_property(CACHE ${var} PROPERTY TYPE PATH)
set_property(CACHE ${var} PROPERTY VALUE "${_GNUInstallPackageDir_cmakepath}")
set_property(CACHE ${var} PROPERTY HELPSTRING "${description}")
unset(_GNUInstallPackageDir_cmakepath)
endif()
unset(_GNUInstallPackageDir_cache_type)
endmacro()

# Create a cache variable with default for a path.
macro(_GNUInstallPackageDir_cache_path var default description)
if(NOT DEFINED ${var})
set(${var} "${default}" CACHE PATH "${description}")
endif()
_GNUInstallPackageDir_cache_convert_to_path("${var}" "${description}")
endmacro()

_GNUInstallPackageDir_cache_path(CMAKE_INSTALL_PACKAGEDIR "lib${LLVM_LIBDIR_SUFFIX}/cmake"
"Directories containing installed CMake modules (lib/cmake)")
Loading

0 comments on commit d993874

Please sign in to comment.