gpt4 book ai didi

c++ - 相当于CMake中autoconf的AC_CHECK_DECLS

转载 作者:行者123 更新时间:2023-11-30 02:25:06 28 4
gpt4 key购买 nike

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.

https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Generic-Declarations.html

示例

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])

更新 1

@Tsyvarev 给了我答案。非常感谢。

我改变了配置如下。它有效。

include(CheckSymbolExists)
CHECK_INCLUDE_FILE(endian.h HAVE_ENDIAN_H)
CHECK_SYMBOL_EXISTS(htole16 "endian.h" HAVE_DECL_HTOLE16)
CHECK_SYMBOL_EXISTS(be16toh "endian.h" HAVE_DECL_BE16TOH)
CHECK_SYMBOL_EXISTS(le16toh "endian.h" HAVE_DECL_LE16TOH)
CHECK_SYMBOL_EXISTS(htobe32 "endian.h" HAVE_DECL_HTOBE32)
CHECK_SYMBOL_EXISTS(htole32 "endian.h" HAVE_DECL_HTOLE32)
CHECK_SYMBOL_EXISTS(be32toh "endian.h" HAVE_DECL_BE32TOH)
CHECK_SYMBOL_EXISTS(le32toh "endian.h" HAVE_DECL_LE32TOH)
CHECK_SYMBOL_EXISTS(htobe64 "endian.h" HAVE_DECL_HTOBE64)
CHECK_SYMBOL_EXISTS(htole64 "endian.h" HAVE_DECL_HTOLE64)
CHECK_SYMBOL_EXISTS(be64toh "endian.h" HAVE_DECL_BE64TOH)
CHECK_SYMBOL_EXISTS(le64toh "endian.h" HAVE_DECL_LE64TOH)
CHECK_SYMBOL_EXISTS(htobe16 "endian.h" HAVE_DECL_HTOBE16)
CHECK_SYMBOL_EXISTS(bswap_16 "byteswap.h" HAVE_DECL_HTOBE16)
target_compile_definitions(myapp PRIVATE HAVE_ENDIAN_H HAVE_DECL_BSWAP_16 HAVE_DECL_HTOLE16 HAVE_DECL_BE16TOH HAVE_DECL_LE16TOH HAVE_DECL_HTOBE32 HAVE_DECL_HTOLE32 HAVE_DECL_BE32TOH HAVE_DECL_LE32TOH HAVE_DECL_HTOBE64 HAVE_DECL_HTOLE64 HAVE_DECL_BE64TOH HAVE_DECL_LE64TOH HAVE_DECL_HTOBE16)

最佳答案

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

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_CHECK_DECLS 相比autotools 中的宏:

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

  • CHECK_SYMBOL_EXISTS()您需要指定标题的具体列表。

    如果头文件的包含依赖于其他一些宏,您需要先检查这个宏,或者再次调用 CHECK_SYMBOL_EXISTS() (无论宏是否被定义),或者使用普通命令 try_compile (检查宏的)。或者,您可以使用 CheckIncludeFile 检查特定 header 是否存在模块。

  • 其他操作取决于 CHECK_SYMBOL_EXISTS() 的结果可以在调用common if(<var>)后发出或 if(NOT <var>) .

关于c++ - 相当于CMake中autoconf的AC_CHECK_DECLS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44754512/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com