Home

setCMAKECXXCOMPILER

setCMAKECXXCOMPILER is not a separate CMake command; the relevant variable is CMAKE_CXX_COMPILER. This variable stores the full path to the C++ compiler that CMake will use for building C++ targets. It is intended to be set before the project is configured, so that CMake can select and configure the build with the desired compiler.

Ways to set it include passing it on the configure command line, using a toolchain file, or

Notes and caveats: CMAKE_CXX_COMPILER must be set before enabling languages or calling project(). If you set

In summary, CMAKE_CXX_COMPILER specifies the C++ compiler CMake uses, and should be configured prior to project()

assigning
it
in
the
top-level
CMakeLists.txt
before
project()
is
called.
Common
forms
are:
cmake
-S
.
-B
build
-DCMAKE_CXX_COMPILER=/path/to/compiler,
or
in
a
toolchain
file
via
set(CMAKE_CXX_COMPILER
/path/to/compiler).
You
can
also
set
it
in
the
CMake
cache
with
FORCE,
but
this
is
typically
discouraged
for
routine
use.
it
after
CMake
has
configured
the
project,
the
change
will
not
take
effect
in
the
current
configure;
you
usually
need
to
reconfigure
in
a
clean
build
directory.
The
variable
is
part
of
the
cache
in
practice,
so
changing
it
may
require
removing
CMakeCache.txt
or
starting
a
new
build
directory
to
avoid
stale
state.
It
is
commonly
used
for
cross-compiling
or
selecting
a
specific
toolchain
on
multi-compiler
systems.
to
ensure
a
consistent
and
reproducible
build.