From 4c535150568fb22f1e2be78fbbcc95118b0f6845 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Wed, 31 Oct 2018 10:38:27 +0800 Subject: [PATCH] Improve ros cmake files --- .../src/mynt_eye_ros_wrapper/CMakeLists.txt | 15 +++++--- .../cmake/DetectOpenCV.cmake | 37 +++++++++++++++++++ .../cmake/IncludeGuard.cmake | 23 ++++++++++++ 3 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 wrappers/ros/src/mynt_eye_ros_wrapper/cmake/DetectOpenCV.cmake create mode 100644 wrappers/ros/src/mynt_eye_ros_wrapper/cmake/IncludeGuard.cmake diff --git a/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt b/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt index ae85a88..92cea6c 100644 --- a/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt +++ b/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt @@ -15,8 +15,6 @@ cmake_minimum_required(VERSION 2.8.3) project(mynt_eye_ros_wrapper) -get_filename_component(SDK_DIR "${PROJECT_SOURCE_DIR}/../../../.." ABSOLUTE) - if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() @@ -77,9 +75,11 @@ catkin_package( CATKIN_DEPENDS cv_bridge geometry_msgs image_transport nodelet roscpp sensor_msgs std_msgs tf ) -get_filename_component(SDK_DIR "${PROJECT_SOURCE_DIR}/../../../.." ABSOLUTE) +#get_filename_component(SDK_DIR "${PROJECT_SOURCE_DIR}/../../../.." ABSOLUTE) +#LIST(APPEND CMAKE_PREFIX_PATH ${SDK_DIR}/_install/lib/cmake) + +LIST(APPEND CMAKE_MODULE_PATH cmake) -LIST(APPEND CMAKE_PREFIX_PATH ${SDK_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") @@ -87,10 +87,13 @@ if(NOT mynteye_WITH_API) message(FATAL_ERROR "Must with API layer :(") endif() -include(${SDK_DIR}/cmake/DetectOpenCV.cmake) +include(cmake/DetectOpenCV.cmake) if(mynteye_WITH_GLOG) - include(${SDK_DIR}/cmake/DetectGLog.cmake) + find_package(glog REQUIRED) + if(glog_FOUND) + add_definitions(-DWITH_GLOG) + endif() endif() # targets diff --git a/wrappers/ros/src/mynt_eye_ros_wrapper/cmake/DetectOpenCV.cmake b/wrappers/ros/src/mynt_eye_ros_wrapper/cmake/DetectOpenCV.cmake new file mode 100644 index 0000000..4673876 --- /dev/null +++ b/wrappers/ros/src/mynt_eye_ros_wrapper/cmake/DetectOpenCV.cmake @@ -0,0 +1,37 @@ +# Copyright 2018 Slightech Co., Ltd. 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. + +include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake) +cmake_include_guard() + +find_package(OpenCV REQUIRED) +message(STATUS "Found OpenCV: ${OpenCV_VERSION}") +if(OpenCV_VERSION VERSION_LESS 3.0) + add_definitions(-DUSE_OPENCV2) +elseif(OpenCV_VERSION VERSION_LESS 4.0) + add_definitions(-DUSE_OPENCV3) +else() + add_definitions(-DUSE_OPENCV4) +endif() + +list(FIND OpenCV_LIBS "opencv_world" __index) +if(${__index} GREATER -1) + set(WITH_OPENCV_WORLD TRUE) +endif() + +if(MSVC OR MSYS OR MINGW) + get_filename_component(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}/../bin" ABSOLUTE) +else() + set(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}") +endif() diff --git a/wrappers/ros/src/mynt_eye_ros_wrapper/cmake/IncludeGuard.cmake b/wrappers/ros/src/mynt_eye_ros_wrapper/cmake/IncludeGuard.cmake new file mode 100644 index 0000000..4c5dd68 --- /dev/null +++ b/wrappers/ros/src/mynt_eye_ros_wrapper/cmake/IncludeGuard.cmake @@ -0,0 +1,23 @@ +# Copyright 2018 Slightech Co., Ltd. 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. + +# include_guard: https://cmake.org/cmake/help/latest/command/include_guard.html + +macro(cmake_include_guard) + get_property(INCLUDE_GUARD GLOBAL PROPERTY "_INCLUDE_GUARD_${CMAKE_CURRENT_LIST_FILE}") + if(INCLUDE_GUARD) + return() + endif() + set_property(GLOBAL PROPERTY "_INCLUDE_GUARD_${CMAKE_CURRENT_LIST_FILE}" TRUE) +endmacro()