0

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • If underscores aren't need, this var contains `FALSE`. What's the problem? It is working as you intended. – arrowd Aug 14 '17 at 10:38
  • @arrowd: The problem is the CMake's console output tells me something has failed, while nothing fails, it's just `FALSE`. – einpoklum Aug 14 '17 at 11:28

1 Answers1

1

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
    
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Oh, wait - the `try_run` command takes a source file; but I don't have a source file, I only have the module. Are you suggesting I create a temporary file and use that? Or is there a trick not involving a temporary file? – einpoklum Aug 14 '17 at 15:15
  • Create temporary source file. [Implementation of CHECK_C_SOURCE_RUNS](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/CheckCSourceRuns.cmake) uses exactly this way. – Tsyvarev Aug 14 '17 at 20:27