2017-08-27 141 views
2

我想建立一個最小的例子來建立一個C程序。當我運行cmake .爲什麼CMake檢查C++編譯器?

cmake_minimum_required(VERSION 3.6) 

set(CMAKE_SYSTEM_NAME Generic) 
set(CMAKE_SYSTEM_PROCESSOR arm) 

set(CMAKE_C_COMPILER "arm-none-eabi-gcc") 
#set(CMAKE_CXX_COMPILER "arm-none-eabi-g++") 

set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "") 

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 

project("funambule") 

list(
    APPEND src 
     main.c 
) 

add_executable(
    funambule 
    ${src} 
) 

:我用這個CMakeLists.txt文件。儘管我不需要C++編譯器,但它絕對需要檢查C++編譯器。我怎樣才能防止它做這個無用的檢查?

-- The C compiler identification is GNU 5.4.1 
-- The CXX compiler identification is GNU 5.4.0 
-- Check for working C compiler: /cygdrive/c/Users/NoOne/Home/bin/arm-none-eabi-gcc 
-- Check for working C compiler: /cygdrive/c/Users/NoOne/Home/bin/arm-none-eabi-gcc -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - failed 
-- Detecting C compile features 
-- Detecting C compile features - done 
-- Check for working CXX compiler: /usr/bin/CC 
-- Check for working CXX compiler: /usr/bin/CC -- broken 
... 

回答

5

這是CMake的默認行爲。要改變它,你應該爲你的項目中使用指定的語言:

project(<PROJECT-NAME> [LANGUAGES]) 

CMake documentation

您還可以指定哪些語言項目支持。示例語言是C,CXX(即C++),Fortran等。默認情況下,如果未給出語言選項,則啓用C和CXX。指定語言NONE,或使用LANGUAGES關鍵字並且不列出任何語言,以跳過啓用任何語言。