[llvm] r311036 - [CMake][runtimes] Support for building target variants
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 12:13:45 PDT 2017
Author: phosek
Date: Wed Aug 16 12:13:45 2017
New Revision: 311036
URL: http://llvm.org/viewvc/llvm-project?rev=311036&view=rev
Log:
[CMake][runtimes] Support for building target variants
This can be used to build non-sanitized and sanitized versions of
runtimes, where sanitized versions use the just built sanitizer
which in turn may use the non-sanitized version.
Differential Revision: https://reviews.llvm.org/D36348
Modified:
llvm/trunk/runtimes/CMakeLists.txt
Modified: llvm/trunk/runtimes/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/runtimes/CMakeLists.txt?rev=311036&r1=311035&r2=311036&view=diff
==============================================================================
--- llvm/trunk/runtimes/CMakeLists.txt (original)
+++ llvm/trunk/runtimes/CMakeLists.txt Wed Aug 16 12:13:45 2017
@@ -45,7 +45,9 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_
endforeach()
if(compiler_rt_path)
list(REMOVE_ITEM runtimes ${compiler_rt_path})
- list(INSERT runtimes 0 ${compiler_rt_path})
+ if(NOT LLVM_BUILD_COMPILER_RT)
+ list(INSERT runtimes 0 ${compiler_rt_path})
+ endif()
endif()
# LLVMConfig.cmake contains a bunch of CMake variables from the LLVM build.
@@ -87,6 +89,10 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_
set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_LIBRARIES ${SAFE_CMAKE_REQUIRED_LIBRARIES})
+ if(NOT LLVM_RUNTIMES_PREFIX)
+ set(LLVM_RUNTIMES_PREFIX "${LLVM_RUNTIMES_TARGET}/")
+ endif()
+
foreach(entry ${runtimes})
get_filename_component(projName ${entry} NAME)
@@ -98,7 +104,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_
if(LLVM_RUNTIMES_TARGET)
if(NOT "${entry}" MATCHES "compiler-rt")
- set(${canon_name}_INSTALL_PREFIX "lib/${LLVM_RUNTIMES_TARGET}/" CACHE STRING "" FORCE)
+ set(${canon_name}_INSTALL_PREFIX "lib/${LLVM_RUNTIMES_PREFIX}/" CACHE STRING "" FORCE)
endif()
endif()
@@ -118,9 +124,10 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_
if(LLVM_RUNTIMES_TARGET)
if(NOT "${entry}" MATCHES "compiler-rt")
- set(LLVM_BINARY_DIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_TARGET}")
- set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_TARGET}/lib")
- set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR}/${LLVM_RUNTIMES_TARGET}")
+ set(LLVM_BINARY_DIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_PREFIX}")
+ set(LLVM_LIBDIR_SUFFIX "${LLVM_RUNTIMES_LIBDIR_SUFFIX}")
+ set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_PREFIX}lib${LLVM_RUNTIMES_LIBDIR_SUFFIX}")
+ set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR}/${LLVM_RUNTIMES_PREFIX}")
endif()
endif()
@@ -282,52 +289,60 @@ else() # if this is included from LLVM's
# runtime_register_target(target)
# Utility function to register external runtime target.
- function(runtime_register_target target)
- if(target STREQUAL LLVM_DEFAULT_TARGET_TRIPLE)
+ function(runtime_register_target name target)
+ if(name STREQUAL LLVM_DEFAULT_TARGET_TRIPLE)
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
else()
- include(${LLVM_BINARY_DIR}/runtimes/${target}/Components.cmake OPTIONAL)
- set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${target}/Components.cmake)
+ include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
+ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
+ endif()
+
+ set(${name}_deps ${deps})
+ if(NOT name STREQUAL target)
+ list(APPEND ${name}_deps runtimes-${target})
endif()
foreach(runtime_name ${runtime_names})
- list(APPEND ${target}_extra_targets
- ${runtime_name}-${target}
- install-${runtime_name}-${target})
+ list(APPEND ${name}_extra_targets
+ ${runtime_name}-${name}
+ install-${runtime_name}-${name})
if(LLVM_INCLUDE_TESTS)
- list(APPEND ${target}_test_targets check-${runtime_name}-${target})
+ list(APPEND ${name}_test_targets check-${runtime_name}-${name})
endif()
endforeach()
foreach(name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
- list(APPEND ${target}_extra_targets "${name}:${name}-${target}")
+ list(APPEND ${name}_extra_targets "${name}:${name}-${name}")
endforeach()
if(LLVM_INCLUDE_TESTS)
- list(APPEND ${target}_test_targets runtimes-test-depends-${target} check-runtimes-${target})
- foreach(name IN LISTS SUB_CHECK_TARGETS)
- list(APPEND ${target}_test_targets "${name}:${name}-${target}")
- list(APPEND test_targets ${name}-${target})
+ list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
+ foreach(target_name IN LISTS SUB_CHECK_TARGETS)
+ list(APPEND ${name}_test_targets "${target_name}:${target_name}-${name}")
+ list(APPEND test_targets ${target_name}-${name})
endforeach()
set(test_targets "${test_targets}" PARENT_SCOPE)
endif()
get_cmake_property(variableNames VARIABLES)
foreach(variableName ${variableNames})
- if(variableName MATCHES "^RUNTIMES_${target}")
+ if(variableName MATCHES "^RUNTIMES_${name}")
+ string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
+ list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
+ elseif(variableName MATCHES "^RUNTIMES_${target}")
string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
- list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
+ list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
endif()
endforeach()
if(NOT target STREQUAL LLVM_DEFAULT_TARGET_TRIPLE)
- list(APPEND ${target}_extra_args "-DLLVM_RUNTIMES_TARGET=${target}")
+ list(APPEND ${name}_extra_args "-DLLVM_RUNTIMES_TARGET=${name}")
endif()
- llvm_ExternalProject_Add(runtimes-${target}
+ llvm_ExternalProject_Add(runtimes-${name}
${CMAKE_CURRENT_SOURCE_DIR}
- DEPENDS ${deps}
+ DEPENDS ${${name}_deps}
# Builtins were built separately above
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
@@ -339,11 +354,11 @@ else() # if this is included from LLVM's
-DCMAKE_CXX_COMPILER_WORKS=ON
-DCMAKE_ASM_COMPILER_WORKS=ON
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
- ${${target}_extra_args}
+ ${${name}_extra_args}
TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib
PASSTHROUGH_PREFIXES ${prefixes}
- EXTRA_TARGETS ${${target}_extra_targets}
- ${${target}_test_targets}
+ EXTRA_TARGETS ${${name}_extra_targets}
+ ${${name}_test_targets}
USE_TOOLCHAIN
${EXTRA_ARGS})
endfunction()
@@ -394,19 +409,27 @@ else() # if this is included from LLVM's
set(test_targets "")
endif()
- foreach(target ${LLVM_RUNTIME_TARGETS})
- if(target STREQUAL "default")
- set(target ${LLVM_DEFAULT_TARGET_TRIPLE})
+ foreach(name ${LLVM_RUNTIME_TARGETS})
+ if(name STREQUAL "default")
+ set(name ${LLVM_DEFAULT_TARGET_TRIPLE})
+ endif()
+
+ set(target ${name})
+ string(REPLACE ":" ";" target_list ${target})
+ list(GET target_list 0 name)
+ list(LENGTH target_list target_list_len)
+ if(${target_list_len} GREATER 1)
+ list(GET target_list 1 target)
endif()
- runtime_register_target(${target})
+ runtime_register_target(${name} ${target})
- add_dependencies(runtimes runtimes-${target})
- add_dependencies(runtimes-configure runtimes-${target}-configure)
- add_dependencies(install-runtimes install-runtimes-${target})
+ add_dependencies(runtimes runtimes-${name})
+ add_dependencies(runtimes-configure runtimes-${name}-configure)
+ add_dependencies(install-runtimes install-runtimes-${name})
if(LLVM_INCLUDE_TESTS)
- add_dependencies(check-runtimes check-runtimes-${target})
- add_dependencies(runtimes-test-depends runtimes-test-depends-${target})
+ add_dependencies(check-runtimes check-runtimes-${name})
+ add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
endif()
endforeach()
endif()
More information about the llvm-commits
mailing list