Skip to content

Commit 9740bef

Browse files
committed
[benchmark] Move build configuration/sdk configuration out of the main CMakeLists.txt file into AddSwiftBenchmarkSuite.cmake.
I am going to add some support here for Linux. I want to make sure that these changes are hidden from the main CMakeLists.txt file since we want that file to be as declarative as possible. rdar://40541972
1 parent 61fa5d9 commit 9740bef

File tree

2 files changed

+67
-60
lines changed

2 files changed

+67
-60
lines changed

benchmark/CMakeLists.txt

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -199,38 +199,6 @@ set(BENCH_DRIVER_LIBRARY_MODULES
199199
# Build Configuration
200200
#===-----------------------------------------------------------------------===#
201201

202-
add_definitions(-DSWIFT_EXEC -DSWIFT_LIBRARY_PATH -DONLY_PLATFORMS
203-
-DSWIFT_OPTIMIZATION_LEVELS -DSWIFT_BENCHMARK_EMIT_SIB)
204-
205-
if(NOT ONLY_PLATFORMS)
206-
set(ONLY_PLATFORMS "macosx" "iphoneos" "appletvos" "watchos")
207-
endif()
208-
209-
if(NOT SWIFT_EXEC)
210-
runcmd(COMMAND "xcrun" "-f" "swiftc"
211-
VARIABLE SWIFT_EXEC
212-
ERROR "Unable to find Swift driver")
213-
endif()
214-
215-
if(NOT SWIFT_LIBRARY_PATH)
216-
get_filename_component(tmp_dir "${SWIFT_EXEC}" DIRECTORY)
217-
get_filename_component(tmp_dir "${tmp_dir}" DIRECTORY)
218-
set(SWIFT_LIBRARY_PATH "${tmp_dir}/lib/swift")
219-
endif()
220-
221-
# If the CMAKE_C_COMPILER is already clang, don't find it again,
222-
# thus allowing the --host-cc build-script argument to work here.
223-
get_filename_component(c_compiler ${CMAKE_C_COMPILER} NAME)
224-
225-
if(${c_compiler} STREQUAL "clang")
226-
set(CLANG_EXEC ${CMAKE_C_COMPILER})
227-
else()
228-
runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
229-
VARIABLE CLANG_EXEC
230-
ERROR "Unable to find Clang driver")
231-
endif()
232-
233-
234202
# You have to delete CMakeCache.txt in the swift build to force a
235203
# reconfiguration.
236204
set(SWIFT_EXTRA_BENCH_CONFIGS CACHE STRING
@@ -286,38 +254,13 @@ set(BENCHOPTS_MULTITHREADED
286254
"-whole-module-optimization" "-num-threads" "4")
287255
set(BENCHOPTS_SINGLEFILE "")
288256

257+
configure_build()
258+
289259
#===-----------------------------------------------------------------------===#
290260
# SDK Configuration
291261
#===-----------------------------------------------------------------------===#
292262

293-
set(macosx_arch "x86_64")
294-
set(iphoneos_arch "arm64" "armv7")
295-
set(appletvos_arch "arm64")
296-
set(watchos_arch "armv7k")
297-
298-
set(macosx_ver "10.9")
299-
set(iphoneos_ver "8.0")
300-
set(appletvos_ver "9.1")
301-
set(watchos_ver "2.0")
302-
303-
set(macosx_triple_platform "macosx")
304-
set(iphoneos_triple_platform "ios")
305-
set(appletvos_triple_platform "tvos")
306-
set(watchos_triple_platform "watchos")
307-
308-
set(sdks)
309-
set(platforms)
310-
foreach(platform ${ONLY_PLATFORMS})
311-
execute_process(
312-
COMMAND "xcrun" "--sdk" "${platform}" "--show-sdk-path"
313-
OUTPUT_VARIABLE ${platform}_sdk
314-
RESULT_VARIABLE result
315-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
316-
if("${result}" MATCHES "0")
317-
list(APPEND sdks "${${platform}_sdk}")
318-
list(APPEND platforms ${platform})
319-
endif()
320-
endforeach()
263+
configure_sdks()
321264

322265
#===---------------------------------------------------------------------===#
323266
# Statement of Configuration for Build Users

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)