Files
swift-mirror/cmake/modules/SwiftCheckCXXNativeRegex.cmake
Michael Gottesman 5eb835cfcf [cmake] Refactor check_working_std_regex into its own cmake file SwiftCheckCXXNativeRegex.cmake and rename it appropriately.
It is better to have the top level CMake file only consist of includes and
settings, rather than have it include business logic like this.

Should be NFC.
2016-07-04 20:45:27 -07:00

33 lines
1011 B
CMake

function(check_cxx_native_regex result_var_name)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
# Apple operating systems use libc++, which has a working std::regex.
set("${result_var_name}" TRUE PARENT_SCOPE)
else()
if(CMAKE_CROSSCOMPILING)
# Can't run C source when cross-compiling; assume false until we have a static check.
set("${result_var_name}" FALSE PARENT_SCOPE)
else()
# libstdc++ 4.8 has an incomplete std::regex implementation, and crashes
# on many regexes.
# libstdc++ 4.9 works.
set(std_regex_test_source
"
#include <regex>
const std::regex broken_regex{
\"([a]+)\",
std::regex::ECMAScript | std::regex::nosubs};
int main() {}
")
check_cxx_source_runs("${std_regex_test_source}" "${result_var_name}_TEST")
if ("${${result_var_name}_TEST}")
set("${result_var_name}" TRUE PARENT_SCOPE)
else()
set("${result_var_name}" FALSE PARENT_SCOPE)
endif()
endif()
endif()
endfunction()