Is CMAKE_FIND_ROOT_PATH will overwrite the default search path of compiler?

ubuntu 22.04 and gcc9.4.0

After type the command: echo | gcc -Wp,-v -x c++ - -fsyntax-only

it will output:

ignoring duplicate directory “/usr/include/x86_64-linux-gnu/c++/9”
ignoring nonexistent directory “/usr/local/include/x86_64-linux-gnu”
ignoring nonexistent directory “/usr/lib/gcc/x86_64-linux-gnu/9/include-fixed”
ignoring nonexistent directory “/usr/lib/gcc/x86_64-linux-gnu/9/…/…/…/…/x86_64-linux-gnu/include”
#include “…” search starts here:
#include <…> search starts here:
/usr/include/c++/9
/usr/include/x86_64-linux-gnu/c++/9
/usr/include/c++/9/backward
/usr/lib/gcc/x86_64-linux-gnu/9/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.

I want to know if setting ONLY_CMAKE_FIND_ROOT_PATH will override the compiler’s default search paths?

Are you asking whether the ONLY_CMAKE_FIND_ROOT_PATH will cause CMake to pass a flag to the compiler to drop default search paths when compiling? If that is the question, I don’t think so. Other than that, I’m not sure what find_* command control variables have to do with default compiler search paths.

Cc: @brad.king

Thank you very much for your reply, and I apologize for causing confusion. Allow me to provide a specific description of my question:

When using the following CMake variables:

# where is the target environment located
set(CMAKE_FIND_ROOT_PATH  /usr/i586-mingw32msvc
    /home/alex/mingw-install)

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

For gcc or g++ or ld, will it override their default paths for searching header files or library files? I believe this is important for cross-compilation scenarios.

If I understand your question correctly, no. These variables do nothing to set up include paths to find the files. I suspect that the toolchain file needs to provide the setup for this itself (as projects shouldn’t have to guess at cross-compile setups on their own).

Your code snippet has some “mingw” references:
You have to configure CMake to use the mingw compiler executables. In general cross-compilation is not done with your host compiler.