CMakeLists.txt 3.15 KB
Newer Older
1

2
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
3

4
set(USE_SSE4_INSTRUCTIONS ON CACHE BOOL "Use SSE4 instructions")
5

6
7
8
9
10
include(../../dlib/cmake_utils/check_if_avx_instructions_executable_on_host.cmake)
if (AVX_IS_AVAILABLE_ON_HOST)
   set(USE_AVX_INSTRUCTIONS ON CACHE BOOL "Use AVX instructions")
endif()

Davis King's avatar
Davis King committed
11
12
13
# Set this to disable link time optimization. The only reason for
# doing this to make the compile faster which is nice when developing
# new modules.
14
# set(PYBIND11_LTO_CXX_FLAGS "")
Davis King's avatar
Davis King committed
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# 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
# of other dll files and can be safely copied to someone elese's computer
# and expected to run.
if (MSVC)
    include(${CMAKE_CURRENT_LIST_DIR}/../../dlib/cmake_utils/tell_visual_studio_to_use_static_runtime.cmake)
endif()

add_subdirectory(../../dlib/external/pybind11 ./pybind11_build)
33
add_subdirectory(../../dlib ./dlib_build)
34
35

if (USING_OLD_VISUAL_STUDIO_COMPILER)
Davis King's avatar
Davis King committed
36
   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***")
37
38
endif()

39

40
# Test for numpy
Davis King's avatar
Davis King committed
41
42
43
44
find_package(PythonInterp)
if(PYTHONINTERP_FOUND)
   execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import numpy" OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE NUMPYRC)
   if(NUMPYRC EQUAL 1)
45
      message(WARNING "Numpy not found. Functions that return numpy arrays will not work without Numpy installed!")
Davis King's avatar
Davis King committed
46
47
48
49
   else()
      message(STATUS "Found Python with installed numpy package")
   endif()
else()
50
   message(WARNING "Numpy not found. Functions that return numpy arrays will not work without Numpy installed!")
Davis King's avatar
Davis King committed
51
endif()
52

53
54
add_definitions(-DDLIB_VERSION=${DLIB_VERSION})

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

# 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
85
endif()
86

87
88
89
90
pybind11_add_module(dlib_python ${python_srcs})
target_link_libraries(dlib_python PRIVATE dlib::dlib)
# Set the output library name to dlib because that's what setup.py and distutils expects.
set_target_properties(dlib_python PROPERTIES OUTPUT_NAME dlib)
91