System include path

I’m currently in the process of using pclint in checking the c and c++ source files for errors. So when I have a target I want to lint the files that are the sources of that target to be processed using the pclint application. Currently I have it working so that the include folders for the target are also passed to the pclint application. This works quite oke, but one off the final errors is that the pclint application can’t find the system include files and generates errors for that.

So my question is how can I find the general system include folders for a certain target or source?
I thought that it had to do with INTERFACE_SYSTEM_INCLUDE_DIRECTORIES but when I read this out through several ways of get_property it always returns empty.

That said it might also be relevant that I’m using a cross compiler and that sysroot has been set.

I have just the same problem with clang-tidy:

|| clang-tidy -header-filter=/Users/clausklein/Workspace/cpp/netkit-tftp/.* -checks=-*,cppcoreguidelines-*,cppcoreguidelines-pro-* portability-*,readability-* ,misc-*,boost-*,cert-*,misc-unused-parameters -p=/Users/clausklein/Workspace/cpp/netkit-tftp /Users/clausklein/Workspace/cpp/netkit-tftp/tftpd_test.cpp
async_tftpd_server.hpp|3 col 10| error: 'functional' file not found [clang-diagnostic-error]
|| #include <functional>
||          ^

I have tried to add the include path to the c++ header with:

include_directories(SYSTEM /usr/local/include/c++/${CMAKE_CXX_COMPILER_VERSION})
# ...
target_include_directories(tftpd SYSTEM PRIVATE /usr/local/include/c++/${CMAKE_CXX_COMPILER_VERSION})

but cmake does suppress the second and so it is not added to compile_commands.json file except for c targets?

{
  "directory": "/Users/clausklein/Workspace/cpp/.build-netkit-tftp-Debug",
  "command": "/usr/local/opt/gcc/bin/g++-9  -DASIO_NO_DEPRECATED -DASIO_STANDALONE -DBOOST_ALL_NO_LIB -Dtftpd_EXPORTS -I/Users/clausklein/Workspace/cpp/netkit-tftp -isystem /usr/local/Cellar/boost/1.72.0_2/include -isystem /usr/local/include  -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fPIC   -Wall -Wextra \"-Wno-#pragma-messages\" -Wno-deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -std=c++17 -o CMakeFiles/tftpd.dir/tftp_subs.o -c /Users/clausklein/Workspace/cpp/netkit-tftp/tftp_subs.cpp",
  "file": "/Users/clausklein/Workspace/cpp/netkit-tftp/tftp_subs.cpp"
},

{
  "directory": "/Users/clausklein/Workspace/cpp/.build-netkit-tftp-Debug",
  "command": "/usr/local/opt/gcc/bin/gcc-9  -isystem /usr/local/include/c++/9.3.0  -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk   -Wall -Wextra \"-Wno-#pragma-messages\" -Wno-deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -o tftp/CMakeFiles/tftp.dir/tftp.o   -c /Users/clausklein/Workspace/cpp/netkit-tftp/tftp/tftp.c",
  "file": "/Users/clausklein/Workspace/cpp/netkit-tftp/tftp/tftp.c"
},

see too https://gitlab.kitware.com/cmake/cmake/-/issues/20912

It seem help to set CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES

1 Like

I’m using a MAC M1 12.2.1 to compile c++ code and my problem is similar with yours:

I use cmake to build, although specified the the system include directory with include_directories() or target_include_directories() the compile_commands.json always shows the same -isysroot path:

[
{
  "directory": "/Users/eduardo/Documents/Repos/competitive/build",
  "command": "/opt/homebrew/bin/g++-11   -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -std=gnu++17 -o CMakeFiles/a.dir/main.cpp.o -c /Users/eduardo/Documents/Repos/competitive/main.cpp",
  "file": "/Users/eduardo/Documents/Repos/competitive/main.cpp"
}
]

And my LSP complains about not finding the include files putting error squiggles all over the place.

Using CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES solved for me:

[
{
  "directory": "/Users/eduardo/Documents/Repos/competitive/build",
  "command": "/opt/homebrew/bin/g++-11  -isystem /opt/homebrew/include/c++/11 -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -std=gnu++17 -o CMakeFiles/a.dir/main.cpp.o -c /Users/eduardo/Documents/Repos/competitive/main.cpp",
  "file": "/Users/eduardo/Documents/Repos/competitive/main.cpp"
}
]

More than 1 month trying to solve this until I saw your tip. Thanks!