Merge 'release-4-6' into master
[alexxy/gromacs.git] / cmake / gmxTestCXX11.cmake
1 include(CheckCXXSourceCompiles)
2 MACRO(GMX_TEST_CXX11 VARIABLE FLAG)
3     IF(NOT DEFINED HAVE_${VARIABLE})
4         MESSAGE(STATUS "Checking for C++11 support")
5         if(NOT WIN32)
6             set(CXX11_FLAG "-std=c++0x")
7         else()
8             set(CXX11_FLAG "/Qstd=c++0x")
9         endif()
10         CHECK_CXX_COMPILER_FLAG("${CXX11_FLAG}" CXXFLAG_STD_CXX0X)
11         if(NOT CXXFLAG_STD_CXX0X)
12             set(CXX11_FLAG "")
13         endif()
14         set(CMAKE_REQUIRED_DEFINITIONS "${CXX11_FLAG}")
15         check_cxx_source_compiles(
16 "#include <vector>
17 #include <memory>
18 #include <utility>
19 struct A {
20   A(int *i=NULL) : p(i) {} ;
21   std::unique_ptr<int> p;
22 };
23 int main() {
24   typedef std::unique_ptr<int> intPointer;
25   intPointer p(new int(10));
26   std::vector<intPointer> v;
27   v.push_back(std::move(p));
28   std::vector<A> v2;
29   v2.push_back(A());  //requires default move constructor
30   v2.push_back(A(new int(5))); //detects bug in ICC
31 }" HAVE_${VARIABLE})
32         set(CMAKE_REQUIRED_DEFINITIONS "")
33         if(HAVE_${VARIABLE})
34             set(${VARIABLE} 1 CACHE INTERNAL "Result of C++11 support test" FORCE)
35             set(${FLAG} ${CXX11_FLAG} CACHE INTERNAL "Compiler flag for C++11 support" FORCE)
36             MESSAGE(STATUS "Checking for C++11 support - yes")
37         else()
38             set(${VARIABLE} 0 CACHE INTERNAL "Result of C++11 support test" FORCE)
39             set(${FLAG} "" CACHE INTERNAL "Compiler flag for C++11 support" FORCE)
40             MESSAGE(STATUS "Checking for C++11 support - no")
41         endif()
42     ENDIF(NOT DEFINED HAVE_${VARIABLE})
43 ENDMACRO()