Skip to content

Commit 6c261ce

Browse files
committed
[cmake] Include ClangTargets.cmake so that any clang libraries we include get the correct LLVM/Clang dependency ordering.
This means that one can just use LINK_LIBRARIES to get the correct dependency information without needing to know anything further. rdar://26154980
1 parent 781c856 commit 6c261ce

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,35 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
112112
endmacro()
113113

114114
macro(swift_common_standalone_build_config_clang product is_cross_compiling)
115-
# Clang
116115
set(${product}_PATH_TO_CLANG_SOURCE "${PATH_TO_LLVM_SOURCE}/tools/clang"
117116
CACHE PATH "Path to Clang source code.")
118117
set(${product}_PATH_TO_CLANG_BUILD "${PATH_TO_LLVM_BUILD}" CACHE PATH
119118
"Path to the directory where Clang was built or installed.")
120119

121-
if(NOT EXISTS "${${product}_PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h")
120+
set(PATH_TO_CLANG_SOURCE "${${product}_PATH_TO_CLANG_SOURCE}")
121+
set(PATH_TO_CLANG_BUILD "${${product}_PATH_TO_CLANG_BUILD}")
122+
123+
# Add all Clang CMake paths to our cmake module path.
124+
set(SWIFT_CLANG_CMAKE_PATHS
125+
"${PATH_TO_CLANG_BUILD}/share/clang/cmake")
126+
foreach(path ${SWIFT_CLANG_CMAKE_PATHS})
127+
list(APPEND CMAKE_MODULE_PATH ${path})
128+
endforeach()
129+
130+
# Then include ClangTargets.cmake. If Clang adds a ClangConfig.cmake, this is
131+
# where it will be included. By including ClangTargets.cmake, we at least get
132+
# the right dependency ordering for clang libraries.
133+
include(ClangTargets)
134+
135+
if(NOT EXISTS "${PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h")
122136
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_SOURCE to the root directory of Clang's source code.")
123137
endif()
124-
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
125-
ABSOLUTE)
138+
get_filename_component(CLANG_MAIN_SRC_DIR "${PATH_TO_CLANG_SOURCE}" ABSOLUTE)
126139

127-
if(NOT EXISTS "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
140+
if(NOT EXISTS "${PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
128141
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_BUILD to a directory containing a Clang build.")
129142
endif()
130-
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include")
143+
set(CLANG_BUILD_INCLUDE_DIR "${PATH_TO_CLANG_BUILD}/tools/clang/include")
131144

132145
if (NOT ${is_cross_compiling})
133146
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")

0 commit comments

Comments
 (0)