Skip to content

Commit 9218ff5

Browse files
author
serge-sans-paille
committed
llvmbuildectomy - replace llvm-build by plain cmake
No longer rely on an external tool to build the llvm component layout. Instead, leverage the existing `add_llvm_componentlibrary` cmake function and introduce `add_llvm_component_group` to accurately describe component behavior. These function store extra properties in the created targets. These properties are processed once all components are defined to resolve library dependencies and produce the header expected by llvm-config. Differential Revision: https://reviews.llvm.org/D90848
1 parent b498303 commit 9218ff5

File tree

422 files changed

+1691
-7505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+1691
-7505
lines changed

llvm/CMakeLists.txt

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -714,67 +714,6 @@ if(NOT Python3_Interpreter_FOUND)
714714
set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
715715
endif()
716716

717-
######
718-
# LLVMBuild Integration
719-
#
720-
# We use llvm-build to generate all the data required by the CMake based
721-
# build system in one swoop:
722-
#
723-
# - We generate a file (a CMake fragment) in the object root which contains
724-
# all the definitions that are required by CMake.
725-
#
726-
# - We generate the library table used by llvm-config.
727-
#
728-
# - We generate the dependencies for the CMake fragment, so that we will
729-
# automatically reconfigure ourselves.
730-
731-
set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
732-
set(LLVMCONFIGLIBRARYDEPENDENCIESINC
733-
"${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
734-
set(LLVMBUILDCMAKEFRAG
735-
"${LLVM_BINARY_DIR}/LLVMBuild.cmake")
736-
737-
# Create the list of optional components that are enabled
738-
if (LLVM_USE_INTEL_JITEVENTS)
739-
set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
740-
endif (LLVM_USE_INTEL_JITEVENTS)
741-
if (LLVM_USE_OPROFILE)
742-
set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
743-
endif (LLVM_USE_OPROFILE)
744-
if (LLVM_USE_PERF)
745-
set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} PerfJITEvents)
746-
endif (LLVM_USE_PERF)
747-
748-
message(STATUS "Constructing LLVMBuild project information")
749-
execute_process(
750-
COMMAND "${Python3_EXECUTABLE}" -B ${LLVMBUILDTOOL}
751-
--native-target "${LLVM_NATIVE_ARCH}"
752-
--enable-targets "${LLVM_TARGETS_TO_BUILD}"
753-
--enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
754-
--write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
755-
--write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
756-
OUTPUT_VARIABLE LLVMBUILDOUTPUT
757-
ERROR_VARIABLE LLVMBUILDERRORS
758-
OUTPUT_STRIP_TRAILING_WHITESPACE
759-
ERROR_STRIP_TRAILING_WHITESPACE
760-
RESULT_VARIABLE LLVMBUILDRESULT)
761-
762-
# On Win32, CMake doesn't properly handle piping the default output/error
763-
# streams into the GUI console. So, we explicitly catch and report them.
764-
if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
765-
message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
766-
endif()
767-
if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
768-
message(FATAL_ERROR
769-
"Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
770-
endif()
771-
772-
# Include the generated CMake fragment. This will define properties from the
773-
# LLVMBuild files in a format which is easy to consume from CMake, and will add
774-
# the dependencies so that CMake will reconfigure properly when the LLVMBuild
775-
# files change.
776-
include(${LLVMBUILDCMAKEFRAG})
777-
778717
######
779718

780719
# Configure all of the various header file fragments LLVM uses which depend on

llvm/LLVMBuild.txt

Lines changed: 0 additions & 23 deletions
This file was deleted.

llvm/bindings/LLVMBuild.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,13 @@ function(llvm_add_library name)
616616
endif()
617617
endif()
618618

619+
if(ARG_STATIC)
620+
set(libtype PUBLIC)
621+
else()
622+
# We can use PRIVATE since SO knows its dependent libs.
623+
set(libtype PRIVATE)
624+
endif()
625+
619626
if(ARG_MODULE AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS AND ARG_PLUGIN_TOOL AND (WIN32 OR CYGWIN))
620627
# On DLL platforms symbols are imported from the tool by linking against it.
621628
set(llvm_libs ${ARG_PLUGIN_TOOL})
@@ -630,19 +637,19 @@ function(llvm_add_library name)
630637
endif()
631638
else()
632639
# Components have not been defined explicitly in CMake, so add the
633-
# dependency information for this library as defined by LLVMBuild.
640+
# dependency information for this library through their name, and let
641+
# LLVMBuildResolveComponentsLink resolve the mapping.
634642
#
635643
# It would be nice to verify that we have the dependencies for this library
636644
# name, but using get_property(... SET) doesn't suffice to determine if a
637645
# property has been set to an empty value.
638-
get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
639-
endif()
646+
set_property(TARGET ${name} PROPERTY LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS} ${LLVM_LINK_COMPONENTS})
640647

