Skip to content

Commit 19af8a1

Browse files
authored
Merge pull request #3201 from gottesmm/refactor_llvmclangcmark_config_into_separate_macros
Refactor llvmclangcmark config into separate macros
2 parents bd43806 + 242fa0c commit 19af8a1

File tree

1 file changed

+72
-58
lines changed

1 file changed

+72
-58
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@ else()
1212
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
1313
endif()
1414

15-
# Common cmake project config for standalone builds.
16-
#
17-
# Parameters:
18-
# product
19-
# The product name, e.g. Swift or SourceKit. Used as prefix for some
20-
# cmake variables.
21-
#
22-
# is_cross_compiling
23-
# Whether this is cross-compiling host tools.
24-
macro(swift_common_standalone_build_config product is_cross_compiling)
15+
macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
2516
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
2617

2718
precondition_translate_flag(${product}_PATH_TO_LLVM_SOURCE PATH_TO_LLVM_SOURCE)
@@ -68,44 +59,6 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
6859
precondition_translate_flag(LLVM_BUILD_BINARY_DIR LLVM_BINARY_DIR)
6960
precondition_translate_flag(LLVM_BUILD_MAIN_SRC_DIR LLVM_MAIN_SRC_DIR)
7061

71-
# Clang
72-
set(${product}_PATH_TO_CLANG_SOURCE "${PATH_TO_LLVM_SOURCE}/tools/clang"
73-
CACHE PATH "Path to Clang source code.")
74-
set(${product}_PATH_TO_CLANG_BUILD "${PATH_TO_LLVM_BUILD}" CACHE PATH
75-
"Path to the directory where Clang was built or installed.")
76-
77-
set(${product}_PATH_TO_CMARK_SOURCE "${${product}_PATH_TO_CMARK_SOURCE}"
78-
CACHE PATH "Path to CMark source code.")
79-
set(${product}_PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
80-
CACHE PATH "Path to the directory where CMark was built.")
81-
set(${product}_CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}" CACHE PATH
82-
"Path to the directory where CMark was installed.")
83-
get_filename_component(PATH_TO_CMARK_BUILD "${${product}_PATH_TO_CMARK_BUILD}"
84-
ABSOLUTE)
85-
get_filename_component(CMARK_MAIN_SRC_DIR "${${product}_PATH_TO_CMARK_SOURCE}"
86-
ABSOLUTE)
87-
get_filename_component(CMARK_LIBRARY_DIR "${${product}_CMARK_LIBRARY_DIR}"
88-
ABSOLUTE)
89-
90-
if(NOT EXISTS "${${product}_PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h")
91-
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_SOURCE to the root directory of Clang's source code.")
92-
else()
93-
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
94-
ABSOLUTE)
95-
endif()
96-
97-
if(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/include/clang/Basic/Version.inc")
98-
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/include")
99-
elseif(EXISTS "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
100-
set(CLANG_BUILD_INCLUDE_DIR "${${product}_PATH_TO_CLANG_BUILD}/tools/clang/include")
101-
else()
102-
message(FATAL_ERROR "Please set ${product}_PATH_TO_CLANG_BUILD to a directory containing a Clang build.")
103-
endif()
104-
if(CLANG_MAIN_INCLUDE_DIR)
105-
get_filename_component(CLANG_MAIN_SRC_DIR ${${product}_PATH_TO_CLANG_SOURCE}
106-
ABSOLUTE)
107-
endif()
108-
10962
if(${is_cross_compiling})
11063
find_program(SWIFT_TABLEGEN_EXE "llvm-tblgen" "${${product}_NATIVE_LLVM_TOOLS_PATH}"
11164
NO_DEFAULT_PATH)
@@ -115,7 +68,6 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
11568
else()
11669
set(SWIFT_TABLEGEN_EXE llvm-tblgen)
11770
set(${product}_NATIVE_LLVM_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
118-
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
11971
endif()
12072

12173
include(AddLLVM)
@@ -132,17 +84,9 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
13284
"${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}" CACHE STRING
13385
"Version number that will be placed into the libclang library , in the form XX.YY")
13486

135-
set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
136-
set(CMARK_MAIN_INCLUDE_DIR "${CMARK_MAIN_SRC_DIR}/src")
137-
set(CMARK_BUILD_INCLUDE_DIR "${PATH_TO_CMARK_BUILD}/src")
138-
13987
set(CMAKE_INCLUDE_CURRENT_DIR ON)
14088
include_directories("${PATH_TO_LLVM_BUILD}/include"
141-
"${LLVM_MAIN_INCLUDE_DIR}"
142-
"${CLANG_BUILD_INCLUDE_DIR}"
143-
"${CLANG_MAIN_INCLUDE_DIR}"
144-
"${CMARK_MAIN_INCLUDE_DIR}"
145-
"${CMARK_BUILD_INCLUDE_DIR}")
89+
"${LLVM_MAIN_INCLUDE_DIR}")
14690
foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
14791
include_directories(${INCLUDE_DIR})
14892
endforeach ()
@@ -170,6 +114,76 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
170114
endif()
171115
endmacro()
172116

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})
183+
swift_common_standalone_build_config_clang(${product} ${is_cross_compiling})
184+
swift_common_standalone_build_config_cmark(${product})
185+
endmacro()
186+
173187
# Common cmake project config for unified builds.
174188
#
175189
# Parameters:

0 commit comments

Comments
 (0)