Прежде всего, я работаю над Windows . Таким образом, приведенная ниже командная строка находится в VS2022 pwsh.
Я добавил это в CMakeLists.txt верхнего уровня:
Код: Выделить всё
cmake_minimum_required(VERSION 3.5)
if(DEFINED CC)
set(CMAKE_C_COMPILER ${CC} CACHE STRING "C Compiler" Force)
endif()
if(DEFINED CXX)
set(CMAKE_CXX_COMPILER ${CXX} CACHE STRING "C++ Compiler" Force)
endif()
.
.
.
.
Код: Выделить всё
g++:
cmake -S . -B build -G Ninja -DCC=clang-cl -DCXX=clang-cl
Код: Выделить всё
cmake -S . -B build -G Ninja -DCC=gcc -DCXX=g++
Код: Выделить всё
-- The C compiler identification is MSVC 19.40.33811.0
-- The CXX compiler identification is MSVC 19.40.33811.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Developer/Microsoft/VisualStudio/2022/Community/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Developer/Microsoft/VisualStudio/2022/Community/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for sys/types.h
.
.
.
Код: Выделить всё
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= gcc
CMAKE_CXX_COMPILER= g++
-- The C compiler identification is GNU 13.1.0
-- The CXX compiler identification is GNU 13.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Developer/Strawberry/c/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Developer/Strawberry/c/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Как я могу позволить cmake включить мой псевдоним в первую конфигурацию?
Подробнее здесь: https://stackoverflow.com/questions/787 ... ly-ignored