Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 相当于autoconf';在CMake中进行检查_C++_Cmake - Fatal编程技术网

C++ 相当于autoconf';在CMake中进行检查

C++ 相当于autoconf';在CMake中进行检查,c++,cmake,C++,Cmake,在CMake中,什么与autoconf的AC_CHECK_DECLS等效 我正在设置以下固定定义。我需要根据环境来改变它 target_compile_definitions(myapp PRIVATE HAVE_ENDIAN_H=1 HAVE_DECL_BSWAP_16=1 HAVE_DECL_HTOLE16=1 HAVE_DECL_BE16TOH=1 HAVE_DECL_LE16TOH=1 HAVE_DECL_HTOBE32=1 HAVE_DECL_HTOLE32=1 HAVE_DECL_B

在CMake中,什么与autoconf的AC_CHECK_DECLS等效

我正在设置以下固定定义。我需要根据环境来改变它

target_compile_definitions(myapp PRIVATE HAVE_ENDIAN_H=1 HAVE_DECL_BSWAP_16=1 HAVE_DECL_HTOLE16=1 HAVE_DECL_BE16TOH=1 HAVE_DECL_LE16TOH=1 HAVE_DECL_HTOBE32=1 HAVE_DECL_HTOLE32=1 HAVE_DECL_BE32TOH=1 HAVE_DECL_LE32TOH=1 HAVE_DECL_HTOBE64=1 HAVE_DECL_HTOLE64=1 HAVE_DECL_BE64TOH=1 HAVE_DECL_LE64TOH=1 HAVE_DECL_HTOBE16=1)
我正在研究与CMake中的autoconf AC_CHECK_DECLS功能相同的功能

手册

— Macro: AC_CHECK_DECLS (symbols, [action-if-found], [action-if-not-found], [includes = ‘AC_INCLUDES_DEFAULT’])
For each of the symbols (comma-separated list), define HAVE_DECL_symbol (in all capitals) to ‘1’ if symbol is declared, otherwise to ‘0’. If action-if-not-found is given, it is additional shell code to execute when one of the function declarations is needed, otherwise action-if-found is executed.

示例

AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
        [#if HAVE_ENDIAN_H
                 #include <endian.h>
                 #elif HAVE_SYS_ENDIAN_H
                 #include <sys/endian.h>
                 #endif])

在CMake中,您可以检查是否使用模块声明了符号。例如:

include(CheckSymbolExists)
# ...
# Set HAVE_DECL_LE16TOH variable to 1 or 0 depending on declaration 'le16toh' symbol in 'endian.h' header.
CHECK_SYMBOL_EXISTS(le16toh "endian.h" HAVE_DECL_LE16TOH)
与自动工具中的
AC\u CHECK\u DECLS
宏相比:

  • 调用
    检查符号是否存在()
    一次检查单个符号。要检查多个符号,可以在循环中调用它

  • 对于
    检查\u SYMBOL\u EXISTS()
    您需要指定具体的标题列表

    如果头文件的包含取决于某些其他宏,则需要首先检查此宏,可以使用另一个调用
    检查符号\u EXISTS()
    (宏是否定义了),也可以使用普通命令(检查宏的)。或者,您可以检查模块中是否存在特定的标头

  • 调用common
    if()
    if(NOT)
    后,可以根据
    CHECK\u SYMBOL\u EXISTS()
    的结果发出附加操作


谢谢。我会试试的,谢谢。成功了。我在HAVE_ENDIAN_H中使用了“CHECK_INCLUDE_FILE”。我认为这很好。在堆栈溢出问题上,我们倾向于不将问题和解决方案混为一谈。“更新1”下面的所有内容都可以进入您自己的答案(即自我回答)。此外,您的解决方案可能会引起一些讨论。。。据我所知,您的
target\u compile\u definitions()
调用无条件地定义给定的宏(即,不使用
CHECK\u SYMBOL\u EXISTS()
的结果)。对于条件定义,可以使用
target\u compile\u定义(myapp PRIVATE HAVE\u ENDIAN\u H=${HAVE\u ENDIAN\u H}…
.Oops。我将更改目标\u编译\u定义并测试它。在我确认之后,我会将这些发现作为我自己的答案发布。谢谢你的更正。
include(CheckSymbolExists)
# ...
# Set HAVE_DECL_LE16TOH variable to 1 or 0 depending on declaration 'le16toh' symbol in 'endian.h' header.
CHECK_SYMBOL_EXISTS(le16toh "endian.h" HAVE_DECL_LE16TOH)