]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - CMakeLists.txt
Merge pull request #456 from drnikolaev/caffe-0.16
[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.16.4")
14 set(CAFFE_TARGET_SOVERSION "0.16")
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(CPU_ONLY  "Build Caffe without CUDA support" OFF) # TODO: rename to USE_CUDA
33 caffe_option(USE_CUDNN "Build Caffe with cuDNN library support" ON IF NOT CPU_ONLY)
35 # USE_NCCL: Build Caffe with NCCL Library support
36 # Regular ON/OFF option doesn't work here because we need to recognize 3 states:
37 # 1. User didn't set USE_NCCL option =>
38 #   1.1 If CPU_ONLY is ON we do nothing.
39 #   1.2 If CPU_ONLY is OFF we *quietly* try to find it and use if found; do nothing otherwise.
40 # 2. User explicitly set USE_NCCL=ON option =>
41 #   1.1 If CPU_ONLY is ON we do nothing (it's higher priority).
42 #   2.1 If CPU_ONLY is OFF we try to find it with *required* option, thus CMake fails if not found. 
43 # 3. User explicitly set USE_NCCL=OFF option => we do nothing.
44 SET(USE_NCCL)
45 if(DEFINED USE_NCCL)
46   STRING(TOUPPER "${USE_NCCL}" USE_NCCL)
47 endif()
49 caffe_option(BUILD_SHARED_LIBS "Build shared libraries" ON)
50 caffe_option(BUILD_python "Build Python wrapper" ON)
51 set(python_version "2" CACHE STRING "Specify which Python version to use")
52 caffe_option(BUILD_matlab "Build Matlab wrapper" OFF IF UNIX OR APPLE)
53 caffe_option(BUILD_docs   "Build documentation" ON IF UNIX OR APPLE)
54 caffe_option(BUILD_python_layer "Build the Caffe Python layer" ON)
55 caffe_option(USE_LEVELDB "Build with levelDB" ON)
56 caffe_option(USE_LMDB "Build with lmdb" ON)
57 caffe_option(ALLOW_LMDB_NOLOCK "Allow MDB_NOLOCK when reading LMDB files (only if necessary)" OFF)
58 caffe_option(TEST_FP16 "Build Caffe Tests with 16 bit mode included" OFF)
59 caffe_option(NO_NVML "Build Caffe Tests without NVML (i.e. no CPU affinity)" OFF)
61 if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^aarch")
62   # Tegra
63   set(NO_NVML ON)
64 endif()
66 # ---[ Dependencies
67 include(cmake/Dependencies.cmake)
69 # ---[ Flags
70 if(UNIX OR APPLE)
71   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
72 endif()
74 caffe_set_caffe_link()
76 if(USE_libstdcpp)
77   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
78   message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
79 endif()
81 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
83 add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)
85 # ---[ Warnings
86 caffe_warnings_disable(CMAKE_CXX_FLAGS -Wno-sign-compare -Wno-uninitialized)
88 # ---[ Config generation
89 configure_file(cmake/Templates/caffe_config.h.in "${PROJECT_BINARY_DIR}/caffe_config.h")
91 # ---[ Includes
92 set(Caffe_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
93 set(THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/3rdparty)
94 include_directories(${Caffe_INCLUDE_DIR} ${PROJECT_BINARY_DIR} ${THIRDPARTY_DIR})
95 include_directories(BEFORE src) # This is needed for gtest.
97 # ---[ Subdirectories
98 add_subdirectory(src/gtest)
99 add_subdirectory(src/caffe)
100 add_subdirectory(tools)
101 add_subdirectory(examples)
102 add_subdirectory(python)
103 add_subdirectory(matlab)
104 add_subdirectory(docs)
106 # ---[ Linter target
107 add_custom_target(lint COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/lint.cmake)
109 # ---[ pytest target
110 if(BUILD_python)
111   add_custom_target(pytest COMMAND python${python_version} -m unittest discover -s caffe/test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python )
112   add_dependencies(pytest pycaffe)
113 endif()
115 # ---[ Configuration summary
116 caffe_print_configuration_summary()
118 # ---[ Export configs generation
119 caffe_generate_export_configs()