55
66#include < cppast/cpp_preprocessor.hpp>
77
8+ #include < cstdlib>
9+
810using namespace cppast ;
911
12+ #ifdef __APPLE__
13+ namespace
14+ {
15+ // libclang's embedded driver doesn't auto-detect the Apple SDK from SDKROOT
16+ // for clang_parseTranslationUnit (only the driver binary does). Forward
17+ // -isysroot explicitly so libc++ headers can find <stdlib.h>, <wchar.h>, etc.
18+ void apply_macos_sysroot (libclang_compile_config& config)
19+ {
20+ if (auto sdkroot = std::getenv (" SDKROOT" ))
21+ {
22+ config.add_flag (" -isysroot" );
23+ config.add_flag (sdkroot);
24+ }
25+ }
26+ } // namespace
27+ #endif
28+
1029TEST_CASE (" stdlib" , " [.][integration]" )
1130{
1231 auto code = R"(
@@ -105,6 +124,9 @@ TEST_CASE("stdlib", "[.][integration]")
105124
106125 libclang_compile_config config;
107126 config.set_flags (cpp_standard::cpp_latest);
127+ #ifdef __APPLE__
128+ apply_macos_sysroot (config);
129+ #endif
108130 auto file = parser.parse (" stdlib.cpp" , config);
109131 REQUIRE (!parser.error ());
110132 REQUIRE (file);
@@ -126,6 +148,9 @@ TEST_CASE("cppast", "[integration]")
126148 libclang_compile_config config (database, CPPAST_INTEGRATION_FILE );
127149 config.set_flags (cpp_standard::cpp_latest);
128150 config.fast_preprocessing (true );
151+ #ifdef __APPLE__
152+ apply_macos_sysroot (config);
153+ #endif
129154 parse_files (parser, files, config);
130155
131156 REQUIRE (!parser.error ());
0 commit comments