CMAKE_COMPILER_IS_GNUCXX和CMAKE_CXX_COMPILER_ID为空 [英] CMAKE_COMPILER_IS_GNUCXX and CMAKE_CXX_COMPILER_ID are empty

查看:2981
本文介绍了CMAKE_COMPILER_IS_GNUCXX和CMAKE_CXX_COMPILER_ID为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在玩来简化整个因此我的问题是:


  1. 什么是可能的原因,

而且,我的问题是否有解决方法?请告诉我,如果您看到我的(简单) CMakeLists.txt 文件的任何其他问题。

解决方案

可以 帮助你告诉CMake这是一个C ++项目。要做到这一点你可以在项目中说:

  $(PROJECT)CXX)
#^^^
#注意项目类型

您可能还需要在检查变量之前执行此操作。


I am currently playing around with CMake and want to detect the compiler and the compiler version. My current CMakeLists.txt looks as follows:

cmake_minimum_required (VERSION 2.6)

set (PROJECT "a_tour_of_c++")
set (GNUCXX_MINIMUM_VERSION "4.8")
set (CXX_STANDARD "c++11")

message ("${CMAKE_CXX_COMPILER}")       # C:/dev/MinGW/bin/g++.exe
message ("${CMAKE_CXX_COMPILER_ID}")    # EMPTY
message ("${CMAKE_COMPILER_IS_GNUCXX}") # EMPTY

if (CMAKE_COMPILER_IS_GNUCXX)
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GNUCXX_MINIMUM_VERSION)
    message (FATAL_ERROR "GCC version must be at least ${GNUCXX_MINIMUM_VERSION}!")
  endif()
else()
  message (FATAL_ERROR "Invalid compiler!")
endif()

set (BUILD_DIR build)
set (HEADER_DIR include)
set (SOURCE_DIR src)
set (MAIN_FILE ${SOURCE_DIR}/main.cc)

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${CXX_STANDARD}")
project ($(PROJECT))
include_directories (${HEADER_DIR})
add_executable (${BUILD_DIR}/${PROJECT} ${MAIN_FILE})

The file is fine and I can sucessfully clean, build and run my cli application with this file (if I comment out the else-branch of the compiler check).

The problem is, that both CMAKE_CXX_COMPILER_ID and CMAKE_COMPILER_IS_GNUCXX are empty (CMAKE_CXX_COMPILER is not).

I am using a Microsoft Windows 8 (6.3.9600) operating system and MinGW, more detailed the following tools.

As you can in the screenshot, I use NetBeans IDE to simplify the whole build progress.

So my questions are:

  1. What are possible reasons, that the mentioned variables are empty?
  2. Does any workaround exist for my problem?

And please let me know, if you see any other problems with my (simple) CMakeLists.txt file.

解决方案

It might help you tell CMake that this is a C++ project. To do it you say it in the project command:

project ($(PROJECT) CXX)
#                   ^^^
# Note project type

You might also want to do it before checking the variable.

这篇关于CMAKE_COMPILER_IS_GNUCXX和CMAKE_CXX_COMPILER_ID为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