#2679·folly

[macOS] CMake build fails with libc++ `<cwctype>` error due to system SDK `/usr/include` in `Folly::folly_deps`

Author: lgong2025Created Aug 12, 2026Updated Aug 12, 2026

Environment

  • OS: macOS (Apple Silicon M4)
  • Folly Version: v2026.07.27.00 (Homebrew bottle)
  • Installation Method: Homebrew (brew install folly)
  • Build System: CMake (3.16+)

Description / Actual Behavior

When linking Folly::folly in a standalone CMake project on macOS, compilation fails with the following LLVM libc++ error:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cwctype:61:5: error: <cwctype> tried including <wctype.h> but didn't find libc++'s <wctype.h> header. This usually means that your header search paths are not configured properly. The header search paths should contain the C++ Standard Library headers before any C Standard Library, and you are probably using compiler flags that make that not be the case.
   61 | #   error <cwctype> tried including <wctype.h> but didn't find libc++'s <wctype.h> header. \

Minimal Reproducible Example

main.cpp

cpp
#include <iostream>
#include <folly/FBString.h>

int main(int argc, char **argv) {
    folly::fbstring greeting = "Hello, " + folly::fbstring("World") + "!";
    std::cout << "--- fbstring Demo ---" << std::endl;
    std::cout << greeting << std::endl << std::endl;
    return 0;
}

CMakeLists.txt

cmake
cmake_minimum_required(VERSION 3.16)
project(folly_demo CXX)

set(CMAKE_CXX_STANDARD 20)

find_package(folly REQUIRED)
add_executable(folly_demo main.cpp)

target_link_libraries(folly_demo PRIVATE
    Folly::folly
)

Commands to reproduce:

bash
brew install folly
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build

Investigation & Root Cause Analysis

Upon inspecting folly-targets.cmake generated/installed on the system, Folly::folly_deps explicitly injects system SDK paths into INTERFACE_INCLUDE_DIRECTORIES:

cmake
set_target_properties(Folly::folly_deps PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "/opt/homebrew/include;/Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include;${_IMPORT_PREFIX}/include"
  ...
)

That results in the following build command:

/usr/bin/c++ -DBOOST_ATOMIC_DYN_LINK -DBOOST_ATOMIC_NO_LIB -DBOOST_CONTAINER_DYN_LINK -DBOOST_CONTAINER_NO_LIB -DBOOST_CONTEXT_DYN_LINK -DBOOST_CONTEXT_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_FILESYSTEM_NO_LIB -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_NO_LIB -DBOOST_REGEX_DYN_LINK -DBOOST_REGEX_NO_LIB -DFMT_SHARED -DGFLAGS_IS_A_DLL=0 -DGLOG_USE_GFLAGS -DGLOG_USE_GLOG_EXPORT -isystem /opt/homebrew/include -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include -std=gnu++20 -arch arm64 -o CMakeFiles/folly_demo.dir/main.cpp.o -c /path/to/main.cpp

and we suspected that -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include is the culprit.

Workaround / Verification: Manually removing /Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk/usr/include from INTERFACE_INCLUDE_DIRECTORIES in folly-targets.cmake allows the build to succeed cleanly.

Could the team take a look into how folly_deps include directories are exported during CMake target generation on macOS/Homebrew installations?