VS2019 CMake linux项目指定gcc版本
在项目顶层的CmakeLists.txt中 设置
1、
CC=gcc-4.2 CXX=/usr/bin/g++-4.2 cmake -G "Your Generator" path/to/your/source
2、
cmake -G "Your Generator" -D CMAKE_C_COMPILER=gcc-4.2 -D CMAKE_CXX_COMPILER=g++-4.2 path/to/your/source
cmake -D CMAKE_C_COMPILER=/usr/bin/gcc -D CMAKE_CXX_COMPILER=/usr/bin/g++ . -DRUN_IN_PLACE=TRUE
3、设置缓存区
set(CMAKE_C_COMPILER /usr/bin/clang CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER /usr/bin/clang++ CACHE PATH "" FORCE)
会破坏编译器检查和配置
This is almost the same as the “normal” variable version, the only difference is your value will be set in the cache, so users can see it. But any change will be overwritten by the set command.
Breaking compiler checks and tooling
Early in the configuration process, CMake performs checks on the
compiler: Does it work? Is it able to produce executables? etc. It
also uses the compiler to detect related tools, like ar and ranlib.
When you override the compiler value in a script, it’s “too late”, all
checks and detections are already done.For instance, on my machine with gcc as default compiler, when using
the set command to /usr/bin/clang, ar is set to /usr/bin/gcc-ar-7.
When using an export before running CMake it is set to
/usr/lib/llvm-3.8/bin/llvm-ar.
设置详解
cmake 设置 gcc 版本 官方