[CMake] Refactoring and cleaning up clang symlink generation.

Generation of clang symlinks now uses add_clang_symlink macro which uses add_llvm_symlink. Also the list of symlinks to generate is configurable via CLANG_LINKS_TO_CREATE.

This re-lands r248015, with fixes for clang symlinks to always be generated as part of the clang and install-clang targets.

llvm-svn: 248043
This commit is contained in:
Chris Bieneman 2015-09-18 21:15:54 +00:00
parent e7dba51330
commit cd53780cd4
3 changed files with 13 additions and 72 deletions

View File

@ -414,6 +414,12 @@ macro(add_clang_executable name)
set_clang_windows_version_resource_properties(${name})
endmacro(add_clang_executable)
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)
endmacro()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(BEFORE

View File

@ -51,33 +51,6 @@ endif()
add_dependencies(clang clang-headers)
if(UNIX)
set(CLANGXX_LINK_OR_COPY create_symlink)
# Create a relative symlink
set(clang_binary "clang${CMAKE_EXECUTABLE_SUFFIX}")
else()
set(CLANGXX_LINK_OR_COPY copy)
set(clang_binary "${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}")
endif()
# Create the clang++ symlink in the build directory.
set(clang_pp "${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}")
add_custom_command(TARGET clang POST_BUILD
COMMAND ${CMAKE_COMMAND} -E ${CLANGXX_LINK_OR_COPY} "${clang_binary}" "${clang_pp}"
WORKING_DIRECTORY "${LLVM_RUNTIME_OUTPUT_INTDIR}")
set_property(DIRECTORY APPEND
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clang_pp})
# Create the clang-cl symlink in the build directory.
set(clang_cl "${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}")
add_custom_command(TARGET clang POST_BUILD
COMMAND ${CMAKE_COMMAND} -E ${CLANGXX_LINK_OR_COPY} "${clang_binary}" "${clang_cl}"
WORKING_DIRECTORY "${LLVM_RUNTIME_OUTPUT_INTDIR}")
set_property(DIRECTORY APPEND
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clang_cl})
install(TARGETS clang
RUNTIME DESTINATION bin
COMPONENT clang)
@ -87,8 +60,13 @@ add_custom_target(install-clang
-DCMAKE_INSTALL_COMPONENT=clang
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
# Create the clang++ and clang-cl symlinks at installation time.
install(SCRIPT clang_symlink.cmake -DCMAKE_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\")
if(NOT CLANG_LINKS_TO_CREATE)
set(CLANG_LINKS_TO_CREATE clang++ clang-cl)
endif()
foreach(link ${CLANG_LINKS_TO_CREATE})
add_clang_symlink(${link} clang)
endforeach()
# Configure plist creation for OS X.
set (TOOL_INFO_PLIST "Info.plist" CACHE STRING "Plist name")

View File

@ -1,43 +0,0 @@
# We need to execute this script at installation time because the
# DESTDIR environment variable may be unset at configuration time.
# See PR8397.
if(UNIX)
set(CLANGXX_LINK_OR_COPY create_symlink)
set(CLANGXX_DESTDIR $ENV{DESTDIR})
else()
set(CLANGXX_LINK_OR_COPY copy)
endif()
# CMAKE_EXECUTABLE_SUFFIX is undefined on cmake scripts. See PR9286.
if( WIN32 )
set(EXECUTABLE_SUFFIX ".exe")
else()
set(EXECUTABLE_SUFFIX "")
endif()
set(bindir "${CLANGXX_DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/")
set(clang "clang${EXECUTABLE_SUFFIX}")
set(clangxx "clang++${EXECUTABLE_SUFFIX}")
set(clang_cl "clang-cl${EXECUTABLE_SUFFIX}")
set(cl "cl${EXECUTABLE_SUFFIX}")
message("Creating clang++ executable based on ${clang}")
execute_process(
COMMAND "${CMAKE_COMMAND}" -E ${CLANGXX_LINK_OR_COPY} "${clang}" "${clangxx}"
WORKING_DIRECTORY "${bindir}")
message("Creating clang-cl executable based on ${clang}")
execute_process(
COMMAND "${CMAKE_COMMAND}" -E ${CLANGXX_LINK_OR_COPY} "${clang}" "${clang_cl}"
WORKING_DIRECTORY "${bindir}")
if (WIN32)
message("Creating cl executable based on ${clang}")
execute_process(
COMMAND "${CMAKE_COMMAND}" -E ${CLANGXX_LINK_OR_COPY} "${clang}" "../msbuild-bin/${cl}"
WORKING_DIRECTORY "${bindir}")
endif()