简体   繁体   English

检查time.h / sys / time.h compatibilitybilty

[英]Check for time.h / sys/time.h compatibilty

I am currently porting an autotools project to CMake that uses the AC_HEADER_TIME autotools macro to check if I can include both time.h and sys/time.h . 我目前正在将一个autotools项目移植到CMake,它使用AC_HEADER_TIME autotools宏来检查我是否可以同时包含time.hsys/time.h

How can this be done with CMake? 如何用CMake完成?

It isn't the time test specifically, but for an example of how to do that sort of thing you might check out this example from BRL-CAD: 这不是具体的时间测试,但是对于如何做这类事情的例子,你可以从BRL-CAD中查看这个例子:

http://sourceforge.net/p/brlcad/code/HEAD/tree/brlcad/trunk/misc/CMake/test_srcs/sys_wait_test.c http://sourceforge.net/p/brlcad/code/HEAD/tree/brlcad/trunk/misc/CMake/test_srcs/sys_wait_test.c

The code is then used to do a test in CMake with: 然后使用该代码在CMake中进行测试:

CHECK_C_SOURCE_RUNS(${CMAKE_SOURCE_DIR}/misc/CMake/test_srcs/sys_wait_test.c SYS_WAIT_TEST_RUNS)

You can also use CHECK_C_SOURCE_COMPILES if you don't want to try to run the code (we usually do, but that sort of thing is situation dependent.) See http://www.cmake.org/cmake/help/v3.0/module/CheckCSourceRuns.html and http://www.cmake.org/cmake/help/v3.0/module/CheckCSourceCompiles.html for more information about using variables to control how the compilation is done. 如果您不想尝试运行代码,也可以使用CHECK_C_SOURCE_COMPILES(我们通常会这样做,但这种情况依赖于情境。)请参阅http://www.cmake.org/cmake/help/v3.0 /module/CheckCSourceRuns.htmlhttp://www.cmake.org/cmake/help/v3.0/module/CheckCSourceCompiles.html ,以获取有关使用变量控制编译方式的更多信息。 Generally speaking if you need to set those variables, you'll want to cache their current values before specifying the test values and then restore the original values after the test, ie 一般来说,如果您需要设置这些变量,您需要在指定测试值之前缓存其当前值,然后在测试后恢复原始值,即

set(CMAKE_REQUIRED_FLAGS_CACHE ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-foo_flag")
CHECK_C_SOURCE_RUNS(${CMAKE_SOURCE_DIR}/CMake/time_test.c TIME_TEST_RUNS)
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_CACHE})

I've had a few puzzling behaviors in tests over the years that resulted from leftovers from one test interfering with another. 多年来我在测试中遇到了一些令人费解的行为,这些行为是由于一次测试中的剩余物干扰了另一次。

您可以将try_compile()与样本源一起使用,其中#include两个文件并检查结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM