Skip to content

Choice of CXX standard

Alexander Gaenko edited this page Mar 29, 2018 · 1 revision

Choice of C++ standard

Since version 2.1.0, the new CMake flag ALPS_CXX_STD allows to choose C++ standard to compile ALPSCore with. This flag can be set to either c++03, c++11, c++14 or custom (e.g. -DALPS_CXX_STD=c++11). The flag defaults to c++03 for version 2.1.0, and to c++11 since version 2.1.1 (also, compilation with c++03 is no more supported since 2.1.1). If a compiler is "known" to your version of CMake, CMake will set appropriate compiler flags automatically. (You can see the flags that are actually passed to the compiler by setting -DCMAKE_VERBOSE_MAKEFILE=ON when configuring the project or by running make VERBOSE=1 when building it.)

If CMake failed to set an appropriate flag (most likely because your version of CMake does not know how to deal with this particular compiler), you can set a compilation flag manually as -DALPS_CXX_STD=custom -DCMAKE_CXX_FLAGS='-std=c++14'. Currently, CMake reportedly handles GCC and clang well, but has problems with Intel C++.

If ALPS_CXX_STD was not set to custom, the compilation flag set by CMake (e.g. -std=c++11) will automatically propagate to the build of your code. In these cases, you should not set these flags manually in building your code. However, you can override the language standard to compile your code with, by setting CMake variable ALPS_FORCE_CXX_STD to c++11, c++14 or custom (e.g., -DALPS_FORCE_CXX_STD=custom).

If ALPS_CXX_STD was set to custom (or you choose to set ALPS_FORCE_CXX_STD to custom for your project), you have to set the C++ standard to compile your code with via compilation flags, by setting CMAKE_CXX_FLAGS to an appropriate value (e.g., -DCMAKE_CXX_FLAGS='-std=c++14').