C++ 相当于autoconf';在CMake中进行检查
在CMake中,什么与autoconf的AC_CHECK_DECLS等效 我正在设置以下固定定义。我需要根据环境来改变它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
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()
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)