Skip to content

Commit fab1630

Browse files
authored
Merge pull request #16874 from gottesmm/pr-4b615a53246f430a2aa930207041f82738eac2a3
[benchmark] Move build configuration/sdk configuration out of the main CMakeLists.txt file into AddSwiftBenchmarkSuite.cmake.
2 parents 5f8209e + 9740bef commit fab1630

File tree

2 files changed

+86
-59
lines changed

2 files changed

+86
-59
lines changed

benchmark/CMakeLists.txt

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ endif()
2121

2222
include(AddSwiftBenchmarkSuite)
2323

24+
#===-----------------------------------------------------------------------===#
25+
# Declarative Description of Benchmarks
26+
#===-----------------------------------------------------------------------===#
27+
2428
set(SWIFT_BENCH_MODULES
2529
single-source/Ackermann
2630
single-source/AngryPhonebook
@@ -186,37 +190,9 @@ set(BENCH_DRIVER_LIBRARY_MODULES
186190
utils/DriverUtils
187191
)
188192

189-
add_definitions(-DSWIFT_EXEC -DSWIFT_LIBRARY_PATH -DONLY_PLATFORMS
190-
-DSWIFT_OPTIMIZATION_LEVELS -DSWIFT_BENCHMARK_EMIT_SIB)
191-
192-
if(NOT ONLY_PLATFORMS)
193-
set(ONLY_PLATFORMS "macosx" "iphoneos" "appletvos" "watchos")
194-
endif()
195-
196-
if(NOT SWIFT_EXEC)
197-
runcmd(COMMAND "xcrun" "-f" "swiftc"
198-
VARIABLE SWIFT_EXEC
199-
ERROR "Unable to find Swift driver")
200-
endif()
201-
202-
if(NOT SWIFT_LIBRARY_PATH)
203-
get_filename_component(tmp_dir "${SWIFT_EXEC}" DIRECTORY)
204-
get_filename_component(tmp_dir "${tmp_dir}" DIRECTORY)
205-
set(SWIFT_LIBRARY_PATH "${tmp_dir}/lib/swift")
206-
endif()
207-
208-
# If the CMAKE_C_COMPILER is already clang, don't find it again,
209-
# thus allowing the --host-cc build-script argument to work here.
210-
get_filename_component(c_compiler ${CMAKE_C_COMPILER} NAME)
211-
212-
if(${c_compiler} STREQUAL "clang")
213-
set(CLANG_EXEC ${CMAKE_C_COMPILER})
214-
else()
215-
runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
216-
VARIABLE CLANG_EXEC
217-
ERROR "Unable to find Clang driver")
218-
endif()
219-
193+
#===-----------------------------------------------------------------------===#
194+
# Build Configuration
195+
#===-----------------------------------------------------------------------===#
220196

221197
# You have to delete CMakeCache.txt in the swift build to force a
222198
# reconfiguration.
@@ -273,34 +249,17 @@ set(BENCHOPTS_MULTITHREADED
273249
"-whole-module-optimization" "-num-threads" "4")
274250
set(BENCHOPTS_SINGLEFILE "")
275251

