Skip to content

Commit 1e2d192

Browse files
authored
Merge pull request #3339 from gottesmm/small_cmake_refactoring
2 parents dfa2ba3 + 5eb835c commit 1e2d192

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

CMakeLists.txt

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -432,38 +432,8 @@ if(XCODE)
432432
swift_common_xcode_cxx_config()
433433
endif()
434434

435-
function(check_working_std_regex result_var_name)
436-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
437-
# Apple operating systems use libc++, which has a working std::regex.
438-
set("${result_var_name}" TRUE PARENT_SCOPE)
439-
else()
440-
if(CMAKE_CROSSCOMPILING)
441-
# Can't run C source when cross-compiling; assume false until we have a static check.
442-
set("${result_var_name}" FALSE PARENT_SCOPE)
443-
else()
444-
# libstdc++ 4.8 has an incomplete std::regex implementation, and crashes
445-
# on many regexes.
446-
# libstdc++ 4.9 works.
447-
set(std_regex_test_source
448-
"
449-
#include <regex>
450-
const std::regex broken_regex{
451-
\"([a]+)\",
452-
std::regex::ECMAScript | std::regex::nosubs};
453-
454-
int main() {}
455-
")
456-
457-
check_cxx_source_runs("${std_regex_test_source}" "${result_var_name}_TEST")
458-
if ("${${result_var_name}_TEST}")
459-
set("${result_var_name}" TRUE PARENT_SCOPE)
460-
else()
461-
set("${result_var_name}" FALSE PARENT_SCOPE)
462-
endif()
463-
endif()
464-
endif()
465-
endfunction()
466-
check_working_std_regex(SWIFT_HAVE_WORKING_STD_REGEX)
435+
include(SwiftCheckCXXNativeRegex)
436+
check_cxx_native_regex(SWIFT_HAVE_WORKING_STD_REGEX)
467437

468438
# If SWIFT_HOST_VARIANT_SDK not given, try to detect from the CMAKE_SYSTEM_NAME.
469439
if(SWIFT_HOST_VARIANT_SDK)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function(check_cxx_native_regex result_var_name)
2+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
3+
# Apple operating systems use libc++, which has a working std::regex.
4+
set("${result_var_name}" TRUE PARENT_SCOPE)
5+
else()
6+
if(CMAKE_CROSSCOMPILING)
7+
# Can't run C source when cross-compiling; assume false until we have a static check.
8+
set("${result_var_name}" FALSE PARENT_SCOPE)
9+
else()
10+
# libstdc++ 4.8 has an incomplete std::regex implementation, and crashes
11+
# on many regexes.
12+
# libstdc++ 4.9 works.
13+
set(std_regex_test_source
14+
"
15+
#include <regex>
16+
const std::regex broken_regex{
17+
\"([a]+)\",
18+
std::regex::ECMAScript | std::regex::nosubs};
19+
20+
int main() {}
21+
")
22+
23+
check_cxx_source_runs("${std_regex_test_source}" "${result_var_name}_TEST")
24+
if ("${${result_var_name}_TEST}")
25+
set("${result_var_name}" TRUE PARENT_SCOPE)
26+
else()
27+
set("${result_var_name}" FALSE PARENT_SCOPE)
28+
endif()
29+
endif()
30+
endif()
31+
endfunction()
32+

0 commit comments

Comments
 (0)