forked from DefTruth/lite.ai.toolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lite.ai-cmd.cmake
149 lines (133 loc) · 5.88 KB
/
lite.ai-cmd.cmake
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
# config lite.ai shared lib.
function(add_lite_ai_shared_library version soversion)
configure_file (
"${CMAKE_SOURCE_DIR}/lite/config.h.in"
"${CMAKE_SOURCE_DIR}/lite/config.h"
)
# 2. glob headers files
file(GLOB LITE_HEAD ${CMAKE_SOURCE_DIR}/lite/*.h)
# 3. glob sources files
file(GLOB LITE_SRCS ${CMAKE_SOURCE_DIR}/lite/*.cpp)
set(LITE_DEPENDENCIES ${OpenCV_LIBS})
if (ENABLE_ONNXRUNTIME)
include(lite.ai-onnxruntime.cmake)
set(LITE_SRCS ${LITE_SRCS} ${ORT_SRCS})
set(LITE_DEPENDENCIES ${LITE_DEPENDENCIES} onnxruntime)
endif()
if (ENABLE_MNN)
include(lite.ai-mnn.cmake)
set(LITE_SRCS ${LITE_SRCS} ${MNN_SRCS})
set(LITE_DEPENDENCIES ${LITE_DEPENDENCIES} mnn)
endif()
if (ENABLE_NCNN)
include(lite.ai-ncnn.cmake)
set(LITE_SRCS ${LITE_SRCS} ${NCNN_SRCS})
set(LITE_DEPENDENCIES ${LITE_DEPENDENCIES} ncnn)
endif()
if (ENABLE_TNN)
include(lite.ai-tnn.cmake)
set(LITE_SRCS ${LITE_SRCS} ${TNN_SRCS})
set(LITE_DEPENDENCIES ${LITE_DEPENDENCIES} tnn)
endif()
# 4. shared library
add_library(lite.ai SHARED ${LITE_SRCS})
target_link_libraries(lite.ai ${LITE_DEPENDENCIES})
set_target_properties(lite.ai PROPERTIES VERSION ${version} SOVERSION ${soversion})
if (LITE_AI_COPY_BUILD)
message("Installing Lite.AI Headers ...")
file(INSTALL ${LITE_HEAD} DESTINATION ${CMAKE_SOURCE_DIR}/build/lite.ai/include/lite)
endif ()
message(">>>> Added Shared Library: lite.ai !")
endfunction()
# add custom command for lite.ai shared lib.
function(add_lite_ai_custom_command)
if (LITE_AI_BUILD_TEST)
add_custom_command(TARGET lite.ai
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${EXECUTABLE_OUTPUT_PATH}
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBRARY_OUTPUT_PATH}
COMMAND ${CMAKE_COMMAND} -E echo "create ${LIBRARY_OUTPUT_PATH} done!"
COMMAND ${CMAKE_COMMAND} -E echo "create ${EXECUTABLE_OUTPUT_PATH} done!"
)
# copy opencv & lite.ai libs.
add_custom_command(TARGET lite.ai
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBRARY_OUTPUT_PATH} ${EXECUTABLE_OUTPUT_PATH}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${OpenCV_LIBRARY_DIR} ${EXECUTABLE_OUTPUT_PATH}
COMMAND ${CMAKE_COMMAND} -E rm -rf ${EXECUTABLE_OUTPUT_PATH}/cmake
COMMAND ${CMAKE_COMMAND} -E echo "copy opencv and lite.ai libs done!"
)
# copy onnxruntime libs.
if (ENABLE_ONNXRUNTIME)
add_custom_command(TARGET lite.ai
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${ONNXRUNTIME_LIBRARY_DIR} ${EXECUTABLE_OUTPUT_PATH}
COMMAND ${CMAKE_COMMAND} -E echo "copy onnxruntime libs done!"
)
endif()
# copy MNN libs.
if (ENABLE_MNN)
add_custom_command(TARGET lite.ai
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${MNN_LIBRARY_DIR} ${EXECUTABLE_OUTPUT_PATH}
COMMAND ${CMAKE_COMMAND} -E echo "copy MNN libs done!"
)
endif()
# copy NCNN libs.
if (ENABLE_NCNN)
add_custom_command(TARGET lite.ai
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${NCNN_LIBRARY_DIR} ${EXECUTABLE_OUTPUT_PATH}
COMMAND ${CMAKE_COMMAND} -E echo "copy NCNN libs done!"
)
endif()
# copy TNN libs.
if (ENABLE_TNN)
add_custom_command(TARGET lite.ai
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${TNN_LIBRARY_DIR} ${EXECUTABLE_OUTPUT_PATH}
COMMAND ${CMAKE_COMMAND} -E echo "copy TNN libs done!"
)
endif()
endif()
endfunction()
function(add_lite_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai) # link lite.ai
message(">>>> Added Lite Executable: ${executable_name} !")
endfunction ()
function(add_ort_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai) # link lite.ai
message(">>>> Added Ort Executable: ${executable_name} !")
endfunction ()
function(add_mnn_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai) # link lite.ai
message(">>>> Added MNN Executable: ${executable_name} !")
endfunction ()
function(add_ncnn_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai) # link lite.ai
message(">>>> Added NCNN Executable: ${executable_name} !")
endfunction ()
function(add_tnn_executable executable_name field)
if (NOT ${THIRDPARTY_SET_STATE})
include(${CMAKE_SOURCE_DIR}/setup_3rdparty.cmake)
endif()
add_executable(${executable_name} ${field}/test_${executable_name}.cpp)
target_link_libraries(${executable_name} lite.ai) # link lite.ai
message(">>>> Added TNN Executable: ${executable_name} !")
endfunction ()