641-
if(ARG_STATIC)
642-
set(libtype PUBLIC)
643-
else()
644-
# We can use PRIVATE since SO knows its dependent libs.
645-
set(libtype PRIVATE)
648+
# These two properties are internal properties only used to make sure the
649+
# link step applied in LLVMBuildResolveComponentsLink uses the same
650+
# properties as the target_link_libraries call below.
651+
set_property(TARGET ${name} PROPERTY LLVM_LINK_LIBS ${ARG_LINK_LIBS})
652+
set_property(TARGET ${name} PROPERTY LLVM_LIBTYPE ${libtype})
646653
endif()
647654

648655
target_link_libraries(${name} ${libtype}
@@ -723,8 +730,49 @@ function(add_llvm_install_targets target)
723730
endif()
724731
endfunction()
725732

733+
# Define special targets that behave like a component group. They don't have any
734+
# source attached but other components can add themselves to them. If the
735+
# component supports is a Target and it supports JIT compilation, HAS_JIT must
736+
# be passed. One can use ADD_TO_COMPONENT option from add_llvm_component_library
737+
# to link extra component into an existing group.
738+
function(add_llvm_component_group name)
739+
cmake_parse_arguments(ARG "HAS_JIT" "" "LINK_COMPONENTS" ${ARGN})
740+
add_custom_target(${name})
741+
if(ARG_HAS_JIT)
742+
set_property(TARGET ${name} PROPERTY COMPONENT_HAS_JIT ON)
743+
endif()
744+
if(ARG_LINK_COMPONENTS)
745+
set_property(TARGET ${name} PROPERTY LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
746+
endif()
747+
endfunction()
748+
749+
# An LLVM component is a cmake target with the following cmake properties
750+
# eventually set:
751+
# - LLVM_COMPONENT_NAME: the name of the component, which can be the name of
752+
# the associated library or the one specified through COMPONENT_NAME
753+
# - LLVM_LINK_COMPONENTS: a list of component this component depends on
754+
# - COMPONENT_HAS_JIT: (only for group component) whether this target group
755+
# supports JIT compilation
756+
# Additionnaly, the ADD_TO_COMPONENT <component> option make it possible to add this
757+
# component to the LLVM_LINK_COMPONENTS of <component>.
726758
function(add_llvm_component_library name)
727-
add_llvm_library(${name} COMPONENT_LIB ${ARGN})
759+
cmake_parse_arguments(ARG
760+
""
761+
"COMPONENT_NAME;ADD_TO_COMPONENT"
762+
""
763+
${ARGN})
764+
add_llvm_library(${name} COMPONENT_LIB ${ARG_UNPARSED_ARGUMENTS})
765+
string(REGEX REPLACE "^LLVM" "" component_name ${name})
766+
set_property(TARGET ${name} PROPERTY LLVM_COMPONENT_NAME ${component_name})
767+
768+
if(ARG_COMPONENT_NAME)
769+
set_property(GLOBAL PROPERTY LLVM_COMPONENT_NAME_${ARG_COMPONENT_NAME} ${component_name})
770+
endif()
771+
772+
if(ARG_ADD_TO_COMPONENT)
773+
set_property(TARGET ${ARG_ADD_TO_COMPONENT} APPEND PROPERTY LLVM_LINK_COMPONENTS ${component_name})
774+
endif()
775+
728776
endfunction()
729777

730778
macro(add_llvm_library name)

llvm/cmake/modules/LLVM-Build.cmake

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Generate C code in the file provided as OUTPUT that describes the properties
2+
# of all components. This C code is suitable for inclusion in `llvm-config`
3+
function(LLVMBuildGenerateCFragment)
4+
cmake_parse_arguments(ARG "" "OUTPUT" "" ${ARGN})
5+
6+
# Write C header
7+
#################
8+
get_property(llvmbuild_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
9+
foreach(llvmbuild_component ${llvmbuild_components})
10+
string(REGEX REPLACE "^LLVM" "" component_name ${llvmbuild_component})
11+
list(APPEND all_component_libdeps ${component_name})
12+
endforeach()
13+
list(APPEND llvmbuild_components all)
14+
list(APPEND llvmbuild_components all-targets)
15+
list(APPEND llvmbuild_components Engine)
16+
list(APPEND llvmbuild_components Native)
17+
list(APPEND llvmbuild_components NativeCodeGen)
18+
foreach(llvm_target_to_build ${LLVM_TARGETS_TO_BUILD})
19+
list(APPEND llvmbuild_components ${llvm_target_to_build})
20+
endforeach()
21+
22+
list(LENGTH llvmbuild_components llvmbuild_components_size)
23+
file(WRITE ${ARG_OUTPUT}
24+
"
25+
struct AvailableComponent {
26+
/// The name of the component.
27+
const char *Name;
28+
29+
/// The name of the library for this component (or NULL).
30+
const char *Library;
31+
32+
/// Whether the component is installed.
33+
bool IsInstalled;
34+
35+
/// The list of libraries required when linking this component.
36+
const char *RequiredLibraries[${llvmbuild_components_size}];
37+
} AvailableComponents[${llvmbuild_components_size}] = {
38+
")
39+
40+
foreach(llvmbuild_component ${llvmbuild_components})
41+
if(llvmbuild_component STREQUAL "all")
42+
unset(llvmbuild_libname)
43+
set(llvmbuild_libdeps ${all_component_libdeps})
44+
else()
45+
get_property(llvmbuild_libname TARGET ${llvmbuild_component} PROPERTY LLVM_COMPONENT_NAME)
46+
get_property(llvmbuild_libdeps TARGET ${llvmbuild_component} PROPERTY LLVM_LINK_COMPONENTS)
47+
endif()
48+
string(TOLOWER ${llvmbuild_component} llvmbuild_componentname)
49+
50+
if(NOT llvmbuild_libname)
51+
set(llvmbuild_llvmlibname nullptr)
52+
string(TOLOWER ${llvmbuild_component} llvmbuild_libname)
53+
else()
54+
set(llvmbuild_llvmlibname "\"LLVM${llvmbuild_libname}\"")
55+
string(TOLOWER ${llvmbuild_libname} llvmbuild_libname)
56+
endif()
57+
58+
set(llvmbuild_clibdeps "")
59+
foreach(llvmbuild_libdep ${llvmbuild_libdeps})
60+
get_property(llvmbuild_libdepname GLOBAL PROPERTY LLVM_COMPONENT_NAME_${llvmbuild_libdep})
61+
if(NOT llvmbuild_libdepname)
62+
string(TOLOWER ${llvmbuild_libdep} llvmbuild_clibdep)
63+
else()
64+
string(TOLOWER ${llvmbuild_libdepname} llvmbuild_clibdep)
65+
endif()
66+
list(APPEND llvmbuild_clibdeps ${llvmbuild_clibdep})
67+
endforeach()
68+
69+
list(TRANSFORM llvmbuild_clibdeps PREPEND "\"")
70+
list(TRANSFORM llvmbuild_clibdeps APPEND "\"")
71+
list(JOIN llvmbuild_clibdeps ", " llvmbuild_clibdeps_joint)
72+
list(APPEND llvmbuild_centries "{ \"${llvmbuild_libname}\", ${llvmbuild_llvmlibname}, true, {${llvmbuild_clibdeps_joint}} },\n")
73+
endforeach()
74+
75+
list(SORT llvmbuild_centries)
76+
foreach(llvmbuild_centry ${llvmbuild_centries})
77+
file(APPEND ${ARG_OUTPUT} "${llvmbuild_centry}")
78+
endforeach()
79+
file(APPEND ${ARG_OUTPUT} "};")
80+
endfunction()
81+
82+
# Resolve cross-component dependencies, for each available component.
83+
function(LLVMBuildResolveComponentsLink)
84+
get_property(llvm_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
85+
get_property(llvm_has_jit_native TARGET ${LLVM_NATIVE_ARCH} PROPERTY LLVM_HAS_JIT)
86+
if(llvm_has_jit_native)
87+
set_property(TARGET Engine APPEND PROPERTY LLVM_LINK_COMPONENTS "MCJIT" "Native")
88+
else()
89+
set_property(TARGET Engine APPEND PROPERTY LLVM_LINK_COMPONENTS "Interpreter")
90+
endif()
91+
foreach(llvm_component ${llvm_components})
92+
get_property(link_components TARGET ${llvm_component} PROPERTY LLVM_LINK_COMPONENTS)
93+
llvm_map_components_to_libnames(llvm_libs ${link_components})
94+
if(llvm_libs)
95+
get_property(libtype TARGET ${llvm_component} PROPERTY LLVM_LIBTYPE)
96+
target_link_libraries(${llvm_component} ${libtype} ${llvm_libs})
97+
endif()
98+
endforeach()
99+
endfunction()

llvm/cmake/modules/LLVM-Config.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ function(llvm_map_components_to_libnames out_libs)
253253
# Translate symbolic component names to real libraries:
254254
llvm_expand_pseudo_components(link_components ${link_components})
255255
foreach(c ${link_components})
256+
get_property(c_rename GLOBAL PROPERTY LLVM_COMPONENT_NAME_${c})
257+
if(c_rename)
258+
set(c ${c_rename})
259+
endif()
256260
if( c STREQUAL "native" )
257261
# already processed
258262
elseif( c STREQUAL "backend" )

llvm/docs/CodingStandards.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,7 @@ Library Layering
748748
^^^^^^^^^^^^^^^^
749749

750750
A directory of header files (for example ``include/llvm/Foo``) defines a
751-
library (``Foo``). Dependencies between libraries are defined by the
752-
``LLVMBuild.txt`` file in their implementation (``lib/Foo``). One library (both
751+
library (``Foo``). One library (both
753752
its headers and implementation) should only use things from the libraries
754753
listed in its dependencies.
755754

llvm/docs/CommandGuide/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Developer Tools
7373
FileCheck
7474
tblgen
7575
lit
76-
llvm-build
7776
llvm-exegesis
7877
llvm-pdbutil
7978
llvm-locstats

0 commit comments

Comments
 (0)