Feature #1790

Semi-automatic select correct STL version for C++11

Added by Roland Schulz over 5 years ago. Updated over 4 years ago.

core library
Target version:


At least for Intel and Clang it is cumbersome to select the STL version used. As far as I can see cmake currently doesn't have any build-in feature to specify the STL. I suggest we do the following:

  • Detect that the compiler has sufficient C++11 support and is in the list of compilers which doesn't provide its own STL (we can start with Intel + clang)
  • Check whether the STL used by default is sufficient (e.g. Intel uses the first gcc in the path) and supported by the compiler
  • If not check whether a different GCC version is available (using gcc-4.x and gcc both in the default path and in CMAKE_PREFIX_PATH) or let the user specify the gcc path using GMX_GCC_PATH=
  • Set the STL with the compiler specific flags (-gcc-name, -gcc-toolchain) based on the GCC path discovered or provided.

Associated revisions

Revision 4ce2aa50 (diff)
Added by Mark Abraham over 4 years ago

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

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


#1 Updated by Erik Lindahl almost 5 years ago

  • Tracker changed from Bug to Feature
  • Priority changed from Normal to Low

Changing to feature since we have never claimed to do anything except for simply use the version of the STL the compiler uses by default.

Nice if somebody wants to work on, but not a blocker for any release.

#2 Updated by Gerrit Code Review Bot almost 5 years ago

Gerrit received a related patchset '9' for Issue #1790.
Uploader: Mark Abraham ()
Change-Id: Ieef3b47de5c1a00a203baa1b34ebf70535cf5ff0
Gerrit URL:

#3 Updated by Mark Abraham over 4 years ago

  • Category set to core library
  • Status changed from New to Closed
  • Assignee set to Mark Abraham
  • Target version set to 2016

I think this is done - there's a check that the standard library is sufficient (but we will probably find things to add to it, as time passes), and a CMake interface to specify which standard library should be used by compilers that don't (always) provide their own (Intel, LLVM).

Also available in: Atom PDF