Skip to content

Commit

Permalink
Disable char8_t on broken compilers
Browse files Browse the repository at this point in the history
On some compilers, notably Clang with Xcode Command Line Tools on macOS
10.14, using char8_t can cause linker failures. For example:

    Undefined symbols for architecture x86_64:
      "__ZTIDu", referenced from:
          __ZN7testing8internal11GetTypeNameIKDuEENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEv in test-parse.cpp.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

Disable char8_t on these compilers.
  • Loading branch information
strager committed Jan 23, 2021
1 parent e0525e4 commit 12a13cb
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions cmake/QuickLintJSCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,38 @@ function (quick_lint_js_check_designated_initializers OUT)
endfunction ()

function (quick_lint_js_enable_char8_t_if_supported)
check_cxx_compiler_flag(-fchar8_t QUICK_LINT_JS_HAVE_FCHAR8_T)
if (QUICK_LINT_JS_HAVE_FCHAR8_T)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fchar8_t>)
check_cxx_compiler_flag(-fchar8_t QUICK_LINT_JS_HAVE_FCHAR8_T_FLAG)
if (QUICK_LINT_JS_HAVE_FCHAR8_T_FLAG)
check_cxx_source_compiles(
"#include <cstdio>
#include <typeinfo>
int main() {
std::puts(typeid(char).name());
return 0;
}" QUICK_LINT_JS_HAVE_TYPEID)
if (QUICK_LINT_JS_HAVE_TYPEID)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fchar8_t")
# On some compilers, -fchar8_t appears to work, unless typeid is used.
# Avoid -fchar8_t on these broken compilers.
check_cxx_source_compiles(
"#include <cstdio>
#include <typeinfo>
int main() {
std::puts(typeid(char8_t).name());
return 0;
}" QUICK_LINT_JS_HAVE_WORKING_FCHAR8_T)
else ()
set(QUICK_LINT_JS_HAVE_WORKING_FCHAR8_T TRUE)
endif ()

if (QUICK_LINT_JS_HAVE_WORKING_FCHAR8_T)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fchar8_t>)
else ()
check_cxx_compiler_flag(-fno-char8_t QUICK_LINT_JS_HAVE_FNO_CHAR8_T_FLAG)
if (QUICK_LINT_JS_HAVE_FNO_CHAR8_T_FLAG)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-char8_t>)
endif ()
endif ()
endif ()
endfunction ()

Expand Down

0 comments on commit 12a13cb

Please sign in to comment.