forked from ShiqiYu/libfacedetection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
202 lines (168 loc) · 6.16 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# CMakeLists for libfacedetectcnn
project(libfacedetection)
cmake_minimum_required(VERSION 2.8)
option(ENABLE_NEON "whether use neon, if use arm please set it on" OFF)
option(ENABLE_AVX512 "use avx512" OFF)
option(ENABLE_AVX2 "use avx2" ON)
option(DEMO "build the demo" OFF)
option(USE_OPENMP "Use OpenMP" ON)
if (BUILD_SHARED_LIBS)
add_definitions(-DBUILD_SHARED_LIBS)
if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
# Just setting CMAKE_POSITION_INDEPENDENT_CODE should be enough to set
# -fPIC for GCC but sometimes it still doesn't get set, so make sure it
# does.
add_definitions("-fPIC")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
SET(BUILD_VERSION "v0.0.1")
# Find Git Version Patch
IF(EXISTS "${CMAKE_SOURCE_DIR}/.git")
if(NOT GIT)
SET(GIT $ENV{GIT})
endif()
if(NOT GIT)
FIND_PROGRAM(GIT NAMES git git.exe git.cmd)
endif()
IF(GIT)
EXECUTE_PROCESS(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${GIT} describe --tags
OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_VERSION)
EXECUTE_PROCESS(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${GIT} rev-parse --short HEAD
OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
IF(NOT GIT_VERSION)
SET(BUILD_VERSION ${GIT_VERSION})
ENDIF()
ENDIF()
ENDIF()
message("BUILD_VERSION:${BUILD_VERSION}")
SET(fdt_base_dir ${PROJECT_SOURCE_DIR})
SET(fdt_src_dir ${fdt_base_dir}/src)
SET(fdt_inc_dir ${fdt_base_dir}/src)
SET(fdt_lib_name facedetection)
FILE(GLOB_RECURSE fdt_source_files ${fdt_src_dir}/*.cpp)
LIST(SORT fdt_source_files)
SET(INSTALLHEADER_FILES ${fdt_inc_dir}/facedetectcnn.h)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
IF(MSVC)
# This option is to enable the /MP switch for Visual Studio 2005 and above compilers
OPTION(WIN32_USE_MP "Set to ON to build with the /MP option (Visual Studio 2005 and above)." ON)
IF(WIN32_USE_MP)
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
add_compile_options(/MP)
ENDIF(WIN32_USE_MP)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
ENDIF(MSVC)
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
#use -O3 to speedup
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
ENDIF()
if(ENABLE_AVX512)
add_definitions(-D_ENABLE_AVX512)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512bw")
endif()
if(ENABLE_AVX2)
add_definitions(-D_ENABLE_AVX2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -mfma")
endif()
if(ENABLE_NEON)
message("Using ENON")
add_definitions(-D_ENABLE_NEON)
endif()
if(USE_OPENMP)
FIND_PACKAGE(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
endif()
INCLUDE_DIRECTORIES(${fdt_inc_dir})
include(CMakePackageConfigHelpers)
include(GenerateExportHeader)
include(GNUInstallDirs)
# Create a library
ADD_LIBRARY(${fdt_lib_name} ${fdt_source_files} ${INSTALLHEADER_FILES})
# Generate export header
GENERATE_EXPORT_HEADER(${fdt_lib_name})
string(TOLOWER ${fdt_lib_name} LOWER_PROJECT_NAME)
set(INSTALLHEADER_FILES ${INSTALLHEADER_FILES}
${CMAKE_CURRENT_BINARY_DIR}/${LOWER_PROJECT_NAME}_export.h)
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/${LOWER_PROJECT_NAME}_export.h
DESTINATION ${CMAKE_BINARY_DIR})
include_directories(${fdt_lib_name} ${CMAKE_BINARY_DIR})
set_target_properties(${fdt_lib_name} PROPERTIES
PUBLIC_HEADER "${INSTALLHEADER_FILES}" # Install head files
VERSION ${BUILD_VERSION}
)
# Install target
INSTALL(TARGETS ${fdt_lib_name}
EXPORT ${fdt_lib_name}Config
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/facedetection
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
export(TARGETS ${fdt_lib_name}
APPEND FILE ${CMAKE_BINARY_DIR}/${fdt_lib_name}Config.cmake
)
# Install cmake configure files
install(EXPORT ${fdt_lib_name}Config
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${fdt_lib_name}"
)
write_basic_package_version_file(
"${CMAKE_BINARY_DIR}/${fdt_lib_name}ConfigVersion.cmake"
VERSION ${BUILD_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES "${CMAKE_BINARY_DIR}/${fdt_lib_name}ConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${fdt_lib_name}")
# Create demo. OpenCV is requred.
if (DEMO)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(detect-image-demo ${fdt_base_dir}/example/detect-image.cpp)
target_link_libraries(detect-image-demo ${fdt_lib_name} ${OpenCV_LIBS})
add_executable(detect-camera-demo ${fdt_base_dir}/example/detect-camera.cpp)
target_link_libraries(detect-camera-demo ${fdt_lib_name} ${OpenCV_LIBS})
add_executable(benchmark ${fdt_base_dir}/example/benchmark.cpp)
target_link_libraries(benchmark ${fdt_lib_name} ${OpenCV_LIBS})
endif()
if (GSTREAMER)
find_package(OpenCV REQUIRED)
include(FindPkgConfig)
pkg_search_module(GSTREAMER REQUIRED gstreamer-1.0)
pkg_search_module(GSTREAMER_BASE REQUIRED gstreamer-base-1.0)
pkg_search_module(GSTREAMER_VIDEO REQUIRED gstreamer-video-1.0)
add_library(gstfacedetect SHARED
example/libfacedetect.cpp
)
include_directories(gstfacedetect PRIVATE
${GSTREAMER_INCLUDE_DIRS}
${GSTREAMER_BASE_INCLUDE_DIRS}
${GSTREAMER_VIDEO_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(gstfacedetect
${GSTREAMER_LIBRARIES}
${GSTREAMER_BASE_LIBRARIES}
${GSTREAMER_VIDEO_LIBRARIES}
${OpenCV_LIBS}
${fdt_lib_shared}
)
endif()
message("AVX512 = ${ENABLE_AVX512}")
message("AVX2 = ${ENABLE_AVX2}")
message("NEON = ${ENABLE_NEON}")
message("OpenMP = ${OPENMP_FOUND}")
message("DEMO = ${DEMO}")