[llvm] 09d4dbc - [llvm-driver] Generate symlinks instead of executables for tools
Alex Brachet via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 19 18:43:49 PDT 2022
Author: Alex Brachet
Date: 2022-07-20T01:42:56Z
New Revision: 09d4dbc3829e91397f96d7d7f243440555adee87
URL: https://github.com/llvm/llvm-project/commit/09d4dbc3829e91397f96d7d7f243440555adee87
DIFF: https://github.com/llvm/llvm-project/commit/09d4dbc3829e91397f96d7d7f243440555adee87.diff
LOG: [llvm-driver] Generate symlinks instead of executables for tools
When LLVM_TOOL_LLVM_DRIVER_BUILD is On, create symlinks
to llvm instead of creating the executables. Currently
this only works for install and not
install-distribution, the work for the later will be
split up into a second patch.
Differential Revision: https://reviews.llvm.org/D127800
Added:
Modified:
clang/cmake/modules/AddClang.cmake
llvm/cmake/modules/AddLLVM.cmake
llvm/tools/CMakeLists.txt
llvm/tools/llvm-driver/CMakeLists.txt
Removed:
################################################################################
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index 299f8ce6e2fb4..0b3c64c32cfc5 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -149,43 +149,60 @@ macro(add_clang_executable name)
endmacro(add_clang_executable)
macro(add_clang_tool name)
+ cmake_parse_arguments(ARG "DEPENDS;GENERATE_DRIVER" "" "" ${ARGN})
if (NOT CLANG_BUILD_TOOLS)
set(EXCLUDE_FROM_ALL ON)
endif()
-
- add_clang_executable(${name} ${ARGN})
- add_dependencies(${name} clang-resource-headers)
-
- if (CLANG_BUILD_TOOLS)
- get_target_export_arg(${name} Clang export_to_clangtargets)
- install(TARGETS ${name}
- ${export_to_clangtargets}
- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
- COMPONENT ${name})
-
- if(NOT LLVM_ENABLE_IDE)
- add_llvm_install_targets(install-${name}
- DEPENDS ${name}
- COMPONENT ${name})
+ if(ARG_GENERATE_DRIVER AND LLVM_TOOL_LLVM_DRIVER_BUILD)
+ set(get_obj_args ${ARGN})
+ list(FILTER get_obj_args EXCLUDE REGEX "^SUPPORT_PLUGINS$")
+ generate_llvm_objects(${name} ${get_obj_args})
+ add_custom_target(${name} DEPENDS llvm-driver clang-resource-headers)
+ else()
+ add_clang_executable(${name} ${ARGN})
+ add_dependencies(${name} clang-resource-headers)
+
+ if (CLANG_BUILD_TOOLS)
+ get_target_export_arg(${name} Clang export_to_clangtargets)
+ install(TARGETS ${name}
+ ${export_to_clangtargets}
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+ COMPONENT ${name})
+
+ if(NOT LLVM_ENABLE_IDE)
+ add_llvm_install_targets(install-${name}
+ DEPENDS ${name}
+ COMPONENT ${name})
+ endif()
+ set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
endif()
- set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
endif()
endmacro()
macro(add_clang_symlink name dest)
- add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
- # Always generate install targets
- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
+ get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
+ if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
+ set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_SYMLINKS ${name})
+ else()
+ add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
+ # Always generate install targets
+ llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
+ endif()
endmacro()
function(clang_target_link_libraries target type)
+ if (TARGET obj.${target})
+ target_link_libraries(obj.${target} ${ARGN})
+ endif()
+
+ get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
+ if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${target} IN_LIST LLVM_DRIVER_TOOLS)
+ set(target llvm-driver)
+ endif()
+
if (CLANG_LINK_CLANG_DYLIB)
target_link_libraries(${target} ${type} clang-cpp)
else()
target_link_libraries(${target} ${type} ${ARGN})
endif()
- if (TARGET obj.${target})
- target_link_libraries(obj.${target} ${ARGN})
- endif()
-
endfunction()
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 8e1385e90b82d..6a8e13032bdea 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -863,12 +863,8 @@ macro(add_llvm_library name)
endif()
endmacro(add_llvm_library name)
-macro(add_llvm_executable name)
- cmake_parse_arguments(ARG
- "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS;GENERATE_DRIVER"
- "ENTITLEMENTS;BUNDLE_PATH"
- "DEPENDS"
- ${ARGN})
+macro(generate_llvm_objects name)
+ cmake_parse_arguments(ARG "GENERATE_DRIVER" "" "DEPENDS" ${ARGN})
llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} )
@@ -911,7 +907,15 @@ macro(add_llvm_executable name)
target_link_libraries(${obj_name} ${LLVM_PTHREAD_LIB})
llvm_config(${obj_name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )
endif()
+endmacro()
+macro(add_llvm_executable name)
+ cmake_parse_arguments(ARG
+ "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS"
+ "ENTITLEMENTS;BUNDLE_PATH"
+ ""
+ ${ARGN})
+ generate_llvm_objects(${name} ${ARG_UNPARSED_ARGUMENTS})
add_windows_version_resource_file(ALL_FILES ${ALL_FILES})
if(XCODE)
@@ -1276,30 +1280,36 @@ if(NOT LLVM_TOOLCHAIN_TOOLS)
endif()
macro(add_llvm_tool name)
+ cmake_parse_arguments(ARG "DEPENDS;GENERATE_DRIVER" "" "" ${ARGN})
if( NOT LLVM_BUILD_TOOLS )
set(EXCLUDE_FROM_ALL ON)
endif()
- add_llvm_executable(${name} ${ARGN})
-
- if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
- if( LLVM_BUILD_TOOLS )
- get_target_export_arg(${name} LLVM export_to_llvmexports)
- install(TARGETS ${name}
- ${export_to_llvmexports}
- RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
- COMPONENT ${name})
-
- if (NOT LLVM_ENABLE_IDE)
- add_llvm_install_targets(install-${name}
- DEPENDS ${name}
- COMPONENT ${name})
+ if(ARG_GENERATE_DRIVER AND LLVM_TOOL_LLVM_DRIVER_BUILD)
+ generate_llvm_objects(${name} ${ARGN})
+ add_custom_target(${name} DEPENDS llvm-driver)
+ else()
+ add_llvm_executable(${name} ${ARGN})
+
+ if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+ if( LLVM_BUILD_TOOLS )
+ get_target_export_arg(${name} LLVM export_to_llvmexports)
+ install(TARGETS ${name}
+ ${export_to_llvmexports}
+ RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
+ COMPONENT ${name})
+
+ if (NOT LLVM_ENABLE_IDE)
+ add_llvm_install_targets(install-${name}
+ DEPENDS ${name}
+ COMPONENT ${name})
+ endif()
endif()
endif()
+ if( LLVM_BUILD_TOOLS )
+ set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
+ endif()
+ set_target_properties(${name} PROPERTIES FOLDER "Tools")
endif()
- if( LLVM_BUILD_TOOLS )
- set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
- endif()
- set_target_properties(${name} PROPERTIES FOLDER "Tools")
endmacro(add_llvm_tool name)
@@ -2000,6 +2010,11 @@ function(llvm_install_library_symlink name dest type)
endfunction()
function(llvm_install_symlink name dest)
+ get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
+ if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${dest} IN_LIST LLVM_DRIVER_TOOLS)
+ set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_SYMLINKS ${name})
+ return()
+ endif()
cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
foreach(path ${CMAKE_MODULE_PATH})
if(EXISTS ${path}/LLVMInstallSymlink.cmake)
@@ -2020,6 +2035,9 @@ function(llvm_install_symlink name dest)
set(full_name ${name}${CMAKE_EXECUTABLE_SUFFIX})
set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
+ if (${dest} STREQUAL "llvm-driver")
+ set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
+ endif()
install(SCRIPT ${INSTALL_SYMLINK}
CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})"
diff --git a/llvm/tools/CMakeLists.txt b/llvm/tools/CMakeLists.txt
index ef5edb195317b..c6116ac81d12b 100644
--- a/llvm/tools/CMakeLists.txt
+++ b/llvm/tools/CMakeLists.txt
@@ -21,6 +21,10 @@ if(CYGWIN OR NOT LLVM_ENABLE_PIC)
set(LLVM_TOOL_LTO_BUILD Off)
endif()
+if (LLVM_TOOL_LLVM_DRIVER_BUILD)
+ add_llvm_tool(llvm-driver)
+endif()
+
# Add LTO, llvm-ar, llvm-config, and llvm-profdata before clang, ExternalProject
# requires targets specified in DEPENDS to exist before the call to
# ExternalProject_Add.
@@ -58,4 +62,8 @@ if (LLVM_TOOL_LLVM_DRIVER_BUILD)
# This is explicitly added at the end _after_ all tool projects so that it can
# scrape up tools from other projects into itself.
add_subdirectory(llvm-driver)
+ # This must be here otherwise CMake complains in add_llvm_tool_symlink that
+ # it can't add_custom_command that happens after llvm-driver is built because
+ # llvm-driver was not created in that directory.
+ generate_driver_tool_targets()
endif()
diff --git a/llvm/tools/llvm-driver/CMakeLists.txt b/llvm/tools/llvm-driver/CMakeLists.txt
index 7cbeaf398eb4b..23a1d7e5442fd 100644
--- a/llvm/tools/llvm-driver/CMakeLists.txt
+++ b/llvm/tools/llvm-driver/CMakeLists.txt
@@ -15,11 +15,8 @@ file(WRITE
"${CMAKE_CURRENT_BINARY_DIR}/LLVMDriverTools.def"
"${def_decl}${LLVM_EXTRA_DRIVER_ENTRIES}#undef LLVM_DRIVER_TOOL\n")
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
-add_llvm_tool(llvm-driver
- llvm-driver.cpp
- )
+target_include_directories(llvm-driver PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_sources(llvm-driver PRIVATE llvm-driver.cpp)
set_target_properties(llvm-driver PROPERTIES OUTPUT_NAME llvm)
@@ -29,3 +26,13 @@ if(APPLE)
# dsymutil uses some CoreFoundation stuff on Darwin...
target_link_libraries(llvm-driver PRIVATE "-framework CoreFoundation")
endif(APPLE)
+
+macro(generate_driver_tool_targets)
+ get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
+ get_property(LLVM_DRIVER_TOOL_SYMLINKS GLOBAL PROPERTY LLVM_DRIVER_TOOL_SYMLINKS)
+ foreach(name IN LISTS LLVM_DRIVER_TOOLS LLVM_DRIVER_TOOL_SYMLINKS)
+ add_llvm_tool_symlink(${name} llvm-driver ALWAYS_GENERATE)
+ # Always generate install targets
+ llvm_install_symlink(${name} llvm-driver ALWAYS_GENERATE)
+ endforeach()
+endmacro()
More information about the llvm-commits
mailing list