-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathCMakeLists.txt
167 lines (136 loc) · 4.64 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
# Copyright 2016 Carnegie Mellon University, NVIDIA 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.
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
project(Scanner)
###### Config options #####
option(BUILD_CUDA "" ON)
option(BUILD_TESTS "" ON)
option(ENABLE_PROFILING "" OFF)
if (BUILD_TESTS)
enable_testing()
endif()
###### Setup #########
# Verify C++11 support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y)
if(COMPILER_SUPPORTS_CXX1Y)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
# if(COMPILER_SUPPORTS_CXX11)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++1y support.")
endif()
# Include our custom cmake modules for finding packages
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(GLOBAL_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(THIRDPARTY_SOURCE_DIR "${CMAKE_SOURCE_DIR}/thirdparty")
set(THIRDPARTY_OUTPUT_PATH "${THIRDPARTY_SOURCE_DIR}/build/bin")
if(APPLE)
message(STATUS "Non-debug builds fail on MacOS. Setting to debug.")
set(CMAKE_BUILD_TYPE "Debug")
elseif(UNIX)
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, defaulting to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
if(NOT APPLE AND UNIX)
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -pthread -ldl -lrt")
endif()
if (ENABLE_PROFILING)
add_definitions(-DSCANNER_PROFILING)
endif()
if(APPLE)
set(PLATFORM_LINK_FLAGS
"-framework CoreFoundation"
"-framework CoreMedia"
"-framework CoreVideo"
"-framework Security"
"-framework VideoDecodeAcceleration"
"-framework VideoToolbox"
"-framework Accelerate"
"-undefined dynamic_lookup"
)
elseif(UNIX)
set(PLATFORM_LINK_FLAGS "-pthread -ldl -lrt")
endif()
include(cmake/Dependencies.cmake)
###### Project code #######
set(PROTO_FILES
scanner/metadata.proto
scanner/source_args.proto
scanner/sink_args.proto
scanner/sampler_args.proto
scanner/types.proto)
set(GRPC_PROTO_FILES
scanner/engine/rpc.proto)
protobuf_generate_cpp(
PROTO_SRCS PROTO_HDRS OFF ${PROTO_FILES} ${GRPC_PROTO_FILES})
protobuf_generate_cpp(
GRPC_PROTO_SRCS GRPC_PROTO_HDRS ON ${GRPC_PROTO_FILES})
protobuf_generate_python(PROTO_PY OFF ${PROTO_FILES})
protobuf_generate_python(GRPC_PROTO_PY ON ${GRPC_PROTO_FILES})
add_custom_target(proto_files DEPENDS
${PROTO_HDRS} ${PROTO_PY} ${GRPC_PROTO_HDRS} ${GRPC_PROTO_PY})
macro(add_deps)
add_dependencies(${targetName} proto_files)
endmacro()
function(add_library targetName)
_add_library(${targetName} ${ARGN})
add_deps()
endfunction()
function(add_executable targetName)
_add_executable(${targetName} ${ARGN})
add_deps()
endfunction()
set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG")
add_subdirectory(scanner)
add_library(scanner SHARED
$<TARGET_OBJECTS:api>
$<TARGET_OBJECTS:engine>
$<TARGET_OBJECTS:video>
$<TARGET_OBJECTS:util>
scanner/util/halide_context.cpp
${PROTO_SRCS}
${GRPC_PROTO_SRCS})
target_link_libraries(scanner PUBLIC
${SCANNER_LIBRARIES}
"${PLATFORM_LINK_FLAGS}")
set(PYDIR ${CMAKE_CURRENT_BINARY_DIR})
# Make init files so python code can import from subdirectories
foreach(FIL ${PROTO_FILES} ${GRPC_PROTO_FILES})
get_filename_component(DIR_FIL ${FIL} DIRECTORY)
get_filename_component(FIL_WE ${FIL} NAME_WE)
add_custom_command(TARGET proto_files POST_BUILD
COMMAND ${CMAKE_COMMAND} -E touch ${PYDIR}/${DIR_FIL}/__init__.py)
endforeach()
if (BUILD_TESTS)
add_subdirectory(tests)
endif()
if (BUILD_DOCS)
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen)
set(DOXYGEN_EXCLUDE_PATTERNS json.hpp concurrentqueue.h nvcuvid.h cuviddec.h
tinyformat.h blockingconcurrentqueue.h thread_pool.h)
find_package(Doxygen REQUIRED)
set(DOXYGEN_PROJECT_NAME "Scanner C++ API")
doxygen_add_docs(doxygen ${PROJECT_SOURCE_DIR}/scanner)
endif()
message("${GRPC_VERSION}")
file(WRITE ${CMAKE_BINARY_DIR}/grpc_version.txt "${GRPC_VERSION}")