Fix linking of VTKCoreCppTest by adding a check for linker capabilities

This commit is based on the work of Sankhesh Jhaveri and Bill Hoffman. It
has been adapted to (1) be re-usable by project depending on CTK and
(2) execute the try_compile test only if needed.

It checks whether the linker will be able to resolve all symbols. If the
check fails, another test takes place to make sure the linker is not
lazy-linking. If it is, the flag --no-as-needed is added to
CMAKE_EXE_LINKER_FLAGS.

The link error was:

// ---------------
Linking CXX executable ../../../../../../bin/CTKVisualizationVTKCoreCppTests
/home/jchris/Projects/Slicer-1-SuperBuild-Release-Qt485/VTK-build/bin/libvtkPythonCore.so.5.10.1: undefined reference to `PyNumber_Divmod'
/home/jchris/Projects/Slicer-1-SuperBuild-Release-Qt485/VTK-build/bin/libvtkPythonCore.so.5.10.1: undefined reference to `PyDict_SetItem'
/home/jchris/Projects/Slicer-1-SuperBuild-Release-Qt485/VTK-build/bin/libvtkPythonCore.so.5.10.1: undefined reference to `PyExc_ValueError'
/home/jchris/Projects/Slicer-1-SuperBuild-Release-Qt485/VTK-build/bin/libvtkPythonCore.so.5.10.1: undefined reference to `PyNumber_And'
/home/jchris/Projects/Slicer-1-SuperBuild-Release-Qt485/VTK-build/bin/libvtkPythonCore.so.5.10.1: undefined reference to `PyDict_SetItemString'
/home/jchris/Projects/Slicer-1-SuperBuild-Release-Qt485/VTK-build/bin/libvtkPythonCore.so.5.10.1: undefined reference to `PyNumber_Absolute'
/home/jchris/Projects/Slicer-1-SuperBuild-Release-Qt485/VTK-build/bin/libvtkPythonCore.so.5.10.1: undefined reference to `PyExc_OverflowError'
/home/jchris/Projects/Slicer-1-SuperBuild-Release-Qt485/VTK-build/bin/libvtkPythonCore.so.5.10.1: undefined reference to `PyType_IsSubtype'
[...]
// ---------------

While working on Slicer bug #2321, Sankhesh and Bill figured out the
solution:

"Okay, finally with some awesome help from Bill Hoffman we could figure
out what was the root cause of this problem.

Turns out, the shared library libvtkPythonCore.so uses python symbols
but is not linked to libpython.so [1].
Moreover, the test in question - qSlicerDataModuleWidgetsCxxTest does not
reference any python symbols directly. This makes the linker "not link"
the executable to libpython. However, since libvtkPythonCore depends on
libpython without a direct link between the two, we have to suffer with
this bug. :-(

In essence, if there is a shared library "A" that depends on a shared
library "B" but is not linked directly to it and an executable "C"
depends only on shared library "A", linker fails to link to library "B"
and cannot resolve symbols in "A".

Now, you would expect the linker to resolve the dependency up the
toolchain and link the two shared libraries together. This would have
made it much easier. But, Ubuntu package maintainers decided to add a
linker flag "--as-needed" [2] to the default gcc toolchain starting
Ubuntu 12.04.
There is some discussion on this [3].

[1] https://github.com/Kitware/VTK/blob/v5.10.0/Wrapping/Python/CMakeLists.txt#L50
[2] http://linux.die.net/man/1/ld
[3] http://stackoverflow.com/questions/12693624/references-to-fftw-not-resolved-when-linking-with-as-needed
"
Source: http://na-mic.org/Mantis/view.php?id=2321#c6403

Co-authored-by: Sankhesh Jhaveri <sankhesh.jhaveri@kitware.com>
Co-authored-by: Bill Hoffman <bill.hoffman@kitware.com>
Merge branch 'fix-vtk-core-test-link-error'

* fix-vtk-core-test-link-error:
  Fix linking of VTKCoreCppTest by adding a check for linker capabilities