Skip to content

Commit 5236f2d

Browse files
committed
[cmake] Refactor out clang related config from swift_common_standalone_build_config to swift_common_standalone_build_config_clang.
rdar://26154980
1 parent db964d3 commit 5236f2d

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,42 @@ else()
1212
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
1313
endif()
1414

15+
macro(swift_common_standalone_build_config_clang product is_cross_compiling)
16+
# Clang
17+
set(${product}_PATH_TO_CLANG_SOURCE "${PATH_TO_LLVM_SOURCE}/tools/clang"
18+
CACHE PATH "Path to Clang source code.")
19+
set(${product}_PATH_TO_CLANG_BUILD "${PATH_TO_LLVM_BUILD}" CACHE PATH
20+
"Path to the directory where Clang was built or installed.")
21+
22+
if(NOT EXISTS "${${product}_PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h")
23+
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_SOURCE to the root directory of Clang's source code.")
24+
else()
25+
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
26+
ABSOLUTE)
27+
endif()
28+
29+
if(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/include/clang/Basic/Version.inc")
30+
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/include")
31+
elseif(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
32+
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include")
33+
else()
34+
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_BUILD to a directory containing a Clang build.")
35+
endif()
36+
if(CLANG_MAIN_INCLUDE_DIR)
37+
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
38+
ABSOLUTE)
39+
endif()
40+
41+
if (NOT ${is_cross_compiling})
42+
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
43+
endif()
44+
45+
set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
46+
47+
include_directories("${CLANG_BUILD_INCLUDE_DIR}"
48+
"${CLANG_MAIN_INCLUDE_DIR}")
49+
endmacro()
50+
1551
macro(swift_common_standalone_build_config_cmark product)
1652
set(${product}_PATH_TO_CMARK_SOURCE "${${product}_PATH_TO_CMARK_SOURCE}"
1753
CACHE PATH "Path to CMark source code.")
@@ -87,31 +123,6 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
87123
precondition_translate_flag(LLVM_BUILD_BINARY_DIR LLVM_BINARY_DIR)
88124
precondition_translate_flag(LLVM_BUILD_MAIN_SRC_DIR LLVM_MAIN_SRC_DIR)
89125

90-
# Clang
91-
set(${product}_PATH_TO_CLANG_SOURCE "${PATH_TO_LLVM_SOURCE}/tools/clang"
92-
CACHE PATH "Path to Clang source code.")
93-
set(${product}_PATH_TO_CLANG_BUILD "${PATH_TO_LLVM_BUILD}" CACHE PATH
94-
"Path to the directory where Clang was built or installed.")
95-
96-
if(NOT EXISTS "${${product}_PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h")
97-
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_SOURCE to the root directory of Clang's source code.")
98-
else()
99-
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
100-
ABSOLUTE)
101-
endif()
102-
103-
if(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/include/clang/Basic/Version.inc")
104-
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/include")
105-
elseif(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
106-
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include")
107-
else()
108-
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_BUILD to a directory containing a Clang build.")
109-
endif()
110-
if(CLANG_MAIN_INCLUDE_DIR)
111-
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
112-
ABSOLUTE)
113-
endif()
114-
115126
if(${is_cross_compiling})
116127
find_program(SWIFT_TABLEGEN_EXE "llvm-tblgen" "${${product}_NATIVE_LLVM_TOOLS_PATH}"
117128
NO_DEFAULT_PATH)
@@ -121,7 +132,6 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
121132
else()
122133
set(SWIFT_TABLEGEN_EXE llvm-tblgen)
123134
set(${product}_NATIVE_LLVM_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
124-
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
125135
endif()
126136

127137
include(AddLLVM)
@@ -138,13 +148,9 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
138148
"${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}" CACHE STRING
139149
"Version number that will be placed into the libclang library , in the form XX.YY")
140150

141-
set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
142-
143151
set(CMAKE_INCLUDE_CURRENT_DIR ON)
144152
include_directories("${PATH_TO_LLVM_BUILD}/include"
145-
"${LLVM_MAIN_INCLUDE_DIR}"
146-
"${CLANG_BUILD_INCLUDE_DIR}"
147-
"${CLANG_MAIN_INCLUDE_DIR}")
153+
"${LLVM_MAIN_INCLUDE_DIR}")
148154
foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
149155
include_directories(${INCLUDE_DIR})
150156
endforeach ()
@@ -171,6 +177,7 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
171177
find_package(Doxygen REQUIRED)
172178
endif()
173179

180+
swift_common_standalone_build_config_clang(${product} ${is_cross_compiling})
174181
swift_common_standalone_build_config_cmark(${product})
175182
endmacro()
176183

0 commit comments

Comments
 (0)