CMAKE_COMPILER_IS_GNUCXX and CMAKE_CXX_COMPILER_ID are empty

后端 未结 2 1417
感动是毒
感动是毒 2021-02-14 08:49

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         


        
相关标签:
2条回答
  • 2021-02-14 09:16

    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.

    0 讨论(0)
  • 2021-02-14 09:21

    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
    
    0 讨论(0)
提交回复
热议问题