-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
119 lines (102 loc) · 3.1 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
# Copyright (C), 2023, KNS Group LLC (YADRO)
# 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.
cmake_minimum_required(VERSION 3.21)
project(halide_riscv)
include(ExternalProject)
set(CROSS_COMPILE_FLAGS "")
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "riscv64")
list(APPEND CROSS_COMPILE_FLAGS
"-DCMAKE_TOOLCHAIN_FILE=<SOURCE_DIR>/platforms/linux/riscv64-gcc.toolchain.cmake"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
)
endif()
# OpenCV's flags
ExternalProject_Add(opencv
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/3rdparty/opencv"
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_INSTALL_PREFIX=<BINARY_DIR>/install/"
${CROSS_COMPILE_FLAGS}
"-DBUILD_LIST=ts,core,imgproc,dnn"
"-DWITH_WEBP=OFF"
"-DWITH_ZLIB=OFF"
"-DWITH_OPENEXR=OFF"
"-DWITH_FFMPEG=OFF"
"-DWITH_IPP=OFF"
"-DWITH_JASPER=OFF"
"-DWITH_QUIRC=OFF"
"-DWITH_ITT=OFF"
"-DWITH_ADE=OFF"
"-DWITH_OPENCL=OFF"
"-DWITH_TIFF=OFF"
"-DBUILD_ZLIB=OFF"
"-DBUILD_PERF_TESTS=OFF"
"-DWITH_JASPER=OFF"
"-DBUILD_opencv_apps=OFF"
)
ExternalProject_Get_Property(opencv binary_dir)
set(OpenCV_INCLUDE_DIRS
"${binary_dir}/install/include/opencv4"
"${binary_dir}/install/include/opencv4/opencv2"
"${CMAKE_CURRENT_LIST_DIR}/3rdparty/opencv/modules/ts/include"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
file(GLOB SOURCES src/*.cpp)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "riscv64")
file(GLOB ASM aot/*.s)
list(APPEND SOURCES ${ASM})
endif()
add_library(algos SHARED ${SOURCES})
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "riscv64")
enable_language(ASM)
target_include_directories(algos PRIVATE "${CMAKE_CURRENT_LIST_DIR}/aot")
else()
find_package(Halide REQUIRED)
target_link_libraries(algos
Halide::Halide
)
endif()
add_dependencies(algos opencv)
target_include_directories(algos PRIVATE
${Halide_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
"include"
)
target_link_libraries(algos
"${binary_dir}/install/lib/libopencv_core.so"
"${binary_dir}/install/lib/libopencv_imgproc.so"
"${binary_dir}/install/lib/libopencv_dnn.so"
)
# Performance tests
file(GLOB PERF_SOURCES perf/*.cpp)
add_executable(perf_algo ${PERF_SOURCES})
target_link_libraries(perf_algo
algos
"${binary_dir}/lib/libopencv_ts.a"
pthread
)
target_include_directories(perf_algo PUBLIC
${OpenCV_INCLUDE_DIRS}
"include"
)
# Accuracy tests
file(GLOB PERF_SOURCES test/*.cpp)
add_executable(test_algo ${PERF_SOURCES})
target_link_libraries(test_algo
algos
"${binary_dir}/lib/libopencv_ts.a"
pthread
)
target_include_directories(test_algo PUBLIC
${OpenCV_INCLUDE_DIRS}
"include"
)