forked from microsoft/nnfusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
153 lines (123 loc) · 4.96 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
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
project (nnfusion)
message(STATUS " _ __ _ __ ____ _ ")
message(STATUS " / |/ // |/ // __/__ __ ___ (_)___ ___ ")
message(STATUS " / // // _/ / // /(_-< / // _ \\ / _ \\")
message(STATUS " /_/|_//_/|_//_/ \\_,_//___//_/ \\___//_//_/")
message(STATUS " MSRAsia NNFusion Team(@nnfusion)")
message(STATUS " https://github.com/microsoft/nnfusion")
message(STATUS "")
#-----------------------------------------------------------------------------------------------
# STEP.0 Global Options
#-----------------------------------------------------------------------------------------------
option(NNFUSION "Enable NNFusion backend." TRUE)
option(DEBUG_ENABLE "Enable debug mode" FALSE)
option(CODE_COVERAGE_ENABLE "Enable code coverage." FALSE)
option(ONNX_FRONTEND "Enable ONNX frontend." TRUE)
option(TENSORFLOW_FRONTEND "Enable Tensorflow frontend." TRUE)
option(TORCHSCRIPT_FRONTEND "Enable TorchScript frontend." FALSE)
#-----------------------------------------------------------------------------------------------
# STEP.1 Customnized targets
#-----------------------------------------------------------------------------------------------
message(STATUS "Installation directory: ${CMAKE_INSTALL_PREFIX}")
add_custom_target(style-check
COMMAND ${PROJECT_SOURCE_DIR}/maint/script/check_code_style.sh
)
add_custom_target(style
COMMAND ${PROJECT_SOURCE_DIR}/maint/script/apply_code_style.sh
)
#-----------------------------------------------------------------------------------------------
# STEP.2 Set CMake configs
#-----------------------------------------------------------------------------------------------
# *Make build proto file inside build folder possible.
set(CMAKE_DISABLE_SOURCE_CHANGES OFF)
set(CMAKE_DISABLE_IN_SOURCE_BUILD OFF)
# Determin which flags in use
if (UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
if (APPLE)
set(WholeArchiveFlag -Wl,-force_load)
set(NoWholeArchiveFlag -Wl,-noall_load)
else()
set(WholeArchiveFlag -Wl,--whole-archive)
set(NoWholeArchiveFlag -Wl,--no-whole-archive)
endif()
cmake_minimum_required (VERSION 3.10)
# Create compilation database compile_commands.json .
# Could be unsed in VScode or some analysis tool.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# STEP.3 Set compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if (${WARNINGS_AS_ERRORS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
message(STATUS "Warnings as errors")
endif()
# SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")
if(${DEBUG_ENABLE})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()
if (CODE_COVERAGE_ENABLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif()
set(GLOBAL_INCLUDE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/thirdparty
# for proto headers
${PROJECT_BINARY_DIR}/src
)
include_directories(
${GLOBAL_INCLUDE_PATH}
)
#-----------------------------------------------------------------------------------------------
# STEP.4 Set Project Defines
#-----------------------------------------------------------------------------------------------
# For usage inside source code
if(ONNX_FRONTEND)
add_definitions(-DONNX_FRONTEND)
endif()
if(TORCHSCRIPT_FRONTEND)
add_definitions(-DTORCHSCRIPT_FRONTEND)
endif()
add_definitions(-DPROJECT_ROOT_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
#-----------------------------------------------------------------------------------------------
# STEP.5 Find thirdparty libraries
#-----------------------------------------------------------------------------------------------
###Static###
set(Protobuf_USE_STATIC_LIBS ON)
find_package(Threads REQUIRED) # This is for test usage
find_package(GTest)
find_package(Protobuf 3.5.0)
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a)
find_library(GFLAGS NAMES gflags)
if (NOT "${GFLAGS}" STREQUAL "")
message(STATUS "Found gflags: ${GFLAGS}")
else()
message(FATAL_ERROR "Not found gflags" )
endif()
find_library(SQLITE3 NAMES sqlite3)
if (NOT "${SQLITE3}" STREQUAL "")
message(STATUS "Found sqlite3: ${SQLITE3}")
else()
message(FATAL_ERROR "Not found sqlite3" )
endif()
#-----------------------------------------------------------------------------------------------
# STEP.6 Check envs
#-----------------------------------------------------------------------------------------------
if(Protobuf_LIBRARY MATCHES "NOTFOUND")
message(STATUS "Cannot found any Protobuf libraries.")
endif()
#-----------------------------------------------------------------------------------------------
# STEP.7 Enable features
#-----------------------------------------------------------------------------------------------
add_subdirectory(thirdparty)
message(STATUS "thirdparty enabled")
add_subdirectory(src)
message(STATUS "nnfusion enabled")
add_subdirectory(test)
message(STATUS "unit tests enabled")
# add_subdirectory(doc)
# message(STATUS "nnfusion documents enabled")