CMAKE_COMPILER_IS_GNUCXX and CMAKE_CXX_COMPILER_ID are empty

I am currently playing with CMake and want to determine the compiler and version of the compiler. My current CMakeLists.txt 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 successfully clean, create and run the cli application with this file (if I comment on 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 use the operating system Microsoft Windows 8 (6.3.9600) and MinGW , in more detail the following tools.

Versions of tools used

As you can in the screenshot, I use the NetBeans IDE to simplify the entire build process.

So my questions are:

  • What are the possible reasons why these variables are empty?
  • Is there any workaround for my problem?

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

+6
source share
2 answers

Put the command after project :

 > cat CMakeLists.txt cmake_minimum_required(VERSION 2.8) message("before:") message("> ${CMAKE_CXX_COMPILER}") message("> ${CMAKE_CXX_COMPILER_ID}") message("> ${CMAKE_COMPILER_IS_GNUCXX}") message("-----------------") project(Foo) message("after:") message("> ${CMAKE_CXX_COMPILER}") message("> ${CMAKE_CXX_COMPILER_ID}") message("> ${CMAKE_COMPILER_IS_GNUCXX}") message("-----------------") > cmake -H. -B_builds before: > > > ----------------- -- The C compiler identification is GNU 4.8.1 -- The CXX compiler identification is GNU 4.8.1 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done after: > /usr/bin/c++ > GNU > 1 ----------------- -- Configuring done -- Generating done -- Build files have been written to: /.../_builds 
+6
source

This can help you tell CMake that this is a C ++ project. To do this, you will say this in the project command:

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

You can also do this before checking the variable.

+2
source

All Articles