Commit a62cf03c authored by Davis King's avatar Davis King

Merge branch 'avaucher-modernize_cmake'

parents 272e0c79 67db08f5
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
add_subdirectory(dlib) add_subdirectory(dlib)
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
project(dlib) project(dlib)
# default to a Release build (except if CMAKE_BUILD_TYPE is set) # default to a Release build (except if CMAKE_BUILD_TYPE is set)
...@@ -22,23 +22,10 @@ if(has_parent) ...@@ -22,23 +22,10 @@ if(has_parent)
set(DLIB_VERSION ${VERSION} PARENT_SCOPE) set(DLIB_VERSION ${VERSION} PARENT_SCOPE)
endif() endif()
set(dlib_needed_includes) # Set only because there are old target_link_libraries() statements in the
# This macro sets include directory paths that are needed by dlib and also by # FindCUDA.cmake file that comes with CMake that error out if the new behavior
# applications that include dlib. So the main point of this macro is to set # is used.
# dlib_needed_includes which will get pushed into the parent cmake scope at the cmake_policy(SET CMP0023 OLD)
# end of this CMakeLists.txt file. This way, it is available to users of dlib/cmake.
macro(add_include_directories dir)
include_directories(${dir})
set(dlib_needed_includes ${dlib_needed_includes} ${dir})
endmacro()
# Suppress cmake warnings about changes in new versions.
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
endif()
include(cmake_utils/add_global_compiler_switch.cmake) include(cmake_utils/add_global_compiler_switch.cmake)
...@@ -225,6 +212,7 @@ if (NOT TARGET dlib) ...@@ -225,6 +212,7 @@ if (NOT TARGET dlib)
) )
set(dlib_needed_libraries) set(dlib_needed_libraries)
set(dlib_needed_includes)
if(UNIX) if(UNIX)
set(CMAKE_THREAD_PREFER_PTHREAD ON) set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
...@@ -332,7 +320,7 @@ if (NOT TARGET dlib) ...@@ -332,7 +320,7 @@ if (NOT TARGET dlib)
if (DLIB_GIF_SUPPORT) if (DLIB_GIF_SUPPORT)
find_package(GIF QUIET) find_package(GIF QUIET)
if (GIF_FOUND) if (GIF_FOUND)
add_include_directories(${GIF_INCLUDE_DIR}) set (dlib_needed_includes ${dlib_needed_includes} ${GIF_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${GIF_LIBRARY}) set (dlib_needed_libraries ${dlib_needed_libraries} ${GIF_LIBRARY})
else() else()
set(DLIB_GIF_SUPPORT OFF CACHE STRING ${DLIB_GIF_SUPPORT_STR} FORCE ) set(DLIB_GIF_SUPPORT OFF CACHE STRING ${DLIB_GIF_SUPPORT_STR} FORCE )
...@@ -499,8 +487,8 @@ if (NOT TARGET dlib) ...@@ -499,8 +487,8 @@ if (NOT TARGET dlib)
if (DLIB_USE_MKL_FFT) if (DLIB_USE_MKL_FFT)
if (found_intel_mkl AND found_intel_mkl_headers) if (found_intel_mkl AND found_intel_mkl_headers)
set (dlib_needed_includes ${dlib_needed_includes} ${mkl_include_dir})
set (dlib_needed_libraries ${dlib_needed_libraries} ${mkl_libraries}) set (dlib_needed_libraries ${dlib_needed_libraries} ${mkl_libraries})
add_include_directories(${mkl_include_dir})
else() else()
set(DLIB_USE_MKL_FFT OFF CACHE STRING ${DLIB_USE_MKL_FFT_STR} FORCE ) set(DLIB_USE_MKL_FFT OFF CACHE STRING ${DLIB_USE_MKL_FFT_STR} FORCE )
toggle_preprocessor_switch(DLIB_USE_MKL_FFT) toggle_preprocessor_switch(DLIB_USE_MKL_FFT)
...@@ -615,7 +603,7 @@ if (NOT TARGET dlib) ...@@ -615,7 +603,7 @@ if (NOT TARGET dlib)
find_path(sqlite_path sqlite3.h) find_path(sqlite_path sqlite3.h)
if (sqlite AND sqlite_path) if (sqlite AND sqlite_path)
get_filename_component(sqlite_path2 ${sqlite_path} PATH CACHE) get_filename_component(sqlite_path2 ${sqlite_path} PATH CACHE)
add_include_directories(${sqlite_path2}) set(dlib_needed_includes ${dlib_needed_includes} ${sqlite_path2})
set(dlib_needed_libraries ${dlib_needed_libraries} ${sqlite} ) set(dlib_needed_libraries ${dlib_needed_libraries} ${sqlite} )
else() else()
set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING ${DLIB_LINK_WITH_SQLITE3_STR} FORCE ) set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING ${DLIB_LINK_WITH_SQLITE3_STR} FORCE )
...@@ -630,7 +618,7 @@ if (NOT TARGET dlib) ...@@ -630,7 +618,7 @@ if (NOT TARGET dlib)
# make sure fftw3.h is in the include path # make sure fftw3.h is in the include path
find_path(fftw_path fftw3.h) find_path(fftw_path fftw3.h)
if (fftw AND fftw_path) if (fftw AND fftw_path)
add_include_directories(${fftw_path}) set(dlib_needed_includes ${dlib_needed_includes} ${fftw_path})
set(dlib_needed_libraries ${dlib_needed_libraries} ${fftw} ) set(dlib_needed_libraries ${dlib_needed_libraries} ${fftw} )
else() else()
set(DLIB_USE_FFTW OFF CACHE STRING ${DLIB_USE_FFTW_STR} FORCE ) set(DLIB_USE_FFTW OFF CACHE STRING ${DLIB_USE_FFTW_STR} FORCE )
...@@ -643,11 +631,19 @@ if (NOT TARGET dlib) ...@@ -643,11 +631,19 @@ if (NOT TARGET dlib)
# Tell CMake to build dlib via add_library()/cuda_add_library() # Tell CMake to build dlib via add_library()/cuda_add_library()
if (DLIB_USE_CUDA) if (DLIB_USE_CUDA)
# The old cuda_add_library() command doesn't support CMake's newer dependency
# stuff, so we have to set the include path manually still, which we do here.
include_directories(${dlib_needed_includes})
cuda_add_library(dlib STATIC ${source_files} ) cuda_add_library(dlib STATIC ${source_files} )
else() else()
add_library(dlib STATIC ${source_files} ) add_library(dlib STATIC ${source_files} )
endif() endif()
target_link_libraries(dlib ${dlib_needed_libraries} ) target_include_directories(dlib
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
INTERFACE $<INSTALL_INTERFACE:include>
PUBLIC ${dlib_needed_includes}
)
target_link_libraries(dlib PRIVATE ${dlib_needed_libraries})
if (UNIX AND NOT DLIB_IN_PROJECT_BUILD) if (UNIX AND NOT DLIB_IN_PROJECT_BUILD)
if (DLIB_USE_CUDA) if (DLIB_USE_CUDA)
cuda_add_library(dlib_shared SHARED ${source_files} ) cuda_add_library(dlib_shared SHARED ${source_files} )
...@@ -656,7 +652,12 @@ if (NOT TARGET dlib) ...@@ -656,7 +652,12 @@ if (NOT TARGET dlib)
add_library(dlib_shared SHARED ${source_files} ) add_library(dlib_shared SHARED ${source_files} )
add_dependencies(dlib_shared dlib) add_dependencies(dlib_shared dlib)
endif() endif()
target_link_libraries(dlib_shared ${dlib_needed_libraries} ) target_include_directories(dlib_shared
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
INTERFACE $<INSTALL_INTERFACE:include>
PUBLIC ${dlib_needed_includes}
)
target_link_libraries(dlib_shared PRIVATE ${dlib_needed_libraries})
endif() endif()
endif () ##### end of if NOT DLIB_ISO_CPP_ONLY ########################################################## endif () ##### end of if NOT DLIB_ISO_CPP_ONLY ##########################################################
...@@ -664,6 +665,7 @@ if (NOT TARGET dlib) ...@@ -664,6 +665,7 @@ if (NOT TARGET dlib)
# Allow the unit tests to ask us to compile the all/source.cpp file just to make sure it compiles. # Allow the unit tests to ask us to compile the all/source.cpp file just to make sure it compiles.
if (DLIB_TEST_COMPILE_ALL_SOURCE_CPP) if (DLIB_TEST_COMPILE_ALL_SOURCE_CPP)
ADD_LIBRARY(dlib_all_source_cpp STATIC all/source.cpp) ADD_LIBRARY(dlib_all_source_cpp STATIC all/source.cpp)
target_link_libraries(dlib_all_source_cpp dlib)
endif() endif()
# Install the library # Install the library
...@@ -688,7 +690,7 @@ if (NOT TARGET dlib) ...@@ -688,7 +690,7 @@ if (NOT TARGET dlib)
endif() endif()
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION include/dlib install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION include/dlib
FILES_MATCHING PATTERN "*.h" FILES_MATCHING PATTERN "*.h" PATTERN "*.cmake"
REGEX "${CMAKE_CURRENT_BINARY_DIR}" EXCLUDE) REGEX "${CMAKE_CURRENT_BINARY_DIR}" EXCLUDE)
...@@ -733,9 +735,4 @@ if (NOT TARGET dlib) ...@@ -733,9 +735,4 @@ if (NOT TARGET dlib)
endif() endif()
add_library(dlib::dlib ALIAS dlib)
# put dlib_needed_includes into the parent scope so the dlib/cmake file can use it.
if(has_parent)
set(dlib_needed_includes ${dlib_needed_includes} PARENT_SCOPE)
endif()
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# It will trigger a compilation of dlib *in the project* # It will trigger a compilation of dlib *in the project*
# including it # including it
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
set(DLIB_IN_PROJECT_BUILD true) set(DLIB_IN_PROJECT_BUILD true)
...@@ -93,9 +93,6 @@ elseif (MSVC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # else if using Visu ...@@ -93,9 +93,6 @@ elseif (MSVC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # else if using Visu
endif() endif()
# Add folder containing dlib to the include search path.
INCLUDE_DIRECTORIES(${dlib_path}/..)
# This is really optional, but nice. It will make sure the build mode # This is really optional, but nice. It will make sure the build mode
# created by cmake is always release by default. # created by cmake is always release by default.
include(${dlib_path}/cmake_utils/release_build_by_default) include(${dlib_path}/cmake_utils/release_build_by_default)
...@@ -104,6 +101,5 @@ include(${dlib_path}/cmake_utils/release_build_by_default) ...@@ -104,6 +101,5 @@ include(${dlib_path}/cmake_utils/release_build_by_default)
# Don't add dlib if it's already been added to the cmake project # Don't add dlib if it's already been added to the cmake project
if (NOT TARGET dlib) if (NOT TARGET dlib)
add_subdirectory(${dlib_path} dlib_build) add_subdirectory(${dlib_path} dlib_build)
INCLUDE_DIRECTORIES(${dlib_needed_includes})
endif() endif()
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
# Make macros that can add compiler switches to the entire project. Not just # Make macros that can add compiler switches to the entire project. Not just
# to the current cmake folder being built. # to the current cmake folder being built.
......
...@@ -38,3 +38,5 @@ endif() ...@@ -38,3 +38,5 @@ endif()
find_library(dlib_LIBRARIES dlib HINTS ${dlib_INSTALL_PATH}/lib) find_library(dlib_LIBRARIES dlib HINTS ${dlib_INSTALL_PATH}/lib)
set(dlib_LIBRARIES ${dlib_LIBRARIES} "@dlib_needed_libraries@") set(dlib_LIBRARIES ${dlib_LIBRARIES} "@dlib_needed_libraries@")
set(dlib_LIBS ${dlib_LIBRARIES} "@dlib_needed_libraries@") set(dlib_LIBS ${dlib_LIBRARIES} "@dlib_needed_libraries@")
include(${dlib_INSTALL_PATH}/include/dlib/cmake_utils/use_cpp_11.cmake)
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Including this cmake script into your cmake project will cause visual studio # Including this cmake script into your cmake project will cause visual studio
# to build your project against the static C runtime. # to build your project against the static C runtime.
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
if (POLICY CMP0054) if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW) cmake_policy(SET CMP0054 NEW)
endif() endif()
......
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
project(cpp11_test) project(cpp11_test)
# Try to enable C++11 # Try to enable C++11
......
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
project(cuda_test) project(cuda_test)
include_directories(../../dnn) include_directories(../../dnn)
......
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
project(cudnn_test) project(cudnn_test)
include(../use_cpp_11.cmake) include(../use_cpp_11.cmake)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Also, it sets the COMPILER_CAN_DO_CPP_11 variable to 1 if it was successful. # Also, it sets the COMPILER_CAN_DO_CPP_11 variable to 1 if it was successful.
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
# Don't rerun this script if its already been executed. # Don't rerun this script if its already been executed.
if (DEFINED COMPILER_CAN_DO_CPP_11) if (DEFINED COMPILER_CAN_DO_CPP_11)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
project(cblas) project(cblas)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# information about it at http://www.cmake.org # information about it at http://www.cmake.org
# #
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
# create a variable called target_name and set it to the string "dtest" # create a variable called target_name and set it to the string "dtest"
set (target_name dtest) set (target_name dtest)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# information about it at http://www.cmake.org # information about it at http://www.cmake.org
# #
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
# This variable contains a list of all the tests we are building # This variable contains a list of all the tests we are building
# into the regression test suite. # into the regression test suite.
......
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
add_subdirectory(../../../tools/imglab imglab_build) add_subdirectory(../../../tools/imglab imglab_build)
add_subdirectory(../../../tools/htmlify htmlify_build) add_subdirectory(../../../tools/htmlify htmlify_build)
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
PROJECT(examples) PROJECT(examples)
...@@ -16,7 +16,7 @@ include(../dlib/cmake) ...@@ -16,7 +16,7 @@ include(../dlib/cmake)
# in general you will make programs that const of many .cpp files. # in general you will make programs that const of many .cpp files.
ADD_EXECUTABLE(assignment_learning_ex assignment_learning_ex.cpp) ADD_EXECUTABLE(assignment_learning_ex assignment_learning_ex.cpp)
# Then we tell it to link with dlib. # Then we tell it to link with dlib.
TARGET_LINK_LIBRARIES(assignment_learning_ex dlib) TARGET_LINK_LIBRARIES(assignment_learning_ex dlib::dlib)
...@@ -26,7 +26,7 @@ TARGET_LINK_LIBRARIES(assignment_learning_ex dlib) ...@@ -26,7 +26,7 @@ TARGET_LINK_LIBRARIES(assignment_learning_ex dlib)
# your cmake projects and use the syntax shown above. # your cmake projects and use the syntax shown above.
MACRO(add_example name) MACRO(add_example name)
ADD_EXECUTABLE(${name} ${name}.cpp) ADD_EXECUTABLE(${name} ${name}.cpp)
TARGET_LINK_LIBRARIES(${name} dlib ) TARGET_LINK_LIBRARIES(${name} dlib::dlib )
ENDMACRO() ENDMACRO()
# if an example requires GUI, call this macro to check DLIB_NO_GUI_SUPPORT to include or exclude # if an example requires GUI, call this macro to check DLIB_NO_GUI_SUPPORT to include or exclude
...@@ -154,7 +154,7 @@ else() ...@@ -154,7 +154,7 @@ else()
include_directories(${OpenCV_INCLUDE_DIRS}) include_directories(${OpenCV_INCLUDE_DIRS})
ADD_EXECUTABLE(webcam_face_pose_ex webcam_face_pose_ex.cpp) ADD_EXECUTABLE(webcam_face_pose_ex webcam_face_pose_ex.cpp)
TARGET_LINK_LIBRARIES(webcam_face_pose_ex dlib ${OpenCV_LIBS} ) TARGET_LINK_LIBRARIES(webcam_face_pose_ex dlib::dlib ${OpenCV_LIBS} )
else() else()
message("OpenCV not found, so we won't build the webcam_face_pose_ex example.") message("OpenCV not found, so we won't build the webcam_face_pose_ex example.")
endif() endif()
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# information about it at http://www.cmake.org # information about it at http://www.cmake.org
# #
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
# create a variable called target_name and set it to the string "htmlify" # create a variable called target_name and set it to the string "htmlify"
set (target_name htmlify) set (target_name htmlify)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# information about it at http://www.cmake.org # information about it at http://www.cmake.org
# #
cmake_minimum_required(VERSION 2.8.4) cmake_minimum_required(VERSION 2.8.12)
# create a variable called target_name and set it to the string "imglab" # create a variable called target_name and set it to the string "imglab"
set (target_name imglab) set (target_name imglab)
......
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.4) CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
set(USE_SSE4_INSTRUCTIONS ON CACHE BOOL "Use SSE4 instructions") set(USE_SSE4_INSTRUCTIONS ON CACHE BOOL "Use SSE4 instructions")
......
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