Commit 2c639d3a authored by Davis King's avatar Davis King

Made the cmake test for C++11 support try to compile a C++11 project if

we don't know what compiler we are dealing with.  If the test compile works
then we assume we have C++11.
parent 7c991b18
cmake_minimum_required(VERSION 2.8.4)
project(cpp11_test)
add_library(cpp11_test STATIC cpp11_test.cpp )
// 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;
};
// ------------------------------------------------------------------------------------
...@@ -5,10 +5,17 @@ ...@@ -5,10 +5,17 @@
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.4)
# Don't rerun this script if its already been executed. # Don't rerun this script if its already been executed.
if (COMPILER_CAN_DO_CPP_11) if (DEFINED COMPILER_CAN_DO_CPP_11)
return() return()
endif() 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. # Determine the path to dlib.
string(REGEX REPLACE "use_cpp_11.cmake$" "" dlib_path ${CMAKE_CURRENT_LIST_FILE}) string(REGEX REPLACE "use_cpp_11.cmake$" "" dlib_path ${CMAKE_CURRENT_LIST_FILE})
include(${dlib_path}/add_global_compiler_switch.cmake) include(${dlib_path}/add_global_compiler_switch.cmake)
...@@ -33,6 +40,17 @@ if (CMAKE_VERSION VERSION_LESS "3.1") ...@@ -33,6 +40,17 @@ if (CMAKE_VERSION VERSION_LESS "3.1")
add_global_compiler_switch("-std=c++11") add_global_compiler_switch("-std=c++11")
set(COMPILER_CAN_DO_CPP_11 1) set(COMPILER_CAN_DO_CPP_11 1)
endif() 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() endif()
else() else()
# Set a flag if the compiler you are using is capable of providing C++11 features. # Set a flag if the compiler you are using is capable of providing C++11 features.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment