This repository has been archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
CMakeLists.txt
278 lines (234 loc) · 9.59 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# *****************************************************************************
# Copyright 2018-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# *****************************************************************************
# SEAL requires >= 3.12
cmake_minimum_required(VERSION 3.12)
# Global project name
project(he_transformer LANGUAGES C CXX)
# set directory where the custom finders live
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
message(STATUS "CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}")
if(CMAKE_BUILD_TYPE)
set(RELEASE_TYPES
Debug
Release
RelWithDebInfo
MinSizeRel)
list(FIND RELEASE_TYPES ${CMAKE_BUILD_TYPE} INDEX_FOUND)
if(${INDEX_FOUND} EQUAL -1)
message(
FATAL_ERROR
"CMAKE_BUILD_TYPE must be one of Debug, Release, RelWithDebInfo, or MinSizeRel"
)
endif()
endif()
# Cmake flags SEAL requires C++17
set(NGRAPH_HE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD ${NGRAPH_HE_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_INSTALL_MESSAGE LAZY)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Create compilation database compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type" FORCE)
endif()
set(NGRAPH_HE_FORWARD_CMAKE_ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD}
-DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED}
-DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS}
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=${CMAKE_EXPORT_COMPILE_COMMANDS}
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=${CMAKE_POSITION_INDEPENDENT_CODE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
# These variables are undocumented but useful.
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
message(STATUS "Setting clang flags...")
include(cmake/clang_flags.cmake)
endif()
include(cmake/sdl.cmake)
# For ngraph/log
set(PROJECT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
add_definitions(-DPROJECT_ROOT_DIR="${PROJECT_ROOT_DIR}")
# he-transformer headers
set(HE_TRANSFORMER_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
# External projects (ngraph, seal, etc. )
set(EXTERNAL_INSTALL_DIR ${CMAKE_BINARY_DIR}/external)
set(EXTERNAL_INSTALL_LIB_DIR ${EXTERNAL_INSTALL_DIR}/lib)
set(EXTERNAL_INSTALL_INCLUDE_DIR ${EXTERNAL_INSTALL_DIR}/include)
set(NGRAPH_HE_INSTALL_DOC ${CMAKE_BINARY_DIR}/doc)
if(NOT DEFINED EXTERNAL_PROJECTS_ROOT)
set(EXTERNAL_PROJECTS_ROOT ${CMAKE_CURRENT_BINARY_DIR})
endif()
# Build options python version used in virtual environment
find_package(PythonInterp 3)
if(NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "Python3 not found.")
endif()
if(NOT DEFINED PYTHON_VENV_VERSION)
set(PYTHON_VENV_VERSION
"python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
endif()
option(NGRAPH_HE_DOC_BUILD_ENABLE "Enable building of documentation" OFF)
option(NGRAPH_HE_CLANG_TIDY "Enable clang-tidy checks" OFF)
option(NGRAPH_HE_CODE_COVERAGE "Enable code coverage" OFF)
option(NGRAPH_HE_ABY_ENABLE "Enable multi-party computation using ABY" OFF)
option(NGRAPH_HE_SANITIZE_ADDRESS "Enable address sanitizer" OFF)
option(NGRAPH_HE_PARALLEL "Enable multi-threaded computation" ON)
# Print options
message(STATUS "NGRAPH_HE_CXX_STANDARD: ${NGRAPH_HE_CXX_STANDARD}")
message(STATUS "NGRAPH_HE_DOC_BUILD_ENABLE: ${NGRAPH_HE_DOC_BUILD_ENABLE}")
message(STATUS "NGRAPH_HE_CODE_COVERAGE: ${NGRAPH_HE_CODE_COVERAGE}")
message(STATUS "NGRAPH_HE_ABY_ENABLE: ${NGRAPH_HE_ABY_ENABLE}")
message(STATUS "NGRAPH_HE_CLANG_TIDY: ${NGRAPH_HE_CLANG_TIDY}")
message(STATUS "NGRAPH_HE_SANITIZE_ADDRESS ${NGRAPH_HE_SANITIZE_ADDRESS}")
message(STATUS "NGRAPH_HE_PARALLEL ${NGRAPH_HE_PARALLEL}")
message(STATUS "PYTHON_VENV_VERSION: ${PYTHON_VENV_VERSION}")
message(STATUS "PYTHON_VERSION_STRING: ${PYTHON_VERSION_STRING}")
if(NGRAPH_HE_SANITIZE_ADDRESS)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
endif()
if (NGRAPH_HE_CODE_COVERAGE)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -g -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
if (NGRAPH_HE_ABY_ENABLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNGRAPH_HE_ABY_ENABLE")
endif()
if(NGRAPH_HE_CLANG_TIDY)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
endif()
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy-9)
if(NOT CLANG_TIDY_COMMAND)
message(
FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
endif()
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
# Create a preprocessor definition that depends on .clang-tidy content so the
# compile command will change when .clang-tidy changes. This ensures that a
# subsequent build re-runs clang-tidy on all sources even if they do not
# otherwise need to be recompiled. Nothing actually uses this definition. We
# add it to targets on which we run clang-tidy just to get the build
# dependency on the .clang-tidy file.
file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
unset(clang_tidy_sha1)
endif()
configure_file(.clang-tidy .clang-tidy COPYONLY)
# ------------------------------------------------------------------------------
# Installation logic...
# ------------------------------------------------------------------------------
if(LINUX)
include(GNUInstallDirs)
else()
set(CMAKE_INSTALL_BINDIR "bin")
set(CMAKE_INSTALL_INCLUDEDIR "include")
set(CMAKE_INSTALL_DOCDIR "doc")
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
if(DEFINED NGRAPH_HE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${NGRAPH_HE_INSTALL_PREFIX})
endif()
message(STATUS "Installation directory: ${CMAKE_INSTALL_PREFIX}")
# Destinations
set(NGRAPH_HE_INSTALL_LIB "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(NGRAPH_HE_INSTALL_INCLUDE
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
set(NGRAPH_HE_INSTALL_DOC "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}")
set(NGRAPH_HE_INSTALL_BIN "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
# ------------------------------------------------------------------------------
# Compiler-specific logic...
# ------------------------------------------------------------------------------
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -march=native -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g")
# This allows libhe_seal_backend.so to find libraries in the same directory
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
# Get OS version
if(NOT APPLE)
execute_process(COMMAND cat /etc/os-release
OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "\""
""
LSB_RELEASE_ID_SHORT
${LSB_RELEASE_ID_SHORT})
string(REGEX MATCH
"ID=\([a-z])+"
OS_VERSION
"${LSB_RELEASE_ID_SHORT}")
string(REGEX MATCH
"([a-z])+"
OS_VERSION
"${OS_VERSION}")
message(STATUS "OS version: ${OS_VERSION}")
endif()
if(UNIX OR APPLE)
add_custom_target(
style-check
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/maint/check-code-format.sh)
add_custom_target(
style-apply
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/maint/apply-code-format.sh)
add_custom_target(
style
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/maint/apply-code-format.sh)
endif()
# ------------------------------------------------------------------------------
# Print Global Options
# ------------------------------------------------------------------------------
message(STATUS "NGRAPH_HE_FORWARD_CMAKE_ARGS ${NGRAPH_HE_FORWARD_CMAKE_ARGS}")
message(STATUS "Compile Flags: ${CMAKE_CXX_FLAGS}")
message(STATUS "Shared Link Flags: ${CMAKE_SHARED_LINKER_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}")
include(cmake/ngraph.cmake)
include(cmake/ngraph-tf.cmake)
# Install he-transformer to installation location and into ngraph-tf
set(INSTALL_LIB_DIRS
${EXTERNAL_INSTALL_LIB_DIR}
${NGRAPH_TF_VENV_LIB_DIR}
${NGRAPH_TF_LIB_DIR}
${NGRAPH_HE_INSTALL_LIB})
set(INSTALL_INCLUDE_DIRS ${EXTERNAL_INSTALL_INCLUDE_DIR}
${NGRAPH_HE_INSTALL_INCLUDE})
include(cmake/gtest.cmake)
include(cmake/json.cmake)
if (NGRAPH_HE_PARALLEL)
include(cmake/openmp.cmake)
else ()
add_compile_options(-Wno-source-uses-openmp)
endif()
include(cmake/seal.cmake)
include(cmake/abseil.cmake)
include(cmake/boost.cmake)
include(cmake/protobuf.cmake)
if (NGRAPH_HE_ABY_ENABLE)
include(cmake/aby.cmake)
endif()
# HE transformer source and test directories
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(doc)
# For python bindings
add_subdirectory(python)