Skip to content

Commit 06400a0

Browse files
committed
[runtimes] Generalize how we reorder projects
This way, we could use it for LLVM_ENABLE_PROJECTS too if desired. Differential Revision: https://reviews.llvm.org/D125121
1 parent d95513a commit 06400a0

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

cmake/Modules/SortSubset.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Sort a subset of a list according to the ordering in the full list.
2+
#
3+
# Given a list and a subset of that list, this function sorts the subset
4+
# according to the order in the full list, and returns that in the given
5+
# output variable.
6+
#
7+
# full_list:
8+
# The list containing the desired order of elements in the sub-list.
9+
#
10+
# sub_list:
11+
# A subset of the elements in `full_list`. Those elements will be sorted
12+
# according to the order in `full_list`.
13+
#
14+
# out_var:
15+
# A variable to store the resulting sorted sub-list in.
16+
function(sort_subset full_list sub_list out_var)
17+
set(result "${full_list}")
18+
foreach(project IN LISTS full_list)
19+
if (NOT project IN_LIST sub_list)
20+
list(REMOVE_ITEM result ${project})
21+
endif()
22+
endforeach()
23+
24+
set(${out_var} "${result}" PARENT_SCOPE)
25+
endfunction()

runtimes/CMakeLists.txt

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,27 @@
22
cmake_minimum_required(VERSION 3.13.4)
33
project(Runtimes C CXX ASM)
44

5-
set(LLVM_ALL_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi;libunwind;openmp")
5+
# Add path for custom and the LLVM build's modules to the CMake module path.
6+
set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
7+
list(INSERT CMAKE_MODULE_PATH 0
8+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
9+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
10+
"${LLVM_COMMON_CMAKE_UTILS}"
11+
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
12+
"${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake"
13+
"${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake/modules"
14+
)
15+
16+
# We order libraries to mirror roughly how they are layered, except that compiler-rt can depend
17+
# on libc++, so we put it after.
18+
set(LLVM_ALL_RUNTIMES "libc;libunwind;libcxxabi;libcxx;compiler-rt;openmp")
619
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
720
"Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")
821
if(LLVM_ENABLE_RUNTIMES STREQUAL "all" )
922
set(LLVM_ENABLE_RUNTIMES ${LLVM_ALL_RUNTIMES})
1023
endif()
11-
12-
# Some of the runtimes will conditionally use the compiler-rt sanitizers.
13-
# To make this work smoothly, we ensure that compiler-rt is added first in
14-
# the list of sub-projects. This allows other sub-projects to have checks
15-
# like `if(TARGET asan)` to enable building with asan.
16-
if (compiler-rt IN_LIST LLVM_ENABLE_RUNTIMES)
17-
list(REMOVE_ITEM LLVM_ENABLE_RUNTIMES compiler-rt)
18-
if(NOT DEFINED LLVM_BUILD_COMPILER_RT OR LLVM_BUILD_COMPILER_RT)
19-
list(PREPEND LLVM_ENABLE_RUNTIMES compiler-rt)
20-
endif()
21-
endif()
22-
23-
# If both libc++ and libc++abi are being built, always configure libc++abi before libc++.
24-
# This allows libc++ to depend on targets set up by libc++abi when it needs to.
25-
if (libcxx IN_LIST LLVM_ENABLE_RUNTIMES AND libcxxabi IN_LIST LLVM_ENABLE_RUNTIMES)
26-
list(FIND LLVM_ENABLE_RUNTIMES libcxx _libcxx_index)
27-
list(FIND LLVM_ENABLE_RUNTIMES libcxxabi _libcxxabi_index)
28-
if (_libcxx_index LESS _libcxxabi_index)
29-
list(TRANSFORM LLVM_ENABLE_RUNTIMES REPLACE "^libcxx$" "libcxxabi" AT ${_libcxx_index})
30-
list(TRANSFORM LLVM_ENABLE_RUNTIMES REPLACE "^libcxxabi$" "libcxx" AT ${_libcxxabi_index})
31-
endif()
32-
endif()
24+
include(SortSubset)
25+
sort_subset("${LLVM_ALL_RUNTIMES}" "${LLVM_ENABLE_RUNTIMES}" LLVM_ENABLE_RUNTIMES)
3326

3427
foreach(proj ${LLVM_ENABLE_RUNTIMES})
3528
set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}")
@@ -50,18 +43,6 @@ endfunction()
5043
find_package(LLVM PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
5144
find_package(Clang PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
5245

53-
set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
54-
55-
# Add path for custom and the LLVM build's modules to the CMake module path.
56-
list(INSERT CMAKE_MODULE_PATH 0
57-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
58-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
59-
"${LLVM_COMMON_CMAKE_UTILS}"
60-
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
61-
"${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake"
62-
"${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake/modules"
63-
)
64-
6546
set(LLVM_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../third-party")
6647

6748
# If building standalone by pointing CMake at this runtimes directory,

0 commit comments

Comments
 (0)