Skip to content

Commit ad00bd6

Browse files
committed
[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 llvm-svn: 311036
1 parent a54d379 commit ad00bd6

File tree

1 file changed

+58
-35
lines changed

1 file changed

+58
-35
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
4545
endforeach()
4646
if(compiler_rt_path)
4747
list(REMOVE_ITEM runtimes ${compiler_rt_path})
48-
list(INSERT runtimes 0 ${compiler_rt_path})
48+
if(NOT LLVM_BUILD_COMPILER_RT)
49+
list(INSERT runtimes 0 ${compiler_rt_path})
50+
endif()
4951
endif()
5052

5153
# LLVMConfig.cmake contains a bunch of CMake variables from the LLVM build.
@@ -87,6 +89,10 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
8789
set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS})
8890
set(CMAKE_REQUIRED_LIBRARIES ${SAFE_CMAKE_REQUIRED_LIBRARIES})
8991

92+
if(NOT LLVM_RUNTIMES_PREFIX)
93+
set(LLVM_RUNTIMES_PREFIX "${LLVM_RUNTIMES_TARGET}/")
94+
endif()
95+
9096
foreach(entry ${runtimes})
9197
get_filename_component(projName ${entry} NAME)
9298

@@ -98,7 +104,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
98104

99105
if(LLVM_RUNTIMES_TARGET)
100106
if(NOT "${entry}" MATCHES "compiler-rt")
101-
set(${canon_name}_INSTALL_PREFIX "lib/${LLVM_RUNTIMES_TARGET}/" CACHE STRING "" FORCE)
107+
set(${canon_name}_INSTALL_PREFIX "lib/${LLVM_RUNTIMES_PREFIX}/" CACHE STRING "" FORCE)
102108
endif()
103109
endif()
104110

@@ -118,9 +124,10 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
118124

119125
if(LLVM_RUNTIMES_TARGET)
120126
if(NOT "${entry}" MATCHES "compiler-rt")
121-
set(LLVM_BINARY_DIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_TARGET}")
122-
set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_TARGET}/lib")
123-
set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR}/${LLVM_RUNTIMES_TARGET}")
127+
set(LLVM_BINARY_DIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_PREFIX}")
128+
set(LLVM_LIBDIR_SUFFIX "${LLVM_RUNTIMES_LIBDIR_SUFFIX}")
129+
set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_PREFIX}lib${LLVM_RUNTIMES_LIBDIR_SUFFIX}")
130+
set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR}/${LLVM_RUNTIMES_PREFIX}")
124131
endif()
125132
endif()
126133

@@ -282,52 +289,60 @@ else() # if this is included from LLVM's CMake
282289

283290
# runtime_register_target(target)
284291
# Utility function to register external runtime target.
285-
function(runtime_register_target target)
286-
if(target STREQUAL LLVM_DEFAULT_TARGET_TRIPLE)
292+
function(runtime_register_target name target)
293+
if(name STREQUAL LLVM_DEFAULT_TARGET_TRIPLE)
287294
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
288295
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
289296
else()
290-
include(${LLVM_BINARY_DIR}/runtimes/${target}/Components.cmake OPTIONAL)
291-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${target}/Components.cmake)
297+
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
298+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
299+
endif()
300+
301+
set(${name}_deps ${deps})
302+
if(NOT name STREQUAL target)
303+
list(APPEND ${name}_deps runtimes-${target})
292304
endif()
293305

294306
foreach(runtime_name ${runtime_names})
295-
list(APPEND ${target}_extra_targets
296-
${runtime_name}-${target}
297-
install-${runtime_name}-${target})
307+
list(APPEND ${name}_extra_targets
308+
${runtime_name}-${name}
309+
install-${runtime_name}-${name})
298310
if(LLVM_INCLUDE_TESTS)
299-
list(APPEND ${target}_test_targets check-${runtime_name}-${target})
311+
list(APPEND ${name}_test_targets check-${runtime_name}-${name})
300312
endif()
301313
endforeach()
302314

