[cmake-developers] CheckSymbolExists.cmake

Brad King brad.king at kitware.com
Wed Jun 5 16:10:03 EDT 2013


On 06/05/2013 03:16 PM, Christopher Sean Morrison wrote:
> getting past GCC's pedantic point about direct type conversion.

If the user tests with -Werror that warning could be a problem,
so that flag is worth stripping if possible.

Ideally we need a test that works with gcc flags

 -std=c99 -pedantic -Werror -O3

The only one I've found from some quick experiments requires
two source files:

 $ cat symbol_main.c
 #include <stdio.h> /* declares tested symbol */
 extern int cmakeRequireSymbol();
 int main(void) { return cmakeRequireSymbol(&printf); }

 $ cat symbol_impl.c
 int cmakeRequireSymbol(int* x) { return *x; }

 $ gcc -std=c99 -pedantic -Werror -O3 symbol_main.c symbol_impl.c

In this approach we hide the pointer conversion from the compiler.
If a compiler does whole-program optimization we could restore the
argc offset part.

-Brad



More information about the cmake-developers mailing list