使我的FindLibDL CMake脚本不报告错误的布尔值 [英] Making my FindLibDL CMake script not report failure for a false boolean value
问题描述
我正在使用 FindLibDL CMake模块其中,除其他事项外,它确定有关下划线的布尔值:
I'm usiing a FindLibDL CMake module which, among other things, determines some boolean value regarding underscores:
# ...
CHECK_C_SOURCE_RUNS("#include <dlfcn.h>
#include <stdlib.h>
void testfunc() {}
int main() {
testfunc();
if (dlsym(0, \"_testfunc\") != (void*)0) {
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}" LIBDL_NEEDS_UNDERSCORE)
mark_as_advanced(LIBDL_INCLUDE_DIRS LIBDL_LIBRARIES LIBDL_NEEDS_UNDERSCORE)
问题是,如果不需要下划线,则CMake报告 LIBDL_NEEDS_UNDERSCORE
失败。如何使它仍然确定相同的值并且仍然不报告为失败?
The thing is, if underscores are not needed, CMake reports a Failure for LIBDL_NEEDS_UNDERSCORE
. How can I make it so that I still determine the same value and still not reported as a Failure?
推荐答案
与@arrowed点一样,这就是 CHECK_C_SOURCE_RUNS 宏的工作方式:如果已编译程序返回0,则报告成功,否则报告失败。
As @arrowd points, it is just how CHECK_C_SOURCE_RUNS macro works: if compiled program returns 0, it reports Success, otherwise it reports Failed.
如果需要其他输出,则可以使用 try_run 命令。
If you want other output, you may use try_run command directly.
例如使用 try_run
,您可能会达到以下行为:
E.g. with try_run
you may achive this behavior:
-
如果需要下划线,输出为
if underscore is needed, output is
Check whether 'dl' requires underscore - Yes
如果不需要下划线,则输出为
if underscore is not needed, output is
Check whether 'dl' requires underscore - No
if error occurs during the check, output is
Check whether 'dl' requires underscore - Failed
这篇关于使我的FindLibDL CMake脚本不报告错误的布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!