【问题标题】:how to get visual c++ default include path using cmake?如何使用 cmake 获取 Visual C++ 默认包含路径?
【发布时间】:2013-06-20 04:32:20
【问题描述】:

我尝试使用 cmake 确定是否存在 inttypes.h 头文件来生成 Visual c++ 11 的项目。

最初,我在 CMakeLists.txt 中写了下面这句话

FIND_FILE(HAVE_INTTYPES_H "inttypes.h" DOC "Does the inttypes.h exist?")

不幸的是,HAVE_INTTYPES_H 变量是 HAVE_INTTYPES_H-NOTFOUND。

之后,我查阅了有关 find_file 的 cmake 文档,其中提到需要一些搜索路径。但是我无法在cmake的任何地方获取c标准头文件?

谢谢。

【问题讨论】:

    标签: cmake


    【解决方案1】:

    您的find_file 呼叫是正确的。问题是 Visual Studio 上没有 inttypes.h。所以保持你的测试不变,但是当它没有找到时包括另一个标题,例如:http://code.google.com/p/msinttypes/

    类似:

    FIND_FILE(HAVE_INTTYPES_H "inttypes.h" DOC "Does the inttypes.h exist?")
    if (HAVE_INTTYPES_H)
        add_definitions(-DHAVE_INTTYPES_H=1)
    endif()
    

    在你的代码中:

    #ifdef HAVE_INTTYPES_H
    #include <inttypes.h>
    #else
    #include "path/to/inttypes.h"
    #endif
    

    现在,要检测标头,您可能还想尝试使用 CheckIncludeFile 标准 CMake 模块,它尝试使用您的目标编译器检测包含文件,而不是搜索文件系统:

    include(CheckIncludeFile)
    
    check_include_file("stdint.h" STDINT_H_FOUND)
    if (STDINT_H_FOUND)
        add_definitions(-DHAVE_STDINT_H=1)
    endif()
    

    【讨论】:

    • 谢谢,但我发现 stdint.h 在 Visual Studio 2012 中仍然失败。但是,此文档确实存在,“C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdint .h"
    • 我编辑了我的帖子以包含另一种使用 check_include_file 检测标头的方法,这可能对您更有效。
    猜你喜欢
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多