How to get C system header search directories?

How to get the C system header directories, e.g. where does gcc look to find a system header file ("#include <someSystemHeader>")? I have a very short test file:

cmake_minimum_required(VERSION 3.18)
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_C_STANDARD 11)

message("CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES: ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
message("CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}")

Running ‘cmake -P’ shows both variables are empty:

$ cmake -P test.cmake
CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES: 
CMAKE_SYSTEM_PREFIX_PATH:

I expect these variables to contain at least “/usr/include” and “/usr/local/include”. What am I missing?

Thanks!

In script processing mode it’s not surprising those aren’t defined, since cmake doesn’t actually enable any compilers. Try printing those variables in an actual project.

1 Like