mirror of
https://gitlab.com/yikestone/ros_openvino_tiny-yolov3.git
synced 2025-08-03 05:34:12 +05:30
134 lines
3.9 KiB
CMake
134 lines
3.9 KiB
CMake
cmake_minimum_required(VERSION 2.8.3)
|
|
project(openvino_object_detection)
|
|
|
|
find_package(InferenceEngine 1.5)
|
|
|
|
find_package(catkin REQUIRED COMPONENTS
|
|
message_generation roscpp InferenceEngine sensor_msgs cv_bridge)
|
|
|
|
if(UNIX OR APPLE)
|
|
# Linker flags.
|
|
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
|
|
# GCC specific flags. ICC is compatible with them.
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now")
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now")
|
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
|
# In Clang, -z flags are not compatible, they need to be passed to linker via -Wl.
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
|
|
endif()
|
|
|
|
# Compiler flags.
|
|
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
|
# GCC specific flags.
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector-strong")
|
|
else()
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector")
|
|
endif()
|
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
|
# Clang is compatbile with some of the flags.
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector")
|
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
|
|
# Same as above, with exception that ICC compilation crashes with -fPIE option, even
|
|
# though it uses -pie linker option that require -fPIE during compilation. Checksec
|
|
# shows that it generates correct PIE anyway if only -pie is provided.
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
|
|
endif()
|
|
|
|
# Generic flags.
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fno-operator-names -Wformat -Wformat-security -Wall")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
|
|
# Add OpenMP support
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
|
|
endif()
|
|
|
|
# Add x86 intrinsic compiler support
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
|
|
execute_process(
|
|
COMMAND bash -c "lscpu | grep -qi flags | grep -qi flags | grep -qi f16c"
|
|
RESULT_VARIABLE SUPPORT_F16C)
|
|
if (SUPPORT_F16C EQUAL 0)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c")
|
|
add_definitions(-DSUPPORT_MF16C)
|
|
endif()
|
|
|
|
execute_process(
|
|
COMMAND bash -c "lscpu | grep -qi flags | grep -qi flags | grep -qi sse4_1"
|
|
RESULT_VARIABLE SUPPORT_SSE41)
|
|
if (SUPPORT_SSE41 EQUAL 0)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
|
|
endif()
|
|
|
|
## Generate messages in the 'msg' folder
|
|
add_message_files(FILES
|
|
Object.msg
|
|
)
|
|
|
|
add_service_files(FILES
|
|
Objects.srv
|
|
)
|
|
|
|
generate_messages(DEPENDENCIES
|
|
std_msgs
|
|
sensor_msgs
|
|
)
|
|
|
|
|
|
catkin_package(
|
|
CATKIN_DEPENDS
|
|
message_runtime
|
|
std_msgs
|
|
sensor_msgs
|
|
)
|
|
|
|
find_package(OpenCV REQUIRED)
|
|
|
|
message( ${InferenceEngine_LIBRARIES}
|
|
)
|
|
|
|
include_directories(
|
|
include ${catkin_INCLUDE_DIRS}
|
|
${InferenceEngine_INCLUDE_DIRS}
|
|
${InferenceEngine_INCLUDE_DIRS}/../samples
|
|
${InferenceEngine_INCLUDE_DIRS}/../samples/common
|
|
${InferenceEngine_DIR}/../src
|
|
${InferenceEngine_DIR}/../src/extension
|
|
${OpenCV_INCLUDE_DIRS}
|
|
|
|
)
|
|
|
|
|
|
|
|
add_executable(object_detection
|
|
src/main.cpp
|
|
)
|
|
|
|
add_executable(object_detection_test
|
|
src/test.cpp
|
|
)
|
|
|
|
add_dependencies(object_detection ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
|
|
|
add_dependencies(object_detection_test ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
|
|
|
set_target_properties(object_detection PROPERTIES "CMAKE_CXX_FLAGS" "${CMAKE_CXX_FLAGS} -fPIE"
|
|
COMPILE_PDB_NAME object_detection)
|
|
|
|
target_link_libraries(object_detection
|
|
IE::ie_cpu_extension
|
|
gflags
|
|
dl
|
|
pthread
|
|
${catkin_LIBRARIES}
|
|
${InferenceEngine_LIBRARIES}
|
|
${OpenCV_LIBRARIES}
|
|
)
|
|
|
|
target_link_libraries(object_detection_test
|
|
${catkin_LIBRARIES}
|
|
|
|
${OpenCV_LIBRARIES}
|
|
)
|