Cmake 无法识别 MSVC 编译器
Cmake doesn't recognize MSVC compiler
第一次遇到这个错误
我正在尝试克隆 openvr and get the hello opengl sample running, following their instructions:
cd samples
mkdir build
cd build
cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=C:/Qt/5.6/msvc2013_64/lib/cmake
我得到:
$ cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=C:/Qt/5.6/msvc20 13_64/lib/cmake
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler using: Visual Studio 14 2015 Win64
-- Check for working C compiler using: Visual Studio 14 2015 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 14 2015 Win64
-- Check for working CXX compiler using: Visual Studio 14 2015 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compilation set for 64bits architectures.
CMake Warning at CMakeLists.txt:40 (message):
SDL x64 runtime binaries not provided on Windows.
CMake Error at CMakeLists.txt:98 (message):
Unsupported compiler.
-- Configuring incomplete, errors occurred!
See also "C:/Users/GBarbieri/Documents/Visual Studio 2015/Projects/openvr/sample s/build/CMakeFiles/CMakeOutput.log".
如果我去检查第 98 行:
if( (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
# Better to use the prebuilt GNU preprocessor define __GNUC__,
# kept for legacy reason with the sample code.
add_definitions(-DGNUC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -include ${SHARED_SRC_DIR}/compat.h")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
# Handles x86 compilation support on x64 arch.
if(${PLATFORM} MATCHES 32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
endif()
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Za")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /w2 /DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP /INCREMENTAL:NO")
else()
message(FATAL_ERROR "Unsupported compiler. ") // line 98
endif()
好像匹配不上"MSVC"
..我试试看,我在这段代码前加上:
message("${CMAKE_CXX_COMPILER_ID}")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
message("match")
else()
message("!match")
endif()
然后 returns:
MSVC
!match
CMake Error at CMakeLists.txt:104 (message):
Unsupported compiler.
什么?
伙计们,你们能找出问题所在吗?
好的,正如我在评论中尝试的那样,正确的答案是使用:
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
而不是
if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
第一次遇到这个错误
我正在尝试克隆 openvr and get the hello opengl sample running, following their instructions:
cd samples
mkdir build
cd build
cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=C:/Qt/5.6/msvc2013_64/lib/cmake
我得到:
$ cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=C:/Qt/5.6/msvc20 13_64/lib/cmake
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler using: Visual Studio 14 2015 Win64
-- Check for working C compiler using: Visual Studio 14 2015 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 14 2015 Win64
-- Check for working CXX compiler using: Visual Studio 14 2015 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compilation set for 64bits architectures.
CMake Warning at CMakeLists.txt:40 (message):
SDL x64 runtime binaries not provided on Windows.
CMake Error at CMakeLists.txt:98 (message):
Unsupported compiler.
-- Configuring incomplete, errors occurred!
See also "C:/Users/GBarbieri/Documents/Visual Studio 2015/Projects/openvr/sample s/build/CMakeFiles/CMakeOutput.log".
如果我去检查第 98 行:
if( (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
# Better to use the prebuilt GNU preprocessor define __GNUC__,
# kept for legacy reason with the sample code.
add_definitions(-DGNUC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -include ${SHARED_SRC_DIR}/compat.h")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
# Handles x86 compilation support on x64 arch.
if(${PLATFORM} MATCHES 32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
endif()
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Za")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /w2 /DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP /INCREMENTAL:NO")
else()
message(FATAL_ERROR "Unsupported compiler. ") // line 98
endif()
好像匹配不上"MSVC"
..我试试看,我在这段代码前加上:
message("${CMAKE_CXX_COMPILER_ID}")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
message("match")
else()
message("!match")
endif()
然后 returns:
MSVC
!match
CMake Error at CMakeLists.txt:104 (message):
Unsupported compiler.
什么?
伙计们,你们能找出问题所在吗?
好的,正如我在评论中尝试的那样,正确的答案是使用:
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
而不是
if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")