303315
foreach(name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
304-
list(APPEND ${target}_extra_targets "${name}:${name}-${target}")
316+
list(APPEND ${name}_extra_targets "${name}:${name}-${name}")
305317
endforeach()
306318

307319
if(LLVM_INCLUDE_TESTS)
308-
list(APPEND ${target}_test_targets runtimes-test-depends-${target} check-runtimes-${target})
309-
foreach(name IN LISTS SUB_CHECK_TARGETS)
310-
list(APPEND ${target}_test_targets "${name}:${name}-${target}")
311-
list(APPEND test_targets ${name}-${target})
320+
list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name})
321+
foreach(target_name IN LISTS SUB_CHECK_TARGETS)
322+
list(APPEND ${name}_test_targets "${target_name}:${target_name}-${name}")
323+
list(APPEND test_targets ${target_name}-${name})
312324
endforeach()
313325
set(test_targets "${test_targets}" PARENT_SCOPE)
314326
endif()
315327

316328
get_cmake_property(variableNames VARIABLES)
317329
foreach(variableName ${variableNames})
318-
if(variableName MATCHES "^RUNTIMES_${target}")
330+
if(variableName MATCHES "^RUNTIMES_${name}")
331+
string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
332+
list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
333+
elseif(variableName MATCHES "^RUNTIMES_${target}")
319334
string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
320-
list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}")
335+
list(APPEND ${name}_extra_args "-D${new_name}=${${variableName}}")
321336
endif()
322337
endforeach()
323338

324339
if(NOT target STREQUAL LLVM_DEFAULT_TARGET_TRIPLE)
325-
list(APPEND ${target}_extra_args "-DLLVM_RUNTIMES_TARGET=${target}")
340+
list(APPEND ${name}_extra_args "-DLLVM_RUNTIMES_TARGET=${name}")
326341
endif()
327342

328-
llvm_ExternalProject_Add(runtimes-${target}
343+
llvm_ExternalProject_Add(runtimes-${name}
329344
${CMAKE_CURRENT_SOURCE_DIR}
330-
DEPENDS ${deps}
345+
DEPENDS ${${name}_deps}
331346
# Builtins were built separately above
332347
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
333348
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
@@ -339,11 +354,11 @@ else() # if this is included from LLVM's CMake
339354
-DCMAKE_CXX_COMPILER_WORKS=ON
340355
-DCMAKE_ASM_COMPILER_WORKS=ON
341356
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
342-
${${target}_extra_args}
357+
${${name}_extra_args}
343358
TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib
344359
PASSTHROUGH_PREFIXES ${prefixes}
345-
EXTRA_TARGETS ${${target}_extra_targets}
346-
${${target}_test_targets}
360+
EXTRA_TARGETS ${${name}_extra_targets}
361+
${${name}_test_targets}
347362
USE_TOOLCHAIN
348363
${EXTRA_ARGS})
349364
endfunction()
@@ -394,19 +409,27 @@ else() # if this is included from LLVM's CMake
394409
set(test_targets "")
395410
endif()
396411

397-
foreach(target ${LLVM_RUNTIME_TARGETS})
398-
if(target STREQUAL "default")
399-
set(target ${LLVM_DEFAULT_TARGET_TRIPLE})
412+
foreach(name ${LLVM_RUNTIME_TARGETS})
413+
if(name STREQUAL "default")
414+
set(name ${LLVM_DEFAULT_TARGET_TRIPLE})
415+
endif()
416+
417+
set(target ${name})
418+
string(REPLACE ":" ";" target_list ${target})
419+
list(GET target_list 0 name)
420+
list(LENGTH target_list target_list_len)
421+
if(${target_list_len} GREATER 1)
422+
list(GET target_list 1 target)
400423
endif()
401424

402-
runtime_register_target(${target})
425+
runtime_register_target(${name} ${target})
403426

404-
add_dependencies(runtimes runtimes-${target})
405-
add_dependencies(runtimes-configure runtimes-${target}-configure)
406-
add_dependencies(install-runtimes install-runtimes-${target})
427+
add_dependencies(runtimes runtimes-${name})
428+
add_dependencies(runtimes-configure runtimes-${name}-configure)
429+
add_dependencies(install-runtimes install-runtimes-${name})
407430
if(LLVM_INCLUDE_TESTS)
408-
add_dependencies(check-runtimes check-runtimes-${target})
409-
add_dependencies(runtimes-test-depends runtimes-test-depends-${target})
431+
add_dependencies(check-runtimes check-runtimes-${name})
432+
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
410433
endif()
411434
endforeach()
412435
endif()

0 commit comments

Comments
 (0)