Cmake check for compiler

I am trying to play with cmake to create a little C ++ code.

I don't have g++ yet (I'm testing on a virtual OS)

When I call cmake . I get nasty error messages.

 -- The C compiler identification is GNU 4.7.2 **-- The CXX compiler identification is unknown** -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done **CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name. -- Configuring incomplete, errors occurred!** 

In principle, everything is in order. It says that errors have occurred, but he says too much than necessary. I just want to get an accurate and concise message that "g ++ is not installed. INSTALL it."

Is there a way to check if g++ installed and then give the appropriate message?

0
cmake
Nov 01 '13 at 23:17
source share
2 answers

The result you gave shows that CMake is trying to help you. If this is too verbose for your taste, perhaps the easiest way to reduce it would be to capture it into a variable and then examine it.

You can save the sample CMake script below as detect_cxx_compiler.cmake and invoke the script with cmake -P detect_cxx_compiler.cmake . The code is written in such a way as to be useful for beginners of CMake, and not for small size or processing efficiency.

 cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR) cmake_policy(VERSION 2.8.5) # This cmake script (when saved as detect_cxx_compiler.cmake) is invoked by: # # cmake -P detect_cxx_compiler.cmake # # It is written for clarity, not brevity. # First make a new directory, so that we don't mess up the current one. execute_process( COMMAND ${CMAKE_COMMAND} -E make_directory detection_area WORKING_DIRECTORY . ) # Here, we generate a key file that CMake needs. execute_process( COMMAND ${CMAKE_COMMAND} -E touch CMakeLists.txt WORKING_DIRECTORY detection_area ) # Have CMake check the basic configuration. The output is # actually in the form that you posted in your question, but # instead of displaying it onscreen, we save it to a variable # so that we can select only parts of it to print later. execute_process( COMMAND ${CMAKE_COMMAND} --check-system-vars OUTPUT_VARIABLE the_output OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY detection_area ) # Eliminate the directory, including all of the files within it that # CMake created. execute_process( COMMAND ${CMAKE_COMMAND} -E remove_directory detection_area WORKING_DIRECTORY . ) # Here, you have the entire message captured as a variable. # Uncomment this next line to convince yourself of this. #message(STATUS "the_output = |${the_output}|.") # Here, we search the message to see if the C++ compiler was found or not, # and print an arbitrary message accordingly. string(FIND "${the_output}" "CMAKE_CXX_COMPILER-NOTFOUND" scan_result) #message(STATUS "scan_result = |${scan_result}|.") if(NOT(-1 EQUAL "${scan_result}")) message(FATAL_ERROR "A C++ compiler was not detected.") endif() message(STATUS "A C++ compiler was detected.") 
0
Nov 02 '13 at 6:15
source share

You must use the GCC frontend (Gnu Compiler Collection). You should install gcc-C ++ or something similar.

-one
Nov 01 '13 at 23:22
source share



All Articles