Making my FindLibDL CMake script not report failur

2019-09-15 03:44发布

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)

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?

标签: cmake
1条回答
做自己的国王
2楼-- · 2019-09-15 04:17

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.

If you want other output, you may use try_run command directly.


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
    
查看更多
登录 后发表回答