命令行
cmake -D USERDEFINE=$DEFIN -G "MinGW Makefiles" -D CMAKE_CXX_COMPILER="E:/mingw64/bin/g++.exe" -D CMAKE_C_COMPILER="E:/mingw64/bin/gcc.exe" ..
cmake中
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
set (CMAKE_C_COMPILER E:/mingw64/bin/gcc.exe)
set (CMAKE_CXX_COMPILER E:/mingw64/bin/g++.exe)
endif()
project(my_cmake_tests)
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
set(CMAKE_BUILD_TYPE "Debug")
若gcc g++ 已经加入path
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
set (CMAKE_C_COMPILER gcc)
set (CMAKE_CXX_COMPILER g++)
endif()