276-
set(macosx_arch "x86_64")
277-
set(iphoneos_arch "arm64" "armv7")
278-
set(appletvos_arch "arm64")
279-
set(watchos_arch "armv7k")
280-
281-
set(macosx_ver "10.9")
282-
set(iphoneos_ver "8.0")
283-
set(appletvos_ver "9.1")
284-
set(watchos_ver "2.0")
285-
286-
set(macosx_triple_platform "macosx")
287-
set(iphoneos_triple_platform "ios")
288-
set(appletvos_triple_platform "tvos")
289-
set(watchos_triple_platform "watchos")
290-
291-
set(sdks)
292-
set(platforms)
293-
foreach(platform ${ONLY_PLATFORMS})
294-
execute_process(
295-
COMMAND "xcrun" "--sdk" "${platform}" "--show-sdk-path"
296-
OUTPUT_VARIABLE ${platform}_sdk
297-
RESULT_VARIABLE result
298-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
299-
if("${result}" MATCHES "0")
300-
list(APPEND sdks "${${platform}_sdk}")
301-
list(APPEND platforms ${platform})
302-
endif()
303-
endforeach()
252+
configure_build()
253+
254+
#===-----------------------------------------------------------------------===#
255+
# SDK Configuration
256+
#===-----------------------------------------------------------------------===#
257+
258+
configure_sdks()
259+
260+
#===---------------------------------------------------------------------===#
261+
# Statement of Configuration for Build Users
262+
#===---------------------------------------------------------------------===#
304263

305264
message("--")
306265
message("-- Swift Benchmark Suite:")
@@ -318,6 +277,10 @@ foreach(sdk ${sdks})
318277
message("-- ${sdk}")
319278
endforeach()
320279

280+
#===---------------------------------------------------------------------===#
281+
# Build Rule Generation
282+
#===---------------------------------------------------------------------===#
283+
321284
set(executable_targets)
322285

323286
set(srcdir "${CMAKE_CURRENT_SOURCE_DIR}")

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,70 @@
22
include(CMakeParseArguments)
33
include(SwiftBenchmarkUtils)
44

5+
macro (configure_build)
6+
add_definitions(-DSWIFT_EXEC -DSWIFT_LIBRARY_PATH -DONLY_PLATFORMS
7+
-DSWIFT_OPTIMIZATION_LEVELS -DSWIFT_BENCHMARK_EMIT_SIB)
8+
9+
if(NOT ONLY_PLATFORMS)
10+
set(ONLY_PLATFORMS "macosx" "iphoneos" "appletvos" "watchos")
11+
endif()
12+
13+
if(NOT SWIFT_EXEC)
14+
runcmd(COMMAND "xcrun" "-f" "swiftc"
15+
VARIABLE SWIFT_EXEC
16+
ERROR "Unable to find Swift driver")
17+
endif()
18+
19+
if(NOT SWIFT_LIBRARY_PATH)
20+
get_filename_component(tmp_dir "${SWIFT_EXEC}" DIRECTORY)
21+
get_filename_component(tmp_dir "${tmp_dir}" DIRECTORY)
22+
set(SWIFT_LIBRARY_PATH "${tmp_dir}/lib/swift")
23+
endif()
24+
25+
# If the CMAKE_C_COMPILER is already clang, don't find it again,
26+
# thus allowing the --host-cc build-script argument to work here.
27+
get_filename_component(c_compiler ${CMAKE_C_COMPILER} NAME)
28+
29+
if(${c_compiler} STREQUAL "clang")
30+
set(CLANG_EXEC ${CMAKE_C_COMPILER})
31+
else()
32+
runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
33+
VARIABLE CLANG_EXEC
34+
ERROR "Unable to find Clang driver")
35+
endif()
36+
endmacro()
37+
38+
macro (configure_sdks)
39+
set(macosx_arch "x86_64")
40+
set(iphoneos_arch "arm64" "armv7")
41+
set(appletvos_arch "arm64")
42+
set(watchos_arch "armv7k")
43+
44+
set(macosx_ver "10.9")
45+
set(iphoneos_ver "8.0")
46+
set(appletvos_ver "9.1")
47+
set(watchos_ver "2.0")
48+
49+
set(macosx_triple_platform "macosx")
50+
set(iphoneos_triple_platform "ios")
51+
set(appletvos_triple_platform "tvos")
52+
set(watchos_triple_platform "watchos")
53+
54+
set(sdks)
55+
set(platforms)
56+
foreach(platform ${ONLY_PLATFORMS})
57+
execute_process(
58+
COMMAND "xcrun" "--sdk" "${platform}" "--show-sdk-path"
59+
OUTPUT_VARIABLE ${platform}_sdk
60+
RESULT_VARIABLE result
61+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
62+
if("${result}" MATCHES "0")
63+
list(APPEND sdks "${${platform}_sdk}")
64+
list(APPEND platforms ${platform})
65+
endif()
66+
endforeach()
67+
endmacro()
68+
569
function (add_swift_benchmark_library objfile_out sibfile_out)
670
cmake_parse_arguments(BENCHLIB "" "MODULE_PATH;SOURCE_DIR;OBJECT_DIR" "SOURCES;LIBRARY_FLAGS;DEPENDS" ${ARGN})
771

0 commit comments

Comments
 (0)