mirror of https://github.com/davisking/dlib.git
parent
4de26f1441
commit
29288e5d89
@ -1,5 +1,5 @@
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
cmake_minimum_required(VERSION 3.8.0)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR} dlib_build)
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
message(WARNING "add_global_compiler_switch() is deprecated. Use target_compile_options() instead")
|
||||
|
||||
# Make macros that can add compiler switches to the entire project. Not just
|
||||
# to the current cmake folder being built.
|
||||
macro ( add_global_compiler_switch switch_name )
|
||||
# If removing the switch would change the flags then it's already present
|
||||
# and we don't need to do anything.
|
||||
string(REPLACE "${switch_name}" "" tempstr "${CMAKE_CXX_FLAGS}")
|
||||
if ("${CMAKE_CXX_FLAGS}" STREQUAL "${tempstr}" )
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${switch_name}"
|
||||
CACHE STRING "Flags used by the compiler during all C++ builds."
|
||||
FORCE)
|
||||
endif ()
|
||||
endmacro()
|
||||
|
||||
macro ( remove_global_compiler_switch switch_name )
|
||||
string(REPLACE "${switch_name}" "" tempstr "${CMAKE_CXX_FLAGS}")
|
||||
if (NOT "${CMAKE_CXX_FLAGS}" STREQUAL "${tempstr}" )
|
||||
set (CMAKE_CXX_FLAGS "${tempstr}"
|
||||
CACHE STRING "Flags used by the compiler during all C++ builds."
|
||||
FORCE)
|
||||
endif ()
|
||||
endmacro()
|
||||
|
||||
macro (add_global_define def_name)
|
||||
add_global_compiler_switch(-D${def_name})
|
||||
endmacro()
|
||||
|
||||
macro (remove_global_define def_name)
|
||||
remove_global_compiler_switch(-D${def_name})
|
||||
endmacro()
|
@ -1,17 +0,0 @@
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
project(cpp11_test)
|
||||
|
||||
# Try to enable C++11
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||
if(COMPILER_SUPPORTS_CXX11)
|
||||
message(STATUS "C++11 activated.")
|
||||
ADD_DEFINITIONS("-std=c++11")
|
||||
elseif(COMPILER_SUPPORTS_CXX0X)
|
||||
message(STATUS "C++0x activated.")
|
||||
ADD_DEFINITIONS("-std=c++0x")
|
||||
endif()
|
||||
|
||||
add_library(cpp11_test STATIC cpp11_test.cpp )
|
@ -1,53 +0,0 @@
|
||||
// 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;
|
||||
|
||||
|
||||
template <typename T>
|
||||
auto auto_return(T f) -> decltype(f(4)) { return f(4); }
|
||||
|
||||
template <typename T>
|
||||
auto auto_return(T f) -> decltype(f()) { return f(); }
|
||||
|
||||
static int returnint() { return 0; }
|
||||
|
||||
void dostuff()
|
||||
{
|
||||
thread_local int stuff1 = 999;
|
||||
auto x = 4;
|
||||
++stuff1;
|
||||
|
||||
decltype(x) asdf = 9;
|
||||
++asdf;
|
||||
|
||||
auto f = []() { cout << "in a lambda!" << endl; };
|
||||
f();
|
||||
|
||||
auto_return(returnint);
|
||||
}
|
||||
|
||||
template <typename ...T>
|
||||
void variadic_template(
|
||||
T&& ...args
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<int> asdf;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
@ -1,115 +0,0 @@
|
||||
# This script creates a function, enable_cpp11_for_target(), which checks if your
|
||||
# compiler has C++11 support and enables it if it does.
|
||||
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
if (POLICY CMP0054)
|
||||
cmake_policy(SET CMP0054 NEW)
|
||||
endif()
|
||||
|
||||
|
||||
set(_where_is_cmake_utils_dir ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
function(enable_cpp11_for_target target_name)
|
||||
|
||||
|
||||
# Set to false unless we find out otherwise in the code below.
|
||||
set(COMPILER_CAN_DO_CPP_11 0)
|
||||
|
||||
|
||||
|
||||
macro(test_compiler_for_cpp11)
|
||||
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
|
||||
${_where_is_cmake_utils_dir}/test_for_cpp11 cpp11_test
|
||||
OUTPUT_VARIABLE cpp11_test_output)
|
||||
if (test_for_cpp11_worked)
|
||||
message(STATUS "C++11 activated.")
|
||||
set(COMPILER_CAN_DO_CPP_11 1)
|
||||
else()
|
||||
set(COMPILER_CAN_DO_CPP_11 0)
|
||||
message(STATUS "********** Your compiler failed to build a C++11 project. C++11 is required to use all parts of dlib! **********")
|
||||
message(STATUS "********** Compiler output: ${cpp11_test_output} **********")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Now turn on the appropriate compiler switch to enable C++11 if you have a
|
||||
# C++11 compiler. In CMake 3.1 there is a simple flag you can set, but earlier
|
||||
# verions of CMake are not so convenient.
|
||||
if (CMAKE_VERSION VERSION_LESS "3.1.2")
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
|
||||
if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
|
||||
message(STATUS "C++11 activated.")
|
||||
target_compile_options(${target_name} PUBLIC "-std=gnu++11")
|
||||
set(COMPILER_CAN_DO_CPP_11 1)
|
||||
endif()
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
execute_process( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
|
||||
string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION ${clang_full_version_string})
|
||||
if (CLANG_VERSION VERSION_GREATER 3.3)
|
||||
message(STATUS "C++11 activated.")
|
||||
target_compile_options(${target_name} PUBLIC "-std=c++11")
|
||||
set(COMPILER_CAN_DO_CPP_11 1)
|
||||
endif()
|
||||
else()
|
||||
# Since we don't know what compiler this is just try to build a c++11 project and see if it compiles.
|
||||
test_compiler_for_cpp11()
|
||||
endif()
|
||||
else()
|
||||
|
||||
# Set a flag if the compiler you are using is capable of providing C++11 features.
|
||||
get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
|
||||
if (";${cxx_features};" MATCHES ";cxx_rvalue_references;" AND
|
||||
";${cxx_features};" MATCHES ";cxx_variadic_templates;" AND
|
||||
";${cxx_features};" MATCHES ";cxx_lambdas;" AND
|
||||
";${cxx_features};" MATCHES ";cxx_defaulted_move_initializers;" AND
|
||||
";${cxx_features};" MATCHES ";cxx_delegating_constructors;" AND
|
||||
";${cxx_features};" MATCHES ";cxx_thread_local;" AND
|
||||
";${cxx_features};" MATCHES ";cxx_constexpr;" AND
|
||||
";${cxx_features};" MATCHES ";cxx_decltype_incomplete_return_types;" AND
|
||||
";${cxx_features};" MATCHES ";cxx_auto_type;")
|
||||
|
||||
set(COMPILER_CAN_DO_CPP_11 1)
|
||||
# Tell cmake that we need C++11 for dlib
|
||||
target_compile_features(${target_name}
|
||||
PUBLIC
|
||||
cxx_rvalue_references
|
||||
cxx_variadic_templates
|
||||
cxx_lambdas
|
||||
cxx_defaulted_move_initializers
|
||||
cxx_delegating_constructors
|
||||
cxx_thread_local
|
||||
cxx_constexpr
|
||||
# cxx_decltype_incomplete_return_types # purposfully commented out because cmake errors out on this when using visual studio and cmake 3.8.0
|
||||
cxx_auto_type
|
||||
)
|
||||
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
# Sometimes clang will lie and report that it supports C++11 when
|
||||
# really it doesn't support thread_local. So check for that.
|
||||
test_compiler_for_cpp11()
|
||||
else()
|
||||
message(STATUS "C++11 activated.")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Always enable whatever partial C++11 support we have, even if it isn't full
|
||||
# support, and just hope for the best.
|
||||
if (NOT COMPILER_CAN_DO_CPP_11)
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||
if(COMPILER_SUPPORTS_CXX11)
|
||||
message(STATUS "C++11 activated (compiler doesn't have full C++11 support).")
|
||||
target_compile_options(${target_name} PUBLIC "-std=c++11")
|
||||
elseif(COMPILER_SUPPORTS_CXX0X)
|
||||
message(STATUS "C++0x activated (compiler doesn't have full C++11 support).")
|
||||
target_compile_options(${target_name} PUBLIC "-std=c++0x")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
Loading…
Reference in new issue