diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -385,7 +385,11 @@ # STATIC by default w/o BUILD_SHARED_LIBS. # SHARED by default w/ BUILD_SHARED_LIBS. # OBJECT -# Also create an OBJECT library target. Default if STATIC && SHARED. +# Create an OBJECT library target. +# If STATIC or SHARED are +# also specified, create an OBJECT library target named obj.${name} in +# addition to those. +# If both STATIC && SHARED are specified, OBJECT is implied. # MODULE # Target ${name} might not be created on unsupported platforms. # Check with "if(TARGET ${name})". @@ -430,6 +434,16 @@ llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS}) endif() + set(stand_alone_object_lib FALSE) + if(NOT ARG_SHARED AND NOT ARG_STATIC AND ARG_OBJECT) + set(stand_alone_object_lib TRUE) + endif() + + set(extra_obj_lib FALSE) + if (ARG_SHARED AND ARG_STATIC OR (ARG_OBJECT AND NOT stand_alone_object_lib)) + set(extra_obj_lib TRUE) + endif() + if(ARG_MODULE) if(ARG_SHARED OR ARG_STATIC) message(WARNING "MODULE with SHARED|STATIC doesn't make sense.") @@ -446,13 +460,13 @@ if(BUILD_SHARED_LIBS AND NOT ARG_STATIC) set(ARG_SHARED TRUE) endif() - if(NOT ARG_SHARED) + if(NOT ARG_SHARED AND NOT stand_alone_object_lib) set(ARG_STATIC TRUE) endif() endif() - # Generate objlib - if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT) + # Generate the extra objlib + if(extra_obj_lib) # Generate an obj library for both targets. set(obj_name "obj.${name}") add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL @@ -517,8 +531,10 @@ elseif(ARG_SHARED) add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) add_library(${name} SHARED ${ALL_FILES}) - else() + elseif(ARG_STATIC) add_library(${name} STATIC ${ALL_FILES}) + else() + add_library(${name} OBJECT ${ALL_FILES}) endif() if(ARG_COMPONENT_LIB) @@ -629,11 +645,11 @@ get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) endif() - if(ARG_STATIC) - set(libtype PUBLIC) - else() + if(ARG_SHARED) # We can use PRIVATE since SO knows its dependent libs. set(libtype PRIVATE) + else() + set(libtype PUBLIC) endif() target_link_libraries(${name} ${libtype} @@ -669,6 +685,27 @@ endif() endfunction() +# Add a target which is logically and deployment-wise part of another one +# (owner), but - perhaps because it has optional build dependencies - may be +# built separately. +# The owner consumes it via target_link_libraries (or equivalent syntax). +# +# PUBLIC creates an OBJECT library, so linking it in the owner translates to +# linking the object files in this target as if they were built by the owner. +# +# PRIVATE creates a STATIC library, so linking it would drop objects that are +# not referenced. +macro (add_implementation_detail name) + cmake_parse_arguments(ARG "PUBLIC;PRIVATE" "" "" ${ARGN}) + if (ARG_PUBLIC) + add_llvm_library(${name} OBJECT DISABLE_LLVM_LINK_LLVM_DYLIB + ${ARG_UNPARSED_ARGUMENTS}) + else() + add_llvm_library(${name} STATIC DISABLE_LLVM_LINK_LLVM_DYLIB + ${ARG_UNPARSED_ARGUMENTS}) + endif() +endmacro() + function(add_llvm_install_targets target) cmake_parse_arguments(ARG "" "COMPONENT;PREFIX;SYMLINK" "DEPENDS" ${ARGN}) if(ARG_COMPONENT) diff --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt --- a/llvm/lib/Analysis/CMakeLists.txt +++ b/llvm/lib/Analysis/CMakeLists.txt @@ -108,4 +108,7 @@ DEPENDS intrinsics_gen + + LINK_LIBS + PRIVATE LLVMMLPolicies ) diff --git a/llvm/lib/Analysis/LLVMBuild.txt b/llvm/lib/Analysis/LLVMBuild.txt --- a/llvm/lib/Analysis/LLVMBuild.txt +++ b/llvm/lib/Analysis/LLVMBuild.txt @@ -14,9 +14,6 @@ ; ;===------------------------------------------------------------------------===; -[common] -subdirectories = ML - [component_0] type = Library name = Analysis diff --git a/llvm/lib/Analysis/ML/CMakeLists.txt b/llvm/lib/Analysis/ML/CMakeLists.txt --- a/llvm/lib/Analysis/ML/CMakeLists.txt +++ b/llvm/lib/Analysis/ML/CMakeLists.txt @@ -1,4 +1,6 @@ -add_llvm_component_library(LLVMMLPolicies +set(BUILD_SHARED_LIBS OFF) + +add_implementation_detail(LLVMMLPolicies PUBLIC InlineFeaturesAnalysis.cpp DEPENDS diff --git a/llvm/lib/Analysis/ML/LLVMBuild.txt b/llvm/lib/Analysis/ML/LLVMBuild.txt deleted file mode 100644 --- a/llvm/lib/Analysis/ML/LLVMBuild.txt +++ /dev/null @@ -1,21 +0,0 @@ -;===- ./lib/Analysis/ML/LLVMBuild.txt --------------------------*- Conf -*--===; -; -; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -; See https://llvm.org/LICENSE.txt for license information. -; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -; -;===------------------------------------------------------------------------===; -; -; This is an LLVMBuild description file for the components in this subdirectory. -; -; For more information on the LLVMBuild system, please see: -; -; http://llvm.org/docs/LLVMBuild.html -; -;===------------------------------------------------------------------------===; - -[component_0] -type = Library -name = MLPolicies -parent = Analysis -required_libraries = Core Support diff --git a/llvm/lib/Passes/LLVMBuild.txt b/llvm/lib/Passes/LLVMBuild.txt --- a/llvm/lib/Passes/LLVMBuild.txt +++ b/llvm/lib/Passes/LLVMBuild.txt @@ -18,4 +18,4 @@ type = Library name = Passes parent = Libraries -required_libraries = AggressiveInstCombine Analysis MLPolicies CodeGen Core Coroutines IPO InstCombine Scalar Support Target TransformUtils Vectorize Instrumentation +required_libraries = AggressiveInstCombine Analysis CodeGen Core Coroutines IPO InstCombine Scalar Support Target TransformUtils Vectorize Instrumentation