Facilitate linking with libcxx
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 30 Mar 2016 03:38:46 +0000 (05:38 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 10 May 2016 14:18:30 +0000 (16:18 +0200)
commit4ce2aa504d36a646f3b084c871ee0059446144a9
tree2a1612f3603276cfe1b13e2a3f87a98dfc0b68e9
parent85d59d175c1a3850b2843d9636e43f4fd616e356
Facilitate linking with libcxx

Using recent clang static analyzer versions seems to be easier with
libcxx, which we should anyway support for building and testing.

Reworked the testing for C++11 support, since it is sensible to first
test the compiler, and then the standard library. This helps users
diagnose problems. Converted this code to a function (for better
scoping), added some docs, and made the semantics clearer. Added
some explicit testing for other non-library C++11 functionality.

Introduced GMX_STDLIB_CXX_FLAGS, so that all the linked executables
can have their sources compiled with any compiler flag that might be
required. Alternatives like requiring the user to modify
CMAKE_CXX_FLAGS, or adding COMPILE_FLAGS properties to targets didn't
seem great. The latter also triggers clang to issue warnings for
source files that are still C (group kernels and TNG).

Introduced GMX_STDLIB_LIBRARIES, so that linking can proceed
correctly.

For example, the check for C++11 support needs to be passed a library
to link during the try_compile(), and the only reliable way for the
user to do that before this patch was to add the linker flag to
CMAKE_CXX_FLAGS, which then leads to clang warning about the unused
linker flag as it compiles each source file. The GMX_STDLIB_*
mechanisms probably also permit users to build against different
versions of GNU libstdc++, which may be useful on distributions like
CentOS, because CMake has no mechanism at all for this.

Updated the install guide to clarify how to choose a standard library
in the various cases. Updated the guide for using GROMACS as a library,
and the template README.

Fixed issue where the template did not have C++11 compiler flags
propagated properly. The template now builds correctly, via both
Makefile.pkg and cmake, both with normal default libstdc++ and libc++
selected via this mechanism and propagated to the installed build
system for the template.

Fixed issue where SIMD suggestion would produce a garbage suggestion
when the linking failed and OUTPUT_SIMD was left unset.

Refs #1745,#1790

Change-Id: Ieef3b47de5c1a00a203baa1b34ebf70535cf5ff0
15 files changed:
CMakeLists.txt
cmake/gmxDetectSimd.cmake
cmake/gmxTestCXX11.cmake
docs/doxygen/user/usinglibrary.md
docs/install-guide/index.rst
share/template/CMakeLists.txt
share/template/CMakeLists.txt.template
share/template/README
src/gromacs/CMakeLists.txt
src/gromacs/InstallLibInfo.cmake
src/gromacs/gromacs-config.cmake.cmakein
src/gromacs/libgromacs.pc.cmakein
src/gromacs/trajectoryanalysis/tests/CMakeLists.txt
src/programs/CMakeLists.txt
src/testutils/TestMacros.cmake