Commit 914deffc authored by Davis King's avatar Davis King

Made cmake turn on C++11 automatically. Also disable trying to use CUDA if

C++11 isn't available.
parent edf0310a
...@@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 2.8.4) ...@@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 2.8.4)
# default to a Release build (except if CMAKE_BUILD_TYPE is set) # default to a Release build (except if CMAKE_BUILD_TYPE is set)
include(release_build_by_default) include(release_build_by_default)
include(use_cpp_11.cmake)
project(dlib) project(dlib)
...@@ -395,14 +396,19 @@ if (NOT TARGET dlib) ...@@ -395,14 +396,19 @@ if (NOT TARGET dlib)
mark_as_advanced(cudnn cudnn_include) mark_as_advanced(cudnn cudnn_include)
endif() endif()
if (CUDA_FOUND AND cudnn AND cudnn_include) if (CUDA_FOUND AND cudnn AND cudnn_include AND COMPILER_CAN_DO_CPP_11)
message(STATUS "Found cuDNN: " ${cudnn}) message(STATUS "Found cuDNN: " ${cudnn})
set(source_files ${source_files} dnn/cuda.cu ) set(source_files ${source_files} dnn/cuda.cu )
set(dlib_needed_libraries ${dlib_needed_libraries} ${CUDA_CUBLAS_LIBRARIES} ${cudnn}) set(dlib_needed_libraries ${dlib_needed_libraries} ${CUDA_CUBLAS_LIBRARIES} ${cudnn})
include_directories(${cudnn_include}) include_directories(${cudnn_include})
else() else()
set(DLIB_USE_CUDA OFF CACHE STRING ${DLIB_USE_BLAS_STR} FORCE ) set(DLIB_USE_CUDA OFF CACHE STRING ${DLIB_USE_BLAS_STR} FORCE )
message(STATUS "cuDNN NOT FOUND. DLIB WILL NOT USE CUDA") if (NOT cudnn OR NOT cudnn_include)
message(STATUS "cuDNN NOT FOUND. DLIB WILL NOT USE CUDA.")
endif()
if (NOT COMPILER_CAN_DO_CPP_11)
message(STATUS "Dlib CUDA support requires C++11 but your compiler doesn't support it.")
endif()
endif() endif()
endif() endif()
......
...@@ -14,6 +14,7 @@ endif() ...@@ -14,6 +14,7 @@ endif()
# Determine the path to dlib. # Determine the path to dlib.
string(REGEX REPLACE "cmake$" "" dlib_path ${CMAKE_CURRENT_LIST_FILE}) string(REGEX REPLACE "cmake$" "" dlib_path ${CMAKE_CURRENT_LIST_FILE})
include(${dlib_path}/add_global_compiler_switch.cmake) include(${dlib_path}/add_global_compiler_switch.cmake)
include(${dlib_path}/use_cpp_11.cmake)
if (CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_COMPILER_IS_GNUCXX)
# By default, g++ won't warn or error if you forget to return a value in a # By default, g++ won't warn or error if you forget to return a value in a
......
# This script checks if your compiler has C++11 support and enables it if it does.
# Also, it sets the COMPILER_CAN_DO_CPP_11 variable to 1 if it was successful.
cmake_minimum_required(VERSION 2.8.4)
# Don't rerun this script if its already been executed.
if (COMPILER_CAN_DO_CPP_11)
return()
endif()
# 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)
# 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")
if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)
message(STATUS "C++11 activated.")
add_global_compiler_switch("-std=gnu++11")
set(COMPILER_CAN_DO_CPP_11 1)
elseif(GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
message(WARNING "C++0x activated.")
add_global_compiler_switch("-std=gnu++0x")
set(COMPILER_CAN_DO_CPP_11 1)
endif()
endif()
else()
# Set a flag if the compiler you are using is capable of providing C++11 features.
if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_rvalue_references;" AND
";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_variadic_templates;" AND
";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_lambdas;" AND
";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_auto_type;")
set(COMPILER_CAN_DO_CPP_11 1)
# Set which standard to use unless someone has already set it to something
# newer.
if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11)
set(CMAKE_CXX_STANDARD 11)
message(STATUS "C++11 activated.")
endif()
endif()
endif()
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