forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
109 lines (90 loc) · 3.53 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(Caffe2 CXX C)
# TODO(bwasti): versioning
# We want CMake to GLOB everything every time.
execute_process(COMMAND find "${PROJECT_SOURCE_DIR}" -name "CMakeLists.txt" -exec touch {} \;)
# Useful functions.
function (exclude OUTPUT INPUT)
set(EXCLUDES ${ARGN})
foreach(EXCLUDE ${EXCLUDES})
list(REMOVE_ITEM INPUT "${EXCLUDE}")
endforeach()
set(${OUTPUT} ${INPUT} PARENT_SCOPE)
endfunction(exclude)
function (prepend OUTPUT PREPEND)
set(OUT "")
foreach(ITEM ${ARGN})
list(APPEND OUT "${PREPEND}${ITEM}")
endforeach()
set(${OUTPUT} ${OUT} PARENT_SCOPE)
endfunction(prepend)
# ---[ CMake scripts + modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
# External projects
include(ExternalProject)
include(cmake/Utils.cmake)
# options
option(USE_NERVANA_GPU "Use Nervana GPU backend" OFF)
option(USE_GLOG "Use GLOG" ON)
option(USE_GFLAGS "Use GFLAGS" ON)
option(USE_LMDB "Use LMDB" ON)
option(USE_LEVELDB "Use LMDB" ON)
option(USE_OPENCV "Use openCV" ON)
option(USE_ZMQ "Use ZMQ" OFF)
option(USE_ROCKSDB "Use RocksDB" OFF)
option(USE_MPI "Use MPI" OFF)
option(BUILD_SHARED_LIBS "Build libcaffe2.so" ON)
option(USE_SYSTEM_PROTOBUF "Use system-provided protobuf" ON)
# ---[ Dependencies
include(cmake/Dependencies.cmake)
# ---[ Set link flag, handle additional deps for gcc 5.x
if(BUILD_SHARED_LIBS)
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0.0)
message(STATUS "GCC ${CMAKE_CXX_COMPILER_VERSION}: Adding gcc and gcc_s libs to link line")
set(Caffe2_LINK Caffe2_CPU Caffe_PROTO Caffe2_PROTO gcc_s gcc)
else()
set(Caffe2_LINK Caffe2_CPU Caffe_PROTO Caffe2_PROTO)
endif()
else()
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
set(Caffe2_LINK -Wl,--whole-archive Caffe2_CPU Caffe_PROTO Caffe2_PROTO gcc_s gcc -Wl,--no-whole-archive)
else()
set(Caffe2_LINK -Wl,--whole-archive Caffe2_CPU Caffe_PROTO Caffe2_PROTO -Wl,--no-whole-archive)
endif()
endif()
# ---[ Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "binaries")
# ---[ Third party builds.
include_directories(${CMAKE_SOURCE_DIR})
# ---[ Old caffe protobuf.
add_subdirectory(caffe/proto)
# ---[ Main build
add_subdirectory(caffe2)
# ---[ Copy all python files to build directory
# ---[ Generate and create all needed __init__.py files as they aren't present in source tree
set(Caffe2_INIT_PY
${CMAKE_BINARY_DIR}/caffe2/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/static/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/static/css/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/templates/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/__init__.py
${CMAKE_BINARY_DIR}/caffe2/proto/__init__.py
${CMAKE_BINARY_DIR}/caffe/__init__.py
${CMAKE_BINARY_DIR}/caffe/proto/__init__.py
)
foreach(init ${Caffe2_INIT_PY})
# create each __init__.py file in build directory
file(WRITE ${init} "")
endforeach()
# Copy the files
message(STATUS ${CMAKE_BINARY_DIR})
# Pick up static python files
install(DIRECTORY ${CMAKE_SOURCE_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
# Caffe proto files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
# Caffe2 proto files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")