doc update
[jacinto-ai/caffe-jacinto.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.4.0)
2 if(POLICY CMP0046)
3   cmake_policy(SET CMP0046 NEW)
4 endif()
5 if(POLICY CMP0054)
6   cmake_policy(SET CMP0054 NEW)
7 endif()
9 # ---[ Caffe project
10 project(Caffe C CXX)
12 # ---[ Caffe version
13 set(CAFFE_TARGET_VERSION "0.17.0")
14 set(CAFFE_TARGET_SOVERSION "0.17")
15 add_definitions(-DCAFFE_VERSION=${CAFFE_TARGET_VERSION})
17 # Skip `typedef __half half;`
18 add_definitions(-DCUDA_NO_HALF=1)
20 # ---[ Using cmake scripts and modules
21 list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
23 include(ExternalProject)
25 include(cmake/Utils.cmake)
26 include(cmake/Targets.cmake)
27 include(cmake/Misc.cmake)
28 include(cmake/Summary.cmake)
29 include(cmake/ConfigGen.cmake)
31 # ---[ Options
32 caffe_option(USE_CUDNN "Build Caffe with cuDNN library support" ON)
34 # USE_NCCL: Build Caffe with NCCL Library support
35 # Regular ON/OFF option doesn't work here because we need to recognize 3 states:
36 # 1. User didn't set USE_NCCL option =>
37 #   1.1 We *quietly* try to find it and use if found; do nothing otherwise.
38 # 2. User explicitly set USE_NCCL=ON option =>
39 #   1.1 We try to find it with *required* option, thus CMake fails if not found.
40 # 3. User explicitly set USE_NCCL=OFF option => we do nothing.
41 set(USE_NCCL "NONE" CACHE STRING "Link Caffe with NCCL Library for Multi-GPU support")
42 if(USE_NCCL STREQUAL "NONE")
43   set(USE_NCCL_SET OFF)
44 else()
45   set(USE_NCCL_SET ON)
46 endif()
48 caffe_option(BUILD_SHARED_LIBS "Build shared libraries" ON)
49 caffe_option(BUILD_python "Build Python wrapper" ON)
50 set(python_version "2" CACHE STRING "Specify which Python version to use")
51 caffe_option(BUILD_matlab "Build Matlab wrapper" OFF IF UNIX OR APPLE)
52 caffe_option(BUILD_docs   "Build documentation" ON IF UNIX OR APPLE)
53 caffe_option(BUILD_python_layer "Build the Caffe Python layer" ON)
54 caffe_option(USE_OPENCV "Build with OpenCV support" ON)
55 caffe_option(USE_LEVELDB "Build with levelDB" ON)
56 caffe_option(USE_LMDB "Build with lmdb" ON)
57 caffe_option(TEST_FP16 "Build Caffe Tests with 16 bit mode included" OFF)
58 caffe_option(NO_NVML "Build Caffe Tests without NVML (i.e. no CPU affinity)" OFF)
60 if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^aarch")
61   # Tegra
62   set(NO_NVML ON)
63 endif()
65 # ---[ Dependencies
66 include(cmake/Dependencies.cmake)
68 # ---[ Flags
69 if(UNIX OR APPLE)
70   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
71 endif()
73 # The flag USE_OPENCV is not getting set automatically. Set it explicitly.
74 if (USE_OPENCV)
75   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_OPENCV")
76 endif()
78 caffe_set_caffe_link()
80 if(USE_libstdcpp)
81   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
82   message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
83 endif()
85 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
87 add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)
89 # ---[ Warnings
90 caffe_warnings_disable(CMAKE_CXX_FLAGS -Wno-sign-compare -Wno-uninitialized)
92 # ---[ Config generation
93 configure_file(cmake/Templates/caffe_config.h.in "${PROJECT_BINARY_DIR}/caffe_config.h")
95 # ---[ Includes
96 set(Caffe_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
97 set(THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/3rdparty)
98 include_directories(${Caffe_INCLUDE_DIR} ${PROJECT_BINARY_DIR} ${THIRDPARTY_DIR})
99 include_directories(BEFORE src) # This is needed for gtest.
101 # ---[ Subdirectories
102 add_subdirectory(src/gtest)
103 add_subdirectory(src/caffe)
104 add_subdirectory(tools)
105 add_subdirectory(examples)
106 add_subdirectory(python)
107 add_subdirectory(matlab)
108 add_subdirectory(docs)
110 # ---[ Linter target
111 add_custom_target(lint COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/lint.cmake)
113 # ---[ pytest target
114 if(BUILD_python)
115   add_custom_target(pytest COMMAND python${python_version} -m unittest discover -s caffe/test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python )
116   add_dependencies(pytest pycaffe)
117 endif()
119 # ---[ Configuration summary
120 caffe_print_configuration_summary()
122 # ---[ Export configs generation
123 caffe_generate_export_configs()