Skip to content

Commit 242fa0c

Browse files
committed
[cmake] Refactor out llvm related config from swift_common_standalone_build_config to swift_common_standalone_build_config_llvm.
*NOTE* The diff looks bigger than it actually is. This is just a pure refactoring. rdar://26154980
1 parent 5236f2d commit 242fa0c

File tree

1 file changed

+68
-65
lines changed

1 file changed

+68
-65
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,71 +12,7 @@ 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-
51-
macro(swift_common_standalone_build_config_cmark product)
52-
set(${product}_PATH_TO_CMARK_SOURCE "${${product}_PATH_TO_CMARK_SOURCE}"
53-
CACHE PATH "Path to CMark source code.")
54-
set(${product}_PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
55-
CACHE PATH "Path to the directory where CMark was built.")
56-
set(${product}_CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}" CACHE PATH
57-
"Path to the directory where CMark was installed.")
58-
get_filename_component(PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
59-
ABSOLUTE)
60-
get_filename_component(CMARK_MAIN_SRC_DIR "${${product}_PATH_TO_CMARK_SOURCE}"
61-
ABSOLUTE)
62-
get_filename_component(CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}"
63-
ABSOLUTE)
64-
set(CMARK_MAIN_INCLUDE_DIR "${CMARK_MAIN_SRC_DIR}/src")
65-
set(CMARK_BUILD_INCLUDE_DIR "${PATH_TO_CMARK_BUILD}/src")
66-
include_directories("${CMARK_MAIN_INCLUDE_DIR}"
67-
"${CMARK_BUILD_INCLUDE_DIR}")
68-
endmacro()
69-
70-
# Common cmake project config for standalone builds.
71-
#
72-
# Parameters:
73-
# product
74-
# The product name, e.g. Swift or SourceKit. Used as prefix for some
75-
# cmake variables.
76-
#
77-
# is_cross_compiling
78-
# Whether this is cross-compiling host tools.
79-
macro(swift_common_standalone_build_config product is_cross_compiling)
15+
macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
8016
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
8117

8218
precondition_translate_flag(${product}_PATH_TO_LLVM_SOURCE PATH_TO_LLVM_SOURCE)
@@ -176,7 +112,74 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
176112
if (LLVM_ENABLE_DOXYGEN)
177113
find_package(Doxygen REQUIRED)
178114
endif()
115+
endmacro()
179116

117+
macro(swift_common_standalone_build_config_clang product is_cross_compiling)
118+
# Clang
119+
set(${product}_PATH_TO_CLANG_SOURCE "${PATH_TO_LLVM_SOURCE}/tools/clang"
120+
CACHE PATH "Path to Clang source code.")
121+
set(${product}_PATH_TO_CLANG_BUILD "${PATH_TO_LLVM_BUILD}" CACHE PATH
122+
"Path to the directory where Clang was built or installed.")
123+
124+
if(NOT EXISTS "${${product}_PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h")
125+
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_SOURCE to the root directory of Clang's source code.")
126+
else()
127+
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
128+
ABSOLUTE)
129+
endif()
130+
131+
if(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/include/clang/Basic/Version.inc")
132+
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/include")
133+
elseif(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
134+
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include")
135+
else()
136+
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_BUILD to a directory containing a Clang build.")
137+
endif()
138+
if(CLANG_MAIN_INCLUDE_DIR)
139+
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
140+
ABSOLUTE)
141+
endif()
142+
143+
if (NOT ${is_cross_compiling})
144+
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
145+
endif()
146+
147+
set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
148+
149+
include_directories("${CLANG_BUILD_INCLUDE_DIR}"
150+
"${CLANG_MAIN_INCLUDE_DIR}")
151+
endmacro()
152+
153+
macro(swift_common_standalone_build_config_cmark product)
154+
set(${product}_PATH_TO_CMARK_SOURCE "${${product}_PATH_TO_CMARK_SOURCE}"
155+
CACHE PATH "Path to CMark source code.")
156+
set(${product}_PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
157+
CACHE PATH "Path to the directory where CMark was built.")
158+
set(${product}_CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}" CACHE PATH
159+
"Path to the directory where CMark was installed.")
160+
get_filename_component(PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
161+
ABSOLUTE)
162+
get_filename_component(CMARK_MAIN_SRC_DIR "${${product}_PATH_TO_CMARK_SOURCE}"
163+
ABSOLUTE)
164+
get_filename_component(CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}"
165+
ABSOLUTE)
166+
set(CMARK_MAIN_INCLUDE_DIR "${CMARK_MAIN_SRC_DIR}/src")
167+
set(CMARK_BUILD_INCLUDE_DIR "${PATH_TO_CMARK_BUILD}/src")
168+
include_directories("${CMARK_MAIN_INCLUDE_DIR}"
169+
"${CMARK_BUILD_INCLUDE_DIR}")
170+
endmacro()
171+
172+
# Common cmake project config for standalone builds.
173+
#
174+
# Parameters:
175+
# product
176+
# The product name, e.g. Swift or SourceKit. Used as prefix for some
177+
# cmake variables.
178+
#
179+
# is_cross_compiling
180+
# Whether this is cross-compiling host tools.
181+
macro(swift_common_standalone_build_config product is_cross_compiling)
182+
swift_common_standalone_build_config_llvm(${product} ${is_cross_compiling})
180183
swift_common_standalone_build_config_clang(${product} ${is_cross_compiling})
181184
swift_common_standalone_build_config_cmark(${product})
182185
endmacro()

0 commit comments

Comments
 (0)