forked from OAID/Tengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
173 lines (145 loc) · 5.48 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
# cmake version main changes:
#
# 3.11: generator expression for Xcode and Visual Studio added
# INTERFACE support added
# 3.12: OpenMP support on Mac OS added
# CUDA as a language added
# -j,--parallel in --build added
# new FindPython module added
# C++20 support added
# 3.13: symbolic links on Windows added
# target_link_options and add_link_options added
# target_link_directories added
# STATIC_LIBRARY_OPTIONS added
# CUDA 10 (Turing) detection added
# 3.14: several utilities added
# BUILD_RPATH_USE_ORIGIN added
# 3.15: some command line improve
# 3.16: Objective C and Objective C++ languages support added
# target_precompile_headers support added
# RPath control added
# 3.17: FindCUDAToolkit added
# CUDA_RUNTIME_LIBRARY static linking mode added
# FindPython with Conda added
# Check CMake version
CMAKE_MINIMUM_REQUIRED (VERSION 3.10 FATAL_ERROR)
# Disable inplace builds to prevent source tree corruption.
IF (" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
MESSAGE (FATAL_ERROR "FATAL: Building inplace are not allowed. You should create a separate directory for Building.")
ENDIF ()
# set cmake_install_prefix path
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
endif()
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
# Enable the languages which in use
ENABLE_LANGUAGE (C CXX)
if(CMAKE_TOOLCHAIN_FILE)
set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are compiled to")
# get absolute path, but get_filename_component ABSOLUTE only refer with source dir, so find_file here :(
get_filename_component(CMAKE_TOOLCHAIN_FILE_NAME ${CMAKE_TOOLCHAIN_FILE} NAME)
find_file(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE_NAME} PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
message(STATUS "CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build" FORCE)
endif()
# Do check list
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/check.cmake")
project(tengine-lite)
option(TENGINE_OPENMP "openmp support" ON)
option(TENGINE_BUILD_BENCHMARK "build benchmark" ON)
option(TENGINE_BUILD_EXAMPLES "build examples" ON)
option(TENGINE_BUILD_TESTS "build tests" OFF)
option(TENGINE_BUILD_CPP_API "build C++ API" ON)
option(TENGINE_DEBUG_DATA "extract data for every layer" OFF)
option(TENGINE_DEBUG_TIME "print time information for every layer" OFF)
option(TENGINE_DEBUG_MEM_STAT "print memory status for library" OFF)
option(TENGINE_ARCH_X86_AVX "build avx2 for x86" ON)
option(TENGINE_ARCH_ARM_82 "build armv8.2 for arm" OFF)
# some plugin options
option(TENGINE_ENABLE_ACL "Build with Arm Compute Library(ACL) support" OFF)
option(TENGINE_ENABLE_VULKAN "Build with Vulkan GPU compute support" OFF)
# add_definitions(-DCONFIG_DISABLE_PARAM_ACCESS)
# add_definitions(-DCONFIG_INTERN_ALLOCATOR)
add_definitions(-DCONFIG_TENGINE_SERIALIZER)
# Debug macro information
if (TENGINE_DEBUG_MEM_STAT)
add_definitions(-DCONFIG_MEM_STAT)
endif()
if (TENGINE_DEBUG_DATA)
add_definitions(-DDEBUG_DATA)
endif()
if (TENGINE_DEBUG_TIME)
add_definitions(-DDEBUG_TIME)
endif()
if (TENGINE_LITE_VERSION)
add_definitions(-DTENGINE_LITE_VERSION=${TENGINE_LITE_VERSION})
endif()
if (CONFIG_VERSION_POSTFIX)
add_definitions(-DCONFIG_VERSION_POSTFIX=${CONFIG_VERSION_POSTFIX})
endif()
# add_definitions(-g)
# add_definitions(-O0)
add_definitions(-fPIC)
add_definitions(-O3)
if (${TENGINE_TARGET_PROCESSOR} MATCHES "ARM")
if (TENGINE_TARGET_PROCESSOR_32Bit AND NOT ANDROID)
add_definitions(-march=armv7-a)
add_definitions(-mfpu=neon)
add_definitions(-mfp16-format=ieee)
add_definitions(-mfpu=neon-fp16)
endif()
if (TENGINE_TOOLCHIN_FLAG)
add_definitions ("${TENGINE_TOOLCHIN_FLAG}")
endif()
endif()
enable_language(ASM)
# local include files
include_directories(include/)
include_directories(src/op/)
# add OpenMP support
set (TENGINE_VERBOSE ON)
if (NOT TENGINE_FORCE_SKIP_OPENMP)
find_package(OpenMP)
if(OpenMP_C_FOUND OR OPENMP_FOUND)
message (STATUS "TENGINE: OpenMP was found.")
endif()
endif()
if(TENGINE_OPENMP AND (OpenMP_C_FOUND OR OPENMP_FOUND))
if(TENGINE_VERBOSE)
message (STATUS "TENGINE: OpenMP support enabled.")
endif()
add_definitions(-fopenmp)
if(ANDROID_NDK_MAJOR AND (ANDROID_NDK_MAJOR GREATER 20))
list (APPEND TENGINE_LINKING_LIBS "-fopenmp -static-openmp")
if(TENGINE_VERBOSE)
message (STATUS "TENGINE: Android NDK is ${ANDROID_NDK_MAJOR}.${ANDROID_NDK_MINOR}.")
endif()
elseif(OpenMP_C_FOUND)
list (APPEND TENGINE_LINKING_LIBS "OpenMP::OpenMP_C")
if(TENGINE_VERBOSE)
message (STATUS "TENGINE: 'OpenMP_C_FOUND' is ${OpenMP_C_FOUND}.")
endif()
else()
list (APPEND TENGINE_LINKING_LIBS "${OpenMP_C_FLAGS}")
if(TENGINE_VERBOSE)
message (STATUS "TENGINE: 'OpenMP_C_FLAGS' is ${OpenMP_C_FLAGS}.")
endif()
endif()
endif()
# enable cmake ctest module
enable_testing()
# src files
add_subdirectory(src)
if (TENGINE_BUILD_BENCHMARK)
add_subdirectory(benchmark)
endif()
if (TENGINE_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if (TENGINE_BUILD_TESTS)
add_subdirectory(tests)
endif()
# Report summary
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/summary.cmake")