[llvm] r247632 - [CMake] Refactor and cleanup generating and installing symlinks to tools.
Chris Bieneman via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 14 16:09:06 PDT 2015
Author: cbieneman
Date: Mon Sep 14 18:09:06 2015
New Revision: 247632
URL: http://llvm.org/viewvc/llvm-project?rev=247632&view=rev
Log:
[CMake] Refactor and cleanup generating and installing symlinks to tools.
Summary: This change generalizes symlink generation and makes symlinks to tools obey LLVM_TOOLCHAIN_TOOLS. It makes it so that if you exclude llvm-ar from LLVM_TOOLCHAIN_TOOLS you don't end up with broken symlinks to llvm-lib and llvm-ranlib in your install.
Reviewers: bogner, chapuni, rafael
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D12864
Added:
llvm/trunk/cmake/modules/install_symlink.cmake
Removed:
llvm/trunk/tools/llvm-ar/install_symlink.cmake
Modified:
llvm/trunk/cmake/modules/AddLLVM.cmake
llvm/trunk/tools/llvm-ar/CMakeLists.txt
Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=247632&r1=247631&r2=247632&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Mon Sep 14 18:09:06 2015
@@ -643,6 +643,8 @@ endfunction()
if(NOT LLVM_TOOLCHAIN_TOOLS)
set (LLVM_TOOLCHAIN_TOOLS
llvm-ar
+ llvm-ranlib
+ llvm-lib
llvm-objdump
)
endif()
@@ -1020,3 +1022,49 @@ function(add_lit_testsuites project dire
endforeach()
endif()
endfunction()
+
+function(add_llvm_tool_symlink name target)
+ if(UNIX)
+ set(LLVM_LINK_OR_COPY create_symlink)
+ set(target_binary "${target}${CMAKE_EXECUTABLE_SUFFIX}")
+ else()
+ set(LLVM_LINK_OR_COPY copy)
+ set(target_binary "${LLVM_RUNTIME_OUTPUT_INTDIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}")
+ endif()
+
+ set(output_path "${LLVM_RUNTIME_OUTPUT_INTDIR}/${name}${CMAKE_EXECUTABLE_SUFFIX}")
+
+ add_custom_command(OUTPUT ${output_path}
+ COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${target_binary}" "${output_path}"
+ DEPENDS ${target})
+
+ add_custom_target(${name} ALL DEPENDS ${output_path})
+ set_target_properties(${name} PROPERTIES FOLDER Tools)
+
+ # MAke sure the parent tool is a toolchain tool, otherwise exclude this tool
+ list(FIND LLVM_TOOLCHAIN_TOOLS ${target} LLVM_IS_${target}_TOOLCHAIN_TOOL)
+ if (NOT LLVM_IS_${target}_TOOLCHAIN_TOOL GREATER -1)
+ set(LLVM_IS_${name}_TOOLCHAIN_TOOL ${LLVM_IS_${target}_TOOLCHAIN_TOOL})
+ else()
+ list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL)
+ endif()
+
+ # LLVM_IS_${name}_TOOLCHAIN_TOOL will only be greater than -1 if both this
+ # tool and its parent tool are in LLVM_TOOLCHAIN_TOOLS
+ if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+ if( LLVM_BUILD_TOOLS )
+ install(SCRIPT ${CMAKE_SOURCE_DIR}/cmake/modules/install_symlink.cmake
+ CODE "install_symlink(${name} ${target})"
+ COMPONENT ${name})
+
+ if (NOT CMAKE_CONFIGURATION_TYPES)
+ add_custom_target(install-${name}
+ DEPENDS ${name}
+ COMMAND "${CMAKE_COMMAND}"
+ -DCMAKE_INSTALL_COMPONENT=${name}
+ -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+ endif()
+ endif()
+ endif()
+endfunction()
+
Added: llvm/trunk/cmake/modules/install_symlink.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/install_symlink.cmake?rev=247632&view=auto
==============================================================================
--- llvm/trunk/cmake/modules/install_symlink.cmake (added)
+++ llvm/trunk/cmake/modules/install_symlink.cmake Mon Sep 14 18:09:06 2015
@@ -0,0 +1,28 @@
+# We need to execute this script at installation time because the
+# DESTDIR environment variable may be unset at configuration time.
+# See PR8397.
+
+function(install_symlink name target)
+ if(UNIX)
+ set(LINK_OR_COPY create_symlink)
+ set(DESTDIR $ENV{DESTDIR})
+ else()
+ set(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 "${DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/")
+
+ message("Creating ${name}")
+
+ execute_process(
+ COMMAND "${CMAKE_COMMAND}" -E ${LINK_OR_COPY} "${target}${EXECUTABLE_SUFFIX}" "${name}${EXECUTABLE_SUFFIX}"
+ WORKING_DIRECTORY "${bindir}")
+
+endfunction()
Modified: llvm/trunk/tools/llvm-ar/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/CMakeLists.txt?rev=247632&r1=247631&r2=247632&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-ar/CMakeLists.txt Mon Sep 14 18:09:06 2015
@@ -10,30 +10,5 @@ add_llvm_tool(llvm-ar
llvm-ar.cpp
)
-if(UNIX)
- set(LLVM_LINK_OR_COPY create_symlink)
- set(llvm_ar_binary "llvm-ar${CMAKE_EXECUTABLE_SUFFIX}")
-else()
- set(LLVM_LINK_OR_COPY copy)
- set(llvm_ar_binary "${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar${CMAKE_EXECUTABLE_SUFFIX}")
-endif()
-
-set(llvm_ranlib "${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib${CMAKE_EXECUTABLE_SUFFIX}")
-
-add_custom_command(OUTPUT ${llvm_ranlib}
- COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${llvm_ar_binary}" "${llvm_ranlib}"
- DEPENDS llvm-ar)
-
-add_custom_target(llvm-ranlib ALL DEPENDS ${llvm_ranlib})
-set_target_properties(llvm-ranlib PROPERTIES FOLDER Tools)
-
-set(llvm_lib "${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-lib${CMAKE_EXECUTABLE_SUFFIX}")
-
-add_custom_command(OUTPUT ${llvm_lib}
- COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${llvm_ar_binary}" "${llvm_lib}"
- DEPENDS llvm-ar)
-
-add_custom_target(llvm-lib ALL DEPENDS ${llvm_lib})
-set_target_properties(llvm-lib PROPERTIES FOLDER Tools)
-
-install(SCRIPT install_symlink.cmake -DCMAKE_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\")
+add_llvm_tool_symlink(llvm-ranlib llvm-ar)
+add_llvm_tool_symlink(llvm-lib llvm-ar)
Removed: llvm/trunk/tools/llvm-ar/install_symlink.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/install_symlink.cmake?rev=247631&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-ar/install_symlink.cmake (original)
+++ llvm/trunk/tools/llvm-ar/install_symlink.cmake (removed)
@@ -1,31 +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(LINK_OR_COPY create_symlink)
- set(DESTDIR $ENV{DESTDIR})
-else()
- set(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 "${DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/")
-
-message("Creating llvm-ranlib")
-
-execute_process(
- COMMAND "${CMAKE_COMMAND}" -E ${LINK_OR_COPY} "llvm-ar${EXECUTABLE_SUFFIX}" "llvm-ranlib${EXECUTABLE_SUFFIX}"
- WORKING_DIRECTORY "${bindir}")
-
-message("Creating llvm-lib")
-
-execute_process(
- COMMAND "${CMAKE_COMMAND}" -E ${LINK_OR_COPY} "llvm-ar${EXECUTABLE_SUFFIX}" "llvm-lib${EXECUTABLE_SUFFIX}"
- WORKING_DIRECTORY "${bindir}")
More information about the llvm-commits
mailing list