include(gmxDetectTargetArchitecture)
gmx_detect_target_architecture()
+# Permit the user to specify a particular standard library, e.g. compiling
+# with "-stdlib=libc++" and linking with "-lc++abi -lc++" to get clang's libcxx.
+set(GMX_STDLIB_CXX_FLAGS "" CACHE STRING "Compiler flag for a C++ standard library flavour")
+set(GMX_STDLIB_LIBRARIES "" CACHE STRING "Linker libraries for a particular C++ standard library")
+mark_as_advanced(GMX_STDLIB_CXX_FLAGS)
+mark_as_advanced(GMX_STDLIB_LIBRARIES)
########################################################################
# Detect CXX11 support and flags
include(CheckCXXCompilerFlag)
# This must come early, since some of our configuration flag tests
-# depend on being able to compile C++11 source files
+# depend on being able to compile C++11 source files.
include(gmxTestCXX11)
-gmx_test_cxx11(GMX_CXX11_SUPPORTED GMX_CXX11_FLAGS)
-if(NOT GMX_CXX11_SUPPORTED)
-message(FATAL_ERROR "This version of GROMACS requires C++11. Please use a newer compiler or use the GROMACS 5.1.x release. Note it might be sufficient to instruct the compiler to use a newer STL version. See the installation guide for details.")
-endif()
+gmx_test_cxx11(GMX_CXX11_FLAGS GMX_STDLIB_CXX_FLAGS GMX_STDLIB_LIBRARIES)
-# Make sure all tests are run in C++11 mode
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GMX_CXX11_FLAGS}")
+# Make sure all C++ code will be compiled in C++11 mode, with the
+# expected standard library.
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GMX_CXX11_FLAGS} ${GMX_STDLIB_CXX_FLAGS}")
########################################################################
# User input options #
message(STATUS "Detecting best SIMD instructions for this CPU")
# Get CPU SIMD properties information
- set(_compile_definitions "${GCC_INLINE_ASM_DEFINE} -I${CMAKE_SOURCE_DIR}/src -DGMX_CPUINFO_STANDALONE")
+ set(_compile_definitions "${GCC_INLINE_ASM_DEFINE} -I${CMAKE_SOURCE_DIR}/src -DGMX_CPUINFO_STANDALONE ${GMX_STDLIB_CXX_FLAGS}")
# We need to execute the binary, so this only works if not cross-compiling.
# However, note that we are NOT limited to x86.
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp
COMPILE_DEFINITIONS ${_compile_definitions}
+ LINK_LIBRARIES ${GMX_STDLIB_LIBRARIES}
RUN_OUTPUT_VARIABLE OUTPUT_TMP
COMPILE_OUTPUT_VARIABLE GMX_CPUINFO_COMPILE_OUTPUT
ARGS "-features")
set(OUTPUT_TMP "None")
endif(NOT GMX_CPUINFO_COMPILED)
+ set(OUTPUT_SIMD "None")
if(GMX_TARGET_X86)
if(OUTPUT_TMP MATCHES " avx512er ")
set(OUTPUT_SIMD "AVX_512_KNL")
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
+# Copyright (c) 2012,2013,2014,2015,2016, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
# the research papers on the package. Check out http://www.gromacs.org.
include(CheckCXXSourceCompiles)
-MACRO(GMX_TEST_CXX11 VARIABLE FLAG)
+
+# Check whether both a suitable C++11-compatible compiler and standard
+# library is available, and give a fatal error if not.
+#
+# Any required compiler flag for C++11 support is returned in
+# ${FLAG}. The other parameters are only inputs, naming variables that
+# contain flags that may have been detected, or set by the user.
+function(GMX_TEST_CXX11 CXX11_CXX_FLAG_NAME STDLIB_CXX_FLAG_NAME STDLIB_LIBRARIES_NAME)
+
+ # First check that the compiler is OK, and find the appropriate flag.
+
if(WIN32 AND NOT MINGW)
- set(CXX11_FLAG "/Qstd=c++0x")
+ set(CXX11_CXX_FLAG "/Qstd=c++0x")
elseif(CYGWIN)
- set(CXX11_FLAG "-std=gnu++0x") #required for strdup
+ set(CXX11_CXX_FLAG "-std=gnu++0x") #required for strdup
else()
- set(CXX11_FLAG "-std=c++0x")
+ set(CXX11_CXX_FLAG "-std=c++0x")
endif()
- CHECK_CXX_COMPILER_FLAG("${CXX11_FLAG}" CXXFLAG_STD_CXX0X)
+ CHECK_CXX_COMPILER_FLAG("${CXX11_CXX_FLAG}" CXXFLAG_STD_CXX0X)
if(NOT CXXFLAG_STD_CXX0X)
- set(CXX11_FLAG "")
+ set(CXX11_CXX_FLAG "")
+ endif()
+ set(CMAKE_REQUIRED_FLAGS "${CXX11_CXX_FLAG}")
+ check_cxx_source_compiles(
+"struct a {
+ explicit operator bool() {return true;}
+ a() {};
+ a(a&&) = default;
+ a(const a&) = delete;
+};
+class b: public a {};
+b f() {
+ return b();
+}
+constexpr int factorial(int n)
+{
+ return n <= 1? 1 : (n * factorial(n - 1));
+}
+void checkRvalueReference(int &&);
+template <typename T> void someFunction();
+extern template void someFunction<int>();
+int main() {
+ double *x = nullptr;
+ int array[5] = { 1, 2, 3, 4, 5 };
+ for (int& x : array)
+ x *= 2;
+}" CXX11_SUPPORTED)
+ if(CXX11_SUPPORTED)
+ set(${CXX11_CXX_FLAG_NAME} ${CXX11_CXX_FLAG} PARENT_SCOPE)
+ else()
+ message(FATAL_ERROR "This version of GROMACS requires a C++11 compiler. Please use a newer compiler or use the GROMACS 5.1.x release. See the installation guide for details.")
endif()
- set(CMAKE_REQUIRED_FLAGS "${CXX11_FLAG}")
+
+ # Now check the standard library is OK
+
+ set(CMAKE_REQUIRED_FLAGS "${CXX11_CXX_FLAG} ${${STDLIB_CXX_FLAG_NAME}}")
+ set(CMAKE_REQUIRED_LIBRARIES "${${STDLIB_LIBRARIES_NAME}}")
check_cxx_source_compiles(
"#include <map>
#include <memory>
#include <utility>
-class a { explicit operator bool() {return true;} };
int main() {
typedef std::unique_ptr<int> intPointer;
intPointer p(new int(10));
std::map<int, std::unique_ptr<int>> m;
m.insert(std::make_pair(5, std::move(p)));
-}" ${VARIABLE})
- set(CMAKE_REQUIRED_FLAGS "")
- if(${VARIABLE})
- set(${FLAG} ${CXX11_FLAG})
+}" CXX11_STDLIB_PRESENT)
+ if(NOT CXX11_STDLIB_PRESENT)
+ message(FATAL_ERROR "This version of GROMACS requires C++11-compatible standard library. Please use a newer compiler, or a newer standard library, or use the GROMACS 5.1.x release. See the installation guide for details.")
endif()
-ENDMACRO()
+endfunction()
compile the \Gromacs headers.</dd>
<dt>`GROMACS_IS_DOUBLE`</dt>
<dd>Whether the found \Gromacs was compiled in double precision.</dd>
+<dt>`GROMACS_CXX_FLAGS`</dt>
+<dd>Required compiler flags, e.g. for compiling in C++11 mode,
+or selecting the standard library flavour.</dd>
</dl>
Declared macros/functions that can be used for checking for correctness of some
good compiler. In practice, many compilers struggle to do a good job
optimizing the |Gromacs| architecture-optimized SIMD kernels.
-C++11 support requires both support in the compiler as well as in the
-C++ library. Multiple compilers do not provide their own library
-but use the system library. It is required to select a library with
-sufficient C++11 support. Both the Intel and clang compiler on Linux use
-the libstdc++ which comes with gcc as the default C++ library. 4.6.1 of
-that library is required. Also the C++ library version has to be
-supported by the compiler. To select the C++ library version use:
-
-* For Intel: ``CXXFLAGS=-gcc-name=/path/to/gcc/binary`` or make sure
+C++11 support requires adequate support in both the compiler and the
+C++ library. The gcc compiler includes its own GNU standard library
+called libstdc++, which just works. Both the Intel and clang compiler
+on Linux use the libstdc++ which comes with gcc as the default C++
+library. Version 4.6.1 of that library is required to have enough
+language support for |Gromacs|, and the C++ library version must be
+supported by the compiler. To select a particular libstdc++ library,
+use:
+
+* For Intel: ``-DGMX_STDLIB_CXX_FLAGS=-gcc-name=/path/to/gcc/binary`` or make sure
that the correct gcc version is first in path (e.g. by loading the gcc
module)
-* For clang: ``CFLAGS=--gcc-toolchain=/path/to/gcc/folder
- CXXFLAGS=--gcc-toolchain=/path/to/gcc/folder``. This folder should
+* For clang: ``-DCMAKE_CXX_FLAGS=--gcc-toolchain=/path/to/gcc/folder``. This folder should
contain ``include/c++``.
-* On Windows with e.g. Intel: at least MSVC 2015 is required. Load the
- enviroment with vcvarsall.bat.
+
+On Windows with e.g. Intel, the MSVC standard library is used, and at
+least MSVC 2015 is required. Load the enviroment with vcvarsall.bat.
+
+To build with clang's libcxx standard library, use
+``-DGMX_STDLIB_CXX_FLAGS=-stdlib=libc++ -DGMX_STDLIB_LIBRARIES='-lc++abi -lc++'``.
For best performance, the |Gromacs| team strongly recommends you get the
most recent version of your preferred compiler for your platform.
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2011,2012,2014, by the GROMACS development team, led by
+# Copyright (c) 2011,2012,2014,2016, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
# the research papers on the package. Check out http://www.gromacs.org.
add_executable(template template.cpp)
-target_link_libraries(template libgromacs ${GMX_EXE_LINKER_FLAGS})
+target_link_libraries(template libgromacs ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
install(FILES CMakeLists.txt.template
DESTINATION ${DATA_INSTALL_DIR}/template
RENAME CMakeLists.txt
endif()
add_executable(template template.cpp)
+set_target_properties(template PROPERTIES
+ COMPILE_FLAGS "${GROMACS_CXX_FLAGS}")
target_link_libraries(template ${GROMACS_LIBRARIES})
$ source /path/to/GMXRC
$ make -f Makefile.pkg
-You will need to make sure that you use a sufficiently similar C++
-compiler and C++ Standard Library as the one that was used for
-compiling GROMACS, preferably the same one.
+You will need to make sure that you use the same C++ compiler
+and C++ Standard Library as the one that was used for compiling
+GROMACS.
See the Doxygen documentation for using GROMACS as a library for
more details about the build system used to build the template, as
well as its limitations (link to the latest development version):
- <http://jenkins.gromacs.org/job/Documentation_Gerrit_Nightly/javadoc/doxygen/html-user/page_usinglibrary.xhtml>
+ <http://jenkins.gromacs.org/job/Documentation_Nightly_master/javadoc/doxygen/html-user/page_usinglibrary.xhtml>
----------------------------------------------------------
${TNG_IO_LIBRARIES}
${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
${XML_LIBRARIES}
- ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS} ${OPENCL_LIBRARIES})
+ ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS} ${OPENCL_LIBRARIES}
+ ${GMX_STDLIB_LIBRARIES})
set_target_properties(libgromacs PROPERTIES
OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
SOVERSION ${LIBRARY_SOVERSION_MAJOR}
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2016, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
set(PKG_CFLAGS "${PKG_CFLAGS} ${_def}")
endforeach()
endif()
- set(PKG_CFLAGS "${PKG_CFLAGS} ${OpenMP_C_FLAGS}")
+ set(PKG_CFLAGS "${PKG_CFLAGS} ${OpenMP_C_FLAGS} ${GMX_CXX11_FLAGS} ${GMX_STDLIB_CXX_FLAGS}")
configure_file(libgromacs.pc.cmakein
libgromacs.pc @ONLY)
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2016, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
list(APPEND GROMACS_INCLUDE_DIRS ${_gmx_root_dir}/${_dir})
endif()
endforeach()
-set(GROMACS_LIBRARIES libgromacs)
+set(GROMACS_LIBRARIES libgromacs @GMX_STDLIB_LIBRARIES@)
set(GROMACS_DEFINITIONS @INSTALLED_HEADER_DEFINITIONS@)
set(GROMACS_IS_DOUBLE @GMX_DOUBLE@)
if (DEFINED GROMACS_SUFFIX AND NOT "${GROMACS_SUFFIX}" STREQUAL "@GMX_LIBS_SUFFIX@")
set(GROMACS_CXX_COMPILER "@GROMACS_CXX_COMPILER@")
set(GROMACS_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
set(GROMACS_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
+set(GROMACS_CXX_FLAGS "@GMX_CXX11_FLAGS@ @GMX_STDLIB_CXX_FLAGS@")
# Produce a message, since find_package() prints nothing on success.
include(FindPackageMessage)
NOT "${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "${GROMACS_${LANG}_COMPILER_ID}" OR
NOT "${CMAKE_${LANG}_COMPILER_VERSION}" STREQUAL "${GROMACS_${LANG}_COMPILER_VERSION}")
message(WARNING
- "You are compiling with a different C++ compiler than what was used "
- "to compile GROMACS. This may lead to linking or runtime problems. "
+ "You are compiling with a different C++ compiler from the one that was "
+ "used to compile GROMACS. This may lead to linking or runtime problems. "
"GROMACS was compiled with "
"${GROMACS_${LANG}_COMPILER_ID} ${GROMACS_${LANG}_COMPILER_VERSION} "
"(${GROMACS_${LANG}_COMPILER}).")
Version: @GMX_VERSION_STRING@
Requires: @PKG_FFT@ @PKG_XML@
Libs.private: @CMAKE_THREAD_LIBS_INIT@ @PKG_DL_LIBS@ @OpenMP_LINKER_FLAGS@
-Libs: -L${libdir} -lgromacs@GMX_LIBS_SUFFIX@ @PKG_FFT_LIBS@ -lm
+Libs: -L${libdir} -lgromacs@GMX_LIBS_SUFFIX@ @PKG_FFT_LIBS@ -lm @GMX_STDLIB_LIBRARIES@
Cflags: @PKG_CFLAGS@
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2010,2012,2013,2014,2015, by the GROMACS development team, led by
+# Copyright (c) 2010,2012,2013,2014,2015,2016, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
$<TARGET_OBJECTS:analysisdata-test-shared>)
add_executable(test_selection ${UNITTEST_TARGET_OPTIONS} test_selection.cpp)
-target_link_libraries(test_selection libgromacs ${GMX_EXE_LINKER_FLAGS})
+target_link_libraries(test_selection libgromacs ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+# Copyright (c) 2010,2011,2012,2013,2014,2015,2016, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
add_library(fahcore $<TARGET_OBJECTS:mdrun_objlib>)
elseif(GMX_BUILD_MDRUN_ONLY)
add_executable(mdrun $<TARGET_OBJECTS:mdrun_objlib> mdrun_main.cpp)
- target_link_libraries(mdrun libgromacs ${GMX_EXE_LINKER_FLAGS})
+ target_link_libraries(mdrun libgromacs ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
set(BINARY_NAME "mdrun${GMX_BINARY_SUFFIX}")
set_target_properties(mdrun PROPERTIES
OUTPUT_NAME "${BINARY_NAME}"
${GMX_MAIN_SOURCES}
$<TARGET_OBJECTS:mdrun_objlib>
$<TARGET_OBJECTS:view_objlib>)
- target_link_libraries(gmx libgromacs ${GMX_EXE_LINKER_FLAGS})
+ target_link_libraries(gmx libgromacs ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
if(GMX_X11)
target_link_libraries(gmx ${X11_LIBRARIES})
endif()
add_executable(${EXENAME} ${UNITTEST_TARGET_OPTIONS}
${_source_files} ${TESTUTILS_DIR}/unittest_main.cpp)
target_link_libraries(${EXENAME}
- ${TESTUTILS_LIBS} libgromacs ${GMOCK_LIBRARIES} ${GMX_EXE_LINKER_FLAGS})
+ ${TESTUTILS_LIBS} libgromacs ${GMOCK_LIBRARIES} ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
set_property(TARGET ${EXENAME}
APPEND PROPERTY COMPILE_FLAGS "${GMOCK_COMPILE_FLAGS}")
set_property(TARGET ${EXENAME}
# GMX_EXTRA_LIBRARIES might be needed for mdrun integration tests at
# some point.
- # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES})
+ # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES} ${GMX_STDLIB_LIBRARIES})
endif()
endfunction ()
# GMX_EXTRA_LIBRARIES might be needed for mdrun integration tests at
# some point.
- # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES})
+ # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES} ${GMX_STDLIB_LIBRARIES})
elseif(GMX_THREAD_MPI)
add_test(NAME ${NAME}
COMMAND
# GMX_EXTRA_LIBRARIES might be needed for mdrun integration tests at
# some point.
- # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES})
+ # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES} ${GMX_STDLIB_LIBRARIES})
endif()
endif()
endfunction ()