-
Notifications
You must be signed in to change notification settings - Fork 152
/
CMakeLists.txt
148 lines (132 loc) · 5.56 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
if (WIN32 OR APPLE)
set(SKIP_TOOLCHAIN TRUE)
endif()
if (SKIP_TOOLCHAIN)
# skip toolchain so that code insight can work properly
cmake_minimum_required(VERSION 3.0)
project(graphvite LANGUAGES CXX)
include_directories(include)
add_subdirectory(src)
return()
endif()
cmake_minimum_required(VERSION 3.12)
project(graphvite LANGUAGES CXX CUDA)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(FindCUDA)
find_package(Glog)
find_package(GFlags)
find_package(PythonLibsNew REQUIRED)
find_package(pybind11 REQUIRED)
# CUDA_ROOT & CUDA_ARCH
get_filename_component(CUDA_ROOT ${CMAKE_CUDA_COMPILER} DIRECTORY)
get_filename_component(CUDA_ROOT ${CUDA_ROOT} DIRECTORY)
if (NOT ALL_ARCH)
cuda_select_nvcc_arch_flags(CUDA_ARCH Auto)
else()
cuda_select_nvcc_arch_flags(CUDA_ARCH 3.5 5.0 6.0 7.0)
endif()
string(REPLACE ";" " " CUDA_ARCH "${CUDA_ARCH}")
# add externals
include(ExternalProject)
set(EXTERNAL_DIR ${PROJECT_SOURCE_DIR}/external)
if (NOT UPDATE)
set(SKIP_UPDATE TRUE)
else()
set(SKIP_UPDATE FALSE)
endif()
# glog
if (NOT GLOG_FOUND)
message(WARNING "Can't find glog library. It will be installed from git repository.")
ExternalProject_Add(glog
GIT_REPOSITORY https://github.com/google/glog.git
UPDATE_DISCONNECTED ${SKIP_UPDATE}
PREFIX glog
SOURCE_DIR ${EXTERNAL_DIR}/glog
BINARY_DIR ${PROJECT_BINARY_DIR}/glog
INSTALL_DIR ${PROJECT_BINARY_DIR}/glog
CONFIGURE_COMMAND test -e Makefile && exit ||
cd ${EXTERNAL_DIR}/glog && ./autogen.sh && cd - &&
${EXTERNAL_DIR}/glog/configure
BUILD_COMMAND test -e .libs/libglog.a || make -j
INSTALL_COMMAND test -e include/glog/logging.h || make install prefix=${PROJECT_BINARY_DIR}/glog)
include_directories(${PROJECT_BINARY_DIR}/glog/include)
link_directories(${PROJECT_BINARY_DIR}/glog/.libs)
else()
get_filename_component(GLOG_LIBRARY_DIR ${GLOG_LIBRARY} DIRECTORY)
include_directories(${GLOG_INCLUDE_DIR})
link_directories(${GLOG_LIBRARY_DIR})
endif ()
# gflags
if (NOT GFLAGS_FOUND)
message(WARNING "Can't find gflags library. It will be installed from git repository.")
ExternalProject_Add(gflags
GIT_REPOSITORY https://github.com/gflags/gflags
UPDATE_DISCONNECTED ${SKIP_UPDATE}
PREFIX gflags
SOURCE_DIR ${EXTERNAL_DIR}/gflags
BINARY_DIR ${PROJECT_BINARY_DIR}/gflags
INSTALL_DIR ${PROJECT_BINARY_DIR}/gflags
CONFIGURE_COMMAND test -e Makefile ||
cmake ${EXTERNAL_DIR}/gflags -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/gflags
BUILD_COMMAND test -e lib/libgflags.a || make -j
INSTALL_COMMAND test -e include/gflags/gflags.h || make install)
include_directories(${PROJECT_BINARY_DIR}/gflags/include)
link_directories(${PROJECT_BINARY_DIR}/gflags/lib)
else()
get_filename_component(GFLAGS_LIBRARY_DIR ${GFLAGS_LIBRARY} DIRECTORY)
include_directories(${GFLAGS_INCLUDE_DIR})
link_directories(${GFLAGS_LIBRARY_DIR})
endif()
# faiss
if (NOT FAISS_PATH)
if (NOT NO_FAISS)
ExternalProject_Add(faiss
GIT_REPOSITORY https://github.com/facebookresearch/faiss.git
UPDATE_DISCONNECTED ${SKIP_UPDATE}
PREFIX faiss
SOURCE_DIR ${EXTERNAL_DIR}/faiss
BINARY_DIR ${EXTERNAL_DIR}/faiss
INSTALL_DIR ${PROJECT_BINARY_DIR}/faiss
CONFIGURE_COMMAND test -e makefile.inc ||
${EXTERNAL_DIR}/faiss/configure --with-cuda=${CUDA_ROOT} --with-cuda-arch=${CUDA_ARCH}
BUILD_COMMAND test -e libfaiss.so || make -j
INSTALL_COMMAND test -e ${PROJECT_BINARY_DIR}/faiss/include/faiss/gpu/GpuIndexFlat.h ||
make install prefix=${PROJECT_BINARY_DIR}/faiss)
include_directories(${PROJECT_BINARY_DIR}/faiss/include)
link_directories(${PROJECT_BINARY_DIR}/faiss/lib)
set(FAISS_LIBRARY ${PROJECT_BINARY_DIR}/faiss/lib/libfaiss.so)
endif()
else()
get_filename_component(FAISS_PARENT ${FAISS_PATH} DIRECTORY)
include_directories(${FAISS_PARENT})
link_directories(${FAISS_PATH})
set(FAISS_LIBRARY ${FAISS_PATH}/libfaiss.so)
endif()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# compilation flags
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "-g -Og")
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -D NDEBUG")
set(CMAKE_CUDA_FLAGS "-std=c++11")
set(CMAKE_CUDA_FLAGS_DEBUG "-g -G")
set(CMAKE_CUDA_FLAGS_RELEASE "-O3")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CUDA_ARCH}")
foreach (MACRO FAST_COMPILE NO_FAISS)
if (${${MACRO}})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${MACRO}")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -D${MACRO}")
endif()
endforeach()
# output directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
# symbolic link to faiss
file(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
execute_process(COMMAND ln -sf ${FAISS_LIBRARY} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libfaiss.so)
# project directories
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(include)
add_subdirectory(src)