Regression in 3.14.1 and onwards on macOS with Homebrew clang for `-nostdinc++` with `include_directories("/usr/local/opt/llvm/include/c++/v1")`
I noticed a regression on macOS with brewed clang in version 3.14.1 and later. It was working fine in 3.14.0. It is also working as expected with Apple's clang.
Tested macOS versions that are affected are 10.12 and 10.13, with clang 8.0.0 from Homebrew and cmake also from homebrew.
It seems if you use include_directories("/usr/local/opt/llvm/include/c++/v1")
, which may be relevant in combination with -nostdinc++
, this include path is not actually added. As mentioned, this used to work fine on 3.14.0 and earlier, and continues to work fine with latest cmake with Apple clang.
The release notes hint at some changed behaviour of include_directories
, not sure if it is related.
To reproduce:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
set(CMAKE_CXX_COMPILER "/usr/local/opt/llvm/bin/clang++")
project(Foo CXX)
include_directories("/usr/local/opt/llvm/include/c++/v1")
add_compile_options("-nostdinc++")
add_executable(foobar foobar.cpp)
// foobar.cpp
#include <iostream>
int main() {
std::cout << "Foobar";
return 0;
}
With cmake 3.14.3:
$ cmake ..
-- The CXX compiler identification is Clang 8.0.0
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/demmeln/work/slam/dba/cmake_test/build
$ VERBOSE=1 make
/usr/local/Cellar/cmake/3.14.3/bin/cmake -S/Users/demmeln/work/slam/dba/cmake_test -B/Users/demmeln/work/slam/dba/cmake_test/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.14.3/bin/cmake -E cmake_progress_start /Users/demmeln/work/slam/dba/cmake_test/build/CMakeFiles /Users/demmeln/work/slam/dba/cmake_test/build/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/foobar.dir/build.make CMakeFiles/foobar.dir/depend
cd /Users/demmeln/work/slam/dba/cmake_test/build && /usr/local/Cellar/cmake/3.14.3/bin/cmake -E cmake_depends "Unix Makefiles" /Users/demmeln/work/slam/dba/cmake_test /Users/demmeln/work/slam/dba/cmake_test /Users/demmeln/work/slam/dba/cmake_test/build /Users/demmeln/work/slam/dba/cmake_test/build /Users/demmeln/work/slam/dba/cmake_test/build/CMakeFiles/foobar.dir/DependInfo.cmake --color=
Dependee "/Users/demmeln/work/slam/dba/cmake_test/build/CMakeFiles/foobar.dir/DependInfo.cmake" is newer than depender "/Users/demmeln/work/slam/dba/cmake_test/build/CMakeFiles/foobar.dir/depend.internal".
Dependee "/Users/demmeln/work/slam/dba/cmake_test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/demmeln/work/slam/dba/cmake_test/build/CMakeFiles/foobar.dir/depend.internal".
Scanning dependencies of target foobar
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/foobar.dir/build.make CMakeFiles/foobar.dir/build
[ 50%] Building CXX object CMakeFiles/foobar.dir/foobar.cpp.o
/usr/local/opt/llvm/bin/clang++ -nostdinc++ -o CMakeFiles/foobar.dir/foobar.cpp.o -c /Users/demmeln/work/slam/dba/cmake_test/foobar.cpp
/Users/demmeln/work/slam/dba/cmake_test/foobar.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/foobar.dir/foobar.cpp.o] Error 1
make[1]: *** [CMakeFiles/foobar.dir/all] Error 2
make: *** [all] Error 2