Make C++11 test quiet after the first cmake run.
[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   std::unique_ptr<int> p;
21 };
22 int main() {
23   typedef std::unique_ptr<int> intPointer;
24   intPointer p(new int(10));
25   std::vector<intPointer> v;
26   v.push_back(std::move(p));
27   std::vector<A> v2;
28   v2.push_back(A());  //requires default move constructor
29 }" HAVE_${VARIABLE})
30         set(CMAKE_REQUIRED_DEFINITIONS "")
31         if(HAVE_${VARIABLE})
32             set(${VARIABLE} 1 CACHE INTERNAL "Result of C++11 support test" FORCE)
33             set(${FLAG} ${CXX11_FLAG} CACHE INTERNAL "Compiler flag for C++11 support" FORCE)
34             MESSAGE(STATUS "Checking for C++11 support - yes")
35         else()
36             set(${VARIABLE} 0 CACHE INTERNAL "Result of C++11 support test" FORCE)
37             set(${FLAG} "" CACHE INTERNAL "Compiler flag for C++11 support" FORCE)
38             MESSAGE(STATUS "Checking for C++11 support - no")
39         endif()
40     ENDIF(NOT DEFINED HAVE_${VARIABLE})
41 ENDMACRO()