Index: clang/cmake/modules/AddClang.cmake =================================================================== --- clang/cmake/modules/AddClang.cmake +++ clang/cmake/modules/AddClang.cmake @@ -149,43 +149,58 @@ 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) + setup_llvm_executable(${name} ${ARGN}) + 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(${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() Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -863,7 +863,7 @@ endif() endmacro(add_llvm_library name) -macro(add_llvm_executable name) +macro(setup_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" @@ -911,7 +911,10 @@ target_link_libraries(${obj_name} ${LLVM_PTHREAD_LIB}) llvm_config(${obj_name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} ) endif() +endmacro() +macro(add_llvm_executable name) + setup_llvm_executable(${name} ${ARGN}) add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) if(XCODE) @@ -1276,30 +1279,36 @@ 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) + setup_llvm_executable(${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 +2009,11 @@ endfunction() function(llvm_install_symlink name dest) + get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS) + if(${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 +2034,9 @@ 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})" Index: llvm/tools/CMakeLists.txt =================================================================== --- llvm/tools/CMakeLists.txt +++ llvm/tools/CMakeLists.txt @@ -21,6 +21,10 @@ 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 @@ # 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 so it must be placed here. + generate_driver_tool_targets() endif() Index: llvm/tools/llvm-driver/CMakeLists.txt =================================================================== --- llvm/tools/llvm-driver/CMakeLists.txt +++ llvm/tools/llvm-driver/CMakeLists.txt @@ -15,11 +15,8 @@ "${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 @@ # 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()