llvm.org GIT mirror llvm / 2ec309f
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247632 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 4 years ago
4 changed file(s) with 78 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
642642 if(NOT LLVM_TOOLCHAIN_TOOLS)
643643 set (LLVM_TOOLCHAIN_TOOLS
644644 llvm-ar
645 llvm-ranlib
646 llvm-lib
645647 llvm-objdump
646648 )
647649 endif()
10191021 endforeach()
10201022 endif()
10211023 endfunction()
1024
1025 function(add_llvm_tool_symlink name target)
1026 if(UNIX)
1027 set(LLVM_LINK_OR_COPY create_symlink)
1028 set(target_binary "${target}${CMAKE_EXECUTABLE_SUFFIX}")
1029 else()
1030 set(LLVM_LINK_OR_COPY copy)
1031 set(target_binary "${LLVM_RUNTIME_OUTPUT_INTDIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}")
1032 endif()
1033
1034 set(output_path "${LLVM_RUNTIME_OUTPUT_INTDIR}/${name}${CMAKE_EXECUTABLE_SUFFIX}")
1035
1036 add_custom_command(OUTPUT ${output_path}
1037 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${target_binary}" "${output_path}"
1038 DEPENDS ${target})
1039
1040 add_custom_target(${name} ALL DEPENDS ${output_path})
1041 set_target_properties(${name} PROPERTIES FOLDER Tools)
1042
1043 # MAke sure the parent tool is a toolchain tool, otherwise exclude this tool
1044 list(FIND LLVM_TOOLCHAIN_TOOLS ${target} LLVM_IS_${target}_TOOLCHAIN_TOOL)
1045 if (NOT LLVM_IS_${target}_TOOLCHAIN_TOOL GREATER -1)
1046 set(LLVM_IS_${name}_TOOLCHAIN_TOOL ${LLVM_IS_${target}_TOOLCHAIN_TOOL})
1047 else()
1048 list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL)
1049 endif()
1050
1051 # LLVM_IS_${name}_TOOLCHAIN_TOOL will only be greater than -1 if both this
1052 # tool and its parent tool are in LLVM_TOOLCHAIN_TOOLS
1053 if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
1054 if( LLVM_BUILD_TOOLS )
1055 install(SCRIPT ${CMAKE_SOURCE_DIR}/cmake/modules/install_symlink.cmake
1056 CODE "install_symlink(${name} ${target})"
1057 COMPONENT ${name})
1058
1059 if (NOT CMAKE_CONFIGURATION_TYPES)
1060 add_custom_target(install-${name}
1061 DEPENDS ${name}
1062 COMMAND "${CMAKE_COMMAND}"
1063 -DCMAKE_INSTALL_COMPONENT=${name}
1064 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
1065 endif()
1066 endif()
1067 endif()
1068 endfunction()
1069
0 # We need to execute this script at installation time because the
1 # DESTDIR environment variable may be unset at configuration time.
2 # See PR8397.
3
4 function(install_symlink name target)
5 if(UNIX)
6 set(LINK_OR_COPY create_symlink)
7 set(DESTDIR $ENV{DESTDIR})
8 else()
9 set(LINK_OR_COPY copy)
10 endif()
11
12 # CMAKE_EXECUTABLE_SUFFIX is undefined on cmake scripts. See PR9286.
13 if( WIN32 )
14 set(EXECUTABLE_SUFFIX ".exe")
15 else()
16 set(EXECUTABLE_SUFFIX "")
17 endif()
18
19 set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/")
20
21 message("Creating ${name}")
22
23 execute_process(
24 COMMAND "${CMAKE_COMMAND}" -E ${LINK_OR_COPY} "${target}${EXECUTABLE_SUFFIX}" "${name}${EXECUTABLE_SUFFIX}"
25 WORKING_DIRECTORY "${bindir}")
26
27 endfunction()
99 llvm-ar.cpp
1010 )
1111
12 if(UNIX)
13 set(LLVM_LINK_OR_COPY create_symlink)
14 set(llvm_ar_binary "llvm-ar${CMAKE_EXECUTABLE_SUFFIX}")
15 else()
16 set(LLVM_LINK_OR_COPY copy)
17 set(llvm_ar_binary "${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar${CMAKE_EXECUTABLE_SUFFIX}")
18 endif()
19
20 set(llvm_ranlib "${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib${CMAKE_EXECUTABLE_SUFFIX}")
21
22 add_custom_command(OUTPUT ${llvm_ranlib}
23 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${llvm_ar_binary}" "${llvm_ranlib}"
24 DEPENDS llvm-ar)
25
26 add_custom_target(llvm-ranlib ALL DEPENDS ${llvm_ranlib})
27 set_target_properties(llvm-ranlib PROPERTIES FOLDER Tools)
28
29 set(llvm_lib "${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-lib${CMAKE_EXECUTABLE_SUFFIX}")
30
31 add_custom_command(OUTPUT ${llvm_lib}
32 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${llvm_ar_binary}" "${llvm_lib}"
33 DEPENDS llvm-ar)
34
35 add_custom_target(llvm-lib ALL DEPENDS ${llvm_lib})
36 set_target_properties(llvm-lib PROPERTIES FOLDER Tools)
37
38 install(SCRIPT install_symlink.cmake -DCMAKE_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\")
12 add_llvm_tool_symlink(llvm-ranlib llvm-ar)
13 add_llvm_tool_symlink(llvm-lib llvm-ar)
+0
-31
tools/llvm-ar/install_symlink.cmake less more
None # We need to execute this script at installation time because the
1 # DESTDIR environment variable may be unset at configuration time.
2 # See PR8397.
3
4 if(UNIX)
5 set(LINK_OR_COPY create_symlink)
6 set(DESTDIR $ENV{DESTDIR})
7 else()
8 set(LINK_OR_COPY copy)
9 endif()
10
11 # CMAKE_EXECUTABLE_SUFFIX is undefined on cmake scripts. See PR9286.
12 if( WIN32 )
13 set(EXECUTABLE_SUFFIX ".exe")
14 else()
15 set(EXECUTABLE_SUFFIX "")
16 endif()
17
18 set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/")
19
20 message("Creating llvm-ranlib")
21
22 execute_process(
23 COMMAND "${CMAKE_COMMAND}" -E ${LINK_OR_COPY} "llvm-ar${EXECUTABLE_SUFFIX}" "llvm-ranlib${EXECUTABLE_SUFFIX}"
24 WORKING_DIRECTORY "${bindir}")
25
26 message("Creating llvm-lib")
27
28 execute_process(
29 COMMAND "${CMAKE_COMMAND}" -E ${LINK_OR_COPY} "llvm-ar${EXECUTABLE_SUFFIX}" "llvm-lib${EXECUTABLE_SUFFIX}"
30 WORKING_DIRECTORY "${bindir}")