diff --git a/dlib/dnn/test_for_cpp11/CMakeLists.txt b/dlib/dnn/test_for_cpp11/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8e6fb96c0aaa06350f2ea328d5f1a2af2cbcaca8 --- /dev/null +++ b/dlib/dnn/test_for_cpp11/CMakeLists.txt @@ -0,0 +1,5 @@ + +cmake_minimum_required(VERSION 2.8.4) +project(cpp11_test) + +add_library(cpp11_test STATIC cpp11_test.cpp ) diff --git a/dlib/dnn/test_for_cpp11/cpp11_test.cpp b/dlib/dnn/test_for_cpp11/cpp11_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e11baacb70dfc8523ef990ba294e9d9a2cef75a5 --- /dev/null +++ b/dlib/dnn/test_for_cpp11/cpp11_test.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2015 Davis E. King (davis@dlib.net) +// License: Boost Software License See LICENSE.txt for the full license. + +#include <memory> +#include <iostream> + +using namespace std; + +class testme +{ +public: + + testme(testme&&) = default; + testme(const testme&) = delete; + + void dostuff() + { + auto x = 4; + + decltype(x) asdf = 9; + + auto f = [](){ cout << "in a lambda!" << endl; }; + f(); + } + + template <typename ...T> + void variadic_template( + T&& ...args + ) + { + } + + std::shared_ptr<int> asdf; +}; + +// ------------------------------------------------------------------------------------ + diff --git a/dlib/use_cpp_11.cmake b/dlib/use_cpp_11.cmake index 4fff7503f06f8991a779abd858a2b3225d9d1c07..3aad697084951a8911158eff529fe0f0e560ad23 100644 --- a/dlib/use_cpp_11.cmake +++ b/dlib/use_cpp_11.cmake @@ -5,10 +5,17 @@ cmake_minimum_required(VERSION 2.8.4) # Don't rerun this script if its already been executed. -if (COMPILER_CAN_DO_CPP_11) +if (DEFINED COMPILER_CAN_DO_CPP_11) return() endif() +if (POLICY CMP0054) + cmake_policy(SET CMP0054 NEW) +endif() + +# Set to false unless we find out otherwise in the code below. +set(COMPILER_CAN_DO_CPP_11 0) + # Determine the path to dlib. string(REGEX REPLACE "use_cpp_11.cmake$" "" dlib_path ${CMAKE_CURRENT_LIST_FILE}) include(${dlib_path}/add_global_compiler_switch.cmake) @@ -33,6 +40,17 @@ if (CMAKE_VERSION VERSION_LESS "3.1") add_global_compiler_switch("-std=c++11") set(COMPILER_CAN_DO_CPP_11 1) endif() + else() + # Since we don't know what compiler this is ust try to build a c++11 project and see if it compiles. + message(STATUS "Building a C++11 test project to see if your compiler supports C++11") + try_compile(test_for_cpp11_worked ${PROJECT_BINARY_DIR}/cpp11_test_build + ${dlib_path}/dnn/test_for_cpp11 cpp11_test) + if (test_for_cpp11_worked) + message(STATUS "C++11 activated.") + set(COMPILER_CAN_DO_CPP_11 1) + else() + message(STATUS "*** Your compiler failed to build a C++11 project, so dlib won't use C++11 features.***") + endif() endif() else() # Set a flag if the compiler you are using is capable of providing C++11 features.