CMakeLists.txt 3.07 KB
Newer Older
1

2
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
3
4
5
6
7
8
9
10
11
12
13

if (WIN32 AND NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio") 
   message(FATAL_ERROR "\n"
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
      "You must use Visual Studio to build a python extension on windows. If you "
      "are getting this error it means you have not installed Visual C++.  Note that "
      "there are many flavors of Visual Studio, like Visual Studio for C\# development. " 
      "You need to install Visual Studio for C++. \n"
      "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
endif()

Davis King's avatar
Davis King committed
14
project(dlib_python_bindings)
15

16
17
18
19
20
# Pybind11's cmake scripts enable link time optimization by default.  However,
# it makes linking take a really long time and doesn't seem to substantively
# improve runtime performance.  So we disable LTO here to make building dlib
# faster.
set(PYBIND11_LTO_CXX_FLAGS "")
Davis King's avatar
Davis King committed
21

22
23
24
25
26
27
28
29
30
31

# Avoid cmake warnings about changes in behavior of some Mac OS X path 
# variable we don't care about.
if (POLICY CMP0042)
    cmake_policy(SET CMP0042 NEW)
endif()


# To avoid dll hell, always link everything statically when compiling in
# visual studio.  This way, the resulting library won't depend on a bunch
Davis King's avatar
Davis King committed
32
# of other dll files and can be safely copied to someone else's computer
33
34
35
36
37
# and expected to run.
if (MSVC)
    include(${CMAKE_CURRENT_LIST_DIR}/../../dlib/cmake_utils/tell_visual_studio_to_use_static_runtime.cmake)
endif()

Davis King's avatar
Davis King committed
38
39
add_subdirectory(../../dlib/external/pybind11 pybind11_build)
add_subdirectory(../../dlib dlib_build)
40
41

if (USING_OLD_VISUAL_STUDIO_COMPILER)
Davis King's avatar
Davis King committed
42
   message(FATAL_ERROR "You have to use a version of Visual Studio that supports C++11.  As of December 2017, the only versions that have good enough C++11 support to compile the dlib Python API is a fully updated Visual Studio 2015 or a fully updated Visual Studio 2017.  Older versions of either of these compilers have bad C++11 support and will fail to compile the Python extension. ***SO UPDATE YOUR VISUAL STUDIO TO MAKE THIS ERROR GO AWAY***")
43
44
endif()

45

46
47
add_definitions(-DDLIB_VERSION=${DLIB_VERSION})

Davis King's avatar
Davis King committed
48
# Tell cmake to compile all these cpp files into a dlib python module.
49
50
51
set(python_srcs
   src/dlib.cpp
   src/matrix.cpp
52
   src/vector.cpp
53
   src/svm_c_trainer.cpp
54
   src/svm_rank_trainer.cpp
Davis King's avatar
Davis King committed
55
   src/decision_functions.cpp
Davis King's avatar
Davis King committed
56
57
   src/other.cpp
   src/basic.cpp
Davis King's avatar
Davis King committed
58
   src/cca.cpp
59
   src/sequence_segmenter.cpp
60
   src/svm_struct.cpp
61
   src/image.cpp
62
   src/image2.cpp
63
   src/image3.cpp
64
   src/image4.cpp
65
   src/rectangles.cpp
66
   src/object_detection.cpp
67
   src/shape_predictor.cpp
68
   src/correlation_tracker.cpp
69
   src/face_recognition.cpp
70
   src/cnn_face_detector.cpp
71
   src/global_optimization.cpp
72
   src/image_dataset_metadata.cpp
73
   src/numpy_returns.cpp
74
   src/line.cpp
75
76
77
78
79
)

# Only add the GUI module if requested
if(NOT ${DLIB_NO_GUI_SUPPORT})
   list(APPEND python_srcs src/gui.cpp)
Davis King's avatar
Davis King committed
80
endif()
81

82
83
pybind11_add_module(_dlib_pybind11 ${python_srcs})
target_link_libraries(_dlib_pybind11 PRIVATE dlib::dlib)
84

85
configure_file(${PROJECT_SOURCE_DIR}/dlib/__init__.py.in ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/dlib/__init__.py)