forked from ros4hri/hri_face_detect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
176 lines (147 loc) · 5.66 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
# Copyright (c) 2023 PAL Robotics S.L. All rights reserved.
#
# 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.8)
project(hri_face_detect)
# Global flags
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# Dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(pal_module_cmake)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development) # Find python before pybind11
find_package(pybind11_vendor REQUIRED)
find_package(pybind11 REQUIRED)
### OLDER ATTEMPT TO INCLUDE THE YUNET PROJECT AS EXTERNAL PROJECT WITH ORIGINAL CMAKELISTS.
### IT DID NOT WORK DUE TO ${CATKIN_DEVEL_PREFIX} INCONSISTENCIES IN THE BUILD FARM.
# # build the face detection library as a shared library
# include(ExternalProject)
# externalproject_add(libfacedetection
# SOURCE_DIR ${CMAKE_SOURCE_DIR}/libfacedetection
# INSTALL_DIR "${CATKIN_DEVEL_PREFIX}"
# CMAKE_ARGS
# -DDEMO=OFF
# -DBUILD_SHARED_LIBS=ON
# -DUSE_OPENMP=OFF
# -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
# BUILD_BYPRODUCTS
# <INSTALL_DIR>/lib/libfacedetection.so
# <INSTALL_DIR>/lib/libfacedetection.so.v0.0.3
# )
### END OF OLD ATTEMPT
#########################################################################################
#########################################################################################
### YuNet face detection library
# this part of the CMakeLists is based on the original YuNet library:
# https://github.com/ShiqiYu/libfacedetection/blob/master/CMakeLists.txt
option(ENABLE_AVX512 "use avx512" OFF)
option(ENABLE_AVX2 "use avx2" ON)
option(ENABLE_NEON "whether use neon, if use arm please set it on" OFF)
option(USE_OPENMP "Use OpenMP" OFF)
message(STATUS "AVX512 = ${ENABLE_AVX512}")
message(STATUS "AVX2 = ${ENABLE_AVX2}")
message(STATUS "NEON = ${ENABLE_NEON}")
message(STATUS "OpenMP = ${USE_OPENMP}")
set(FDT_LIB_NAME facedetection)
set(FDT_BASE_DIR ${PROJECT_SOURCE_DIR})
set(FDT_SRC_DIR ${FDT_BASE_DIR}/src/libfacedetectcnn)
set(FDT_INC_DIR ${FDT_BASE_DIR}/include/libfacedetectcnn)
# set compiler flags
set(FDT_COMPILE_DEF)
set(FDT_COMPILE_FEAT cxx_std_11)
set(FDT_COMPILE_OPT -Wno-null-dereference)
if(ENABLE_AVX512)
set(FDT_COMPILE_DEF ${FDT_COMPILE_DEF} _ENABLE_AVX512)
set(FDT_COMPILE_OPT ${FDT_COMPILE_OPT} -mavx512bw)
endif()
if(ENABLE_AVX2)
set(FDT_COMPILE_DEF ${FDT_COMPILE_DEF} -D_ENABLE_AVX2)
set(FDT_COMPILE_OPT ${FDT_COMPILE_OPT} -mavx2 -mfma)
endif()
if(ENABLE_NEON)
message("Using NEON")
set(FDT_COMPILE_DEF ${FDT_COMPILE_DEF} _ENABLE_AVX2)
endif()
if(USE_OPENMP)
find_package(OpenMP)
if(OPENMP_FOUND)
set(FDT_COMPILE_OPT ${FDT_COMPILE_OPT} ${OpenMP_CXX_FLAGS})
endif()
endif()
# Create the shared library
file(GLOB_RECURSE FDT_SRC_FILES ${FDT_SRC_DIR}/*.cpp)
list(SORT FDT_SRC_FILES)
add_library(${FDT_LIB_NAME} SHARED ${FDT_SRC_FILES})
include(GenerateExportHeader)
generate_export_header(${FDT_LIB_NAME})
string(TOLOWER ${FDT_LIB_NAME} LOWER_PROJECT_NAME)
set(INSTALLHEADER_FILES
${FDT_INC_DIR}/facedetectcnn.h
${CMAKE_BINARY_DIR}/${LOWER_PROJECT_NAME}_export.h
)
set(FDT_INC_DIR ${FDT_INC_DIR} ${CMAKE_BINARY_DIR})
target_include_directories(${FDT_LIB_NAME} PUBLIC ${FDT_INC_DIR})
target_compile_definitions(${FDT_LIB_NAME} PUBLIC ${FDT_COMPILE_DEF})
target_compile_features(${FDT_LIB_NAME} PUBLIC ${FDT_COMPILE_FEAT})
target_compile_options(${FDT_LIB_NAME} PUBLIC ${FDT_COMPILE_OPT})
set_target_properties(${FDT_LIB_NAME} PROPERTIES
PUBLIC_HEADER "${INSTALLHEADER_FILES}" # Install head files
CXX_EXTENSIONS OFF
)
# Install target
install(
TARGETS ${FDT_LIB_NAME}
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}
)
### End of YuNet face detection library
#########################################################################################
#########################################################################################
ament_python_install_package(${PROJECT_NAME}
SCRIPTS_DESTINATION lib/${PROJECT_NAME}
)
# build the python bindings to the face detection library
pybind11_add_module(yunet_detector src/hri_face_detect/yunet_detector.cpp)
target_include_directories(yunet_detector PRIVATE ${PYBIND11_INCLUDE_DIRS} include)
target_link_libraries(yunet_detector PRIVATE ${FDT_LIB_NAME})
install(TARGETS yunet_detector
LIBRARY DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}"
)
install(DIRECTORY launch config
DESTINATION share/${PROJECT_NAME}
)
# register the default configuration file
ament_index_register_resource("pal_configuration.hri_face_detect" CONTENT config/00-defaults.yml)
if(pal_module_cmake_FOUND)
pal_register_modules(
module/hri_face_detect_module.yaml
)
endif()
# Testing
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
find_package(ament_lint_common REQUIRED)
set(AMENT_LINT_AUTO_FILE_EXCLUDE
include/libfacedetectcnn/facedetectcnn.h
src/libfacedetectcnn/facedetectcnn-data.cpp
src/libfacedetectcnn/facedetectcnn-model.cpp
src/libfacedetectcnn/facedetectcnn.cpp)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()