[cmake-developers] CheckSymbolExists is unreliable

Brad King brad.king at kitware.com
Tue Jan 3 14:47:23 EST 2012


On Tue, Jan 3, 2012 at 2:17 PM, Rolf Eike Beer <eike at sf-mail.de> wrote:
> Sorry, that was not intentional. I dropped the previous branch and created a
> new one, based on current master. It has 2 commits: the first one introducing
> the (hopefully) fixed CheckSymbolExists.cmake, the second one adding the
> tests. It also adds a positive test: it checks if errno can be found in
> errno.h for both C and C++. Hope this will not break on some strange machines.

Nice, thanks.

>>   int main(int argc, char* argv[])
>>   {
>>     (void)argv;
>>     return ((int*)(&SYMBOL))[argc];
>>   }
>
> It looks like, at least it survives my -O3 test.

Great.

> Pushed updated branch. Please review and merge to next if you like it.

Can you handle Modules/CheckPrototypeDefinition.cmake too?  I think it
has the same problem.

There are a few problems with the current test.  The configured "cse.cmake"
scripts end up driving the test builds using the CMake that was used to
configure CMake's build tree, not the one that was just built and should
be tested.  Also they don't select the generator properly so will only work
on Unix-like systems.

I don't think you need to create a whole new build tree for every test.
You can do all the test try-compiles right in the main test CMakeLists.txt
file, just with different result cache variable names"

  foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
    set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
    check_symbol_exists(...)
  endforeach()

In order to test things like -O3, just add them temporarily to the
CMAKE_C_FLAGS or CMAKE_CXX_FLAGS variables.

Finally, I'd like to tweak the first commit message slightly:

 > CheckSymbolExists: try to force the compiler to keep the referenced symbol

s/try to//

 > previous version was not really using this. This lead to symbols that are

s/lead to/leads to/

Thanks,
-Brad



More information about the cmake-developers mailing list