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
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.
Place it after project
command:
> 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