To define which C and C++ compilers to use, you can define the
CC
and CXX
environment
variables. For example:
shell> CC=gcc
shell> CXX=g++
shell> export CC CXX
To specify your own C and C++ compiler flags, for flags that
do not affect optimization, use the
CMAKE_C_FLAGS
and
CMAKE_CXX_FLAGS
CMake options:
cmake .. -DCMAKE_C_FLAGS=your_c_flags \
-DCMAKE_CXX_FLAGS=your_c++_flags
When providing your own compiler flags, you might want to
specify CMAKE_BUILD_TYPE
as
well.
For example, to create a 32-bit release build on a 64-bit Linux machine, do this:
cmake .. -DCMAKE_C_FLAGS=-m32 \
-DCMAKE_CXX_FLAGS=-m32 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo
If you set flags that affect optimization
(-O
), you
must set the
number
CMAKE_C_FLAGS_
and/or
build_type
CMAKE_CXX_FLAGS_
options, where build_type
build_type
corresponds to the
CMAKE_BUILD_TYPE
value. To
specify a different optimization for the default build type
(RelWithDebInfo
) set the
CMAKE_C_FLAGS_RELWITHDEBINFO
and
CMAKE_CXX_FLAGS_RELWITHDEBINFO
options. For
example, to compile on Linux with -O3
and
with debug symbols, do this:
cmake .. -DCMAKE_C_FLAGS_RELWITHDEBINFO="-O3 -g" \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O3 -g"