From ff70cc47f34e863e33ef423ea3ba33c6429810de Mon Sep 17 00:00:00 2001 From: John Zhao Date: Fri, 11 May 2018 16:15:26 +0800 Subject: [PATCH] Update CMakeLists.txt --- CMakeLists.txt | 9 +----- Makefile | 4 +++ cmake/Common.cmake | 3 ++ cmake/DetectCXX11.cmake | 3 ++ cmake/DetectOpenCV.cmake | 30 +++++++++++++++++++ cmake/IncludeGuard.cmake | 23 ++++++++++++++ cmake/Utils.cmake | 51 ++++++++++++++++++++++++++++++++ samples/CMakeLists.txt | 17 ++--------- samples/api/CMakeLists.txt | 15 +++------- samples/device/CMakeLists.txt | 15 +++------- samples/tutorials/CMakeLists.txt | 30 +++++++++---------- samples/uvc/CMakeLists.txt | 15 +++------- test/CMakeLists.txt | 33 +++++---------------- tools/CMakeLists.txt | 17 ++--------- tools/dataset/CMakeLists.txt | 15 +++------- tools/writer/CMakeLists.txt | 47 ++++++++--------------------- 16 files changed, 171 insertions(+), 156 deletions(-) create mode 100644 cmake/DetectOpenCV.cmake create mode 100644 cmake/IncludeGuard.cmake create mode 100644 cmake/Utils.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 60bba1a..c674f8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,14 +49,7 @@ find_package(glog REQUIRED) message(STATUS "Found glog: ${glog_VERSION}") if(WITH_API) - find_package(OpenCV REQUIRED) - message(STATUS "Found OpenCV: ${OpenCV_VERSION}") - - if(OpenCV_VERSION VERSION_LESS 3.0) - add_definitions(-DUSE_OPENCV2) - else() - add_definitions(-DUSE_OPENCV3) - endif() + include(cmake/DetectOpenCV.cmake) endif() LIST(APPEND CMAKE_MODULE_PATH cmake) diff --git a/Makefile b/Makefile index da4c050..79077b3 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,10 @@ help: .PHONY: help +all: test tools samples + +.PHONY: all + # doc apidoc: diff --git a/cmake/Common.cmake b/cmake/Common.cmake index e2e7078..d6aeb30 100755 --- a/cmake/Common.cmake +++ b/cmake/Common.cmake @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake) +cmake_include_guard() + include(CMakeParseArguments) set(CUR_DIR ${CMAKE_CURRENT_LIST_DIR}) diff --git a/cmake/DetectCXX11.cmake b/cmake/DetectCXX11.cmake index 61a1c30..7d075b6 100644 --- a/cmake/DetectCXX11.cmake +++ b/cmake/DetectCXX11.cmake @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake) +cmake_include_guard() + if(MSVC) # Support For C++11/14/17 Features (Modern C++) diff --git a/cmake/DetectOpenCV.cmake b/cmake/DetectOpenCV.cmake new file mode 100644 index 0000000..196a551 --- /dev/null +++ b/cmake/DetectOpenCV.cmake @@ -0,0 +1,30 @@ +# 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) +else() + add_definitions(-DUSE_OPENCV3) +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/cmake/IncludeGuard.cmake b/cmake/IncludeGuard.cmake new file mode 100644 index 0000000..4c5dd68 --- /dev/null +++ b/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() diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake new file mode 100644 index 0000000..1f5a607 --- /dev/null +++ b/cmake/Utils.cmake @@ -0,0 +1,51 @@ +# 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() + +include(${CMAKE_CURRENT_LIST_DIR}/Common.cmake) + +# make_executable(NAME +# [SRCS src1 src2 ...] +# [LINK_LIBS lib1 lib2 ...] +# [DLL_SEARCH_PATHS path1 path2 ...] +# [WITH_THREAD]) +macro(make_executable NAME) + set(options WITH_THREAD) + set(oneValueArgs) + set(multiValueArgs SRCS LINK_LIBS DLL_SEARCH_PATHS) + cmake_parse_arguments(THIS "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + add_executable(${NAME} ${THIS_SRCS}) + target_link_libraries(${NAME} ${THIS_LINK_LIBS}) + target_create_scripts(${NAME} DLL_SEARCH_PATHS ${THIS_DLL_SEARCH_PATHS}) + + if(OS_WIN) + target_compile_definitions(${NAME} + PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES + ) + endif() + + if(THIS_WITH_THREAD) + #find_package(Threads REQUIRED) + if(THREADS_HAVE_PTHREAD_ARG) + target_compile_options(PUBLIC ${NAME} "-pthread") + endif() + if(CMAKE_THREAD_LIBS_INIT) + target_link_libraries(${NAME} "${CMAKE_THREAD_LIBS_INIT}") + endif() + endif() +endmacro() diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 1a78096..58a0157 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -19,6 +19,7 @@ project(mynteye_samples VERSION 2.0.0 LANGUAGES C CXX) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) include(${PRO_DIR}/cmake/Common.cmake) +include(${PRO_DIR}/cmake/Utils.cmake) # options @@ -54,21 +55,9 @@ LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") -LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) +include(${PRO_DIR}/cmake/DetectOpenCV.cmake) -find_package(OpenCV REQUIRED) -message(STATUS "Found OpenCV: ${OpenCV_VERSION}") -if(OpenCV_VERSION VERSION_LESS 3.0) - add_definitions(-DUSE_OPENCV2) -else() - add_definitions(-DUSE_OPENCV3) -endif() - -if(OS_WIN) - get_filename_component(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}/../bin" ABSOLUTE) -else() - set(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}") -endif() +#LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) # targets diff --git a/samples/api/CMakeLists.txt b/samples/api/CMakeLists.txt index 61468dc..9920021 100644 --- a/samples/api/CMakeLists.txt +++ b/samples/api/CMakeLists.txt @@ -22,15 +22,8 @@ set_outdir( ## camera_a -add_executable(camera_a camera.cc) -target_link_libraries(camera_a mynteye ${OpenCV_LIBS}) -target_create_scripts(camera_a DLL_SEARCH_PATHS - ${PRO_DIR}/_install/bin - ${OpenCV_LIB_SEARCH_PATH} +make_executable(camera_a + SRCS camera.cc + LINK_LIBS mynteye ${OpenCV_LIBS} + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} ) - -if(OS_WIN) - target_compile_definitions(camera_a - PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES - ) -endif() diff --git a/samples/device/CMakeLists.txt b/samples/device/CMakeLists.txt index 8652fd3..aa27b4e 100644 --- a/samples/device/CMakeLists.txt +++ b/samples/device/CMakeLists.txt @@ -22,15 +22,8 @@ set_outdir( ## camera_d -add_executable(camera_d camera.cc) -target_link_libraries(camera_d mynteye ${OpenCV_LIBS}) -target_create_scripts(camera_d DLL_SEARCH_PATHS - ${PRO_DIR}/_install/bin - ${OpenCV_LIB_SEARCH_PATH} +make_executable(camera_d + SRCS camera.cc + LINK_LIBS mynteye ${OpenCV_LIBS} + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} ) - -if(OS_WIN) - target_compile_definitions(camera_d - PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES - ) -endif() diff --git a/samples/tutorials/CMakeLists.txt b/samples/tutorials/CMakeLists.txt index 9a34d4d..506a94b 100644 --- a/samples/tutorials/CMakeLists.txt +++ b/samples/tutorials/CMakeLists.txt @@ -24,11 +24,11 @@ set_outdir( "${OUT_DIR}/bin/${DIR_NAME}" ) -# make_executable(NAME -# [SRCS src1 src2 ...]) +# make_executable2(NAME +# [SRCS src1 src2 ...] # [WITH_OPENCV] # [WITH_PCL]) -macro(make_executable NAME) +macro(make_executable2 NAME) set(options WITH_OPENCV WITH_PCL) set(oneValueArgs) set(multiValueArgs SRCS) @@ -88,29 +88,29 @@ endif() # data -make_executable(get_device_info SRCS data/get_device_info.cc) -make_executable(get_img_params SRCS data/get_img_params.cc) -make_executable(get_imu_params SRCS data/get_imu_params.cc) +make_executable2(get_device_info SRCS data/get_device_info.cc) +make_executable2(get_img_params SRCS data/get_img_params.cc) +make_executable2(get_imu_params SRCS data/get_imu_params.cc) -make_executable(get_stereo SRCS data/get_stereo.cc WITH_OPENCV) -make_executable(get_stereo_rectified SRCS data/get_stereo_rectified.cc WITH_OPENCV) -make_executable(get_disparity SRCS data/get_disparity.cc WITH_OPENCV) -make_executable(get_depth SRCS data/get_depth.cc WITH_OPENCV) +make_executable2(get_stereo SRCS data/get_stereo.cc WITH_OPENCV) +make_executable2(get_stereo_rectified SRCS data/get_stereo_rectified.cc WITH_OPENCV) +make_executable2(get_disparity SRCS data/get_disparity.cc WITH_OPENCV) +make_executable2(get_depth SRCS data/get_depth.cc WITH_OPENCV) if(PCL_FOUND) - make_executable(get_points + make_executable2(get_points SRCS data/get_points.cc data/pc_viewer.cc WITH_OPENCV WITH_PCL ) endif() -make_executable(get_imu SRCS data/get_imu.cc data/cv_painter.cc WITH_OPENCV) -make_executable(get_from_callbacks +make_executable2(get_imu SRCS data/get_imu.cc data/cv_painter.cc WITH_OPENCV) +make_executable2(get_from_callbacks SRCS data/get_from_callbacks.cc data/cv_painter.cc WITH_OPENCV ) -make_executable(get_with_plugin SRCS data/get_with_plugin.cc WITH_OPENCV) +make_executable2(get_with_plugin SRCS data/get_with_plugin.cc WITH_OPENCV) # control -make_executable(ctrl_infrared SRCS control/infrared.cc WITH_OPENCV) +make_executable2(ctrl_infrared SRCS control/infrared.cc WITH_OPENCV) endif() diff --git a/samples/uvc/CMakeLists.txt b/samples/uvc/CMakeLists.txt index b25cb6f..8f93438 100644 --- a/samples/uvc/CMakeLists.txt +++ b/samples/uvc/CMakeLists.txt @@ -26,15 +26,8 @@ include_directories( ## camera_u -add_executable(camera_u camera.cc) -target_link_libraries(camera_u mynteye ${OpenCV_LIBS}) -target_create_scripts(camera_u DLL_SEARCH_PATHS - ${PRO_DIR}/_install/bin - ${OpenCV_LIB_SEARCH_PATH} +make_executable(camera_u + SRCS camera.cc + LINK_LIBS mynteye ${OpenCV_LIBS} + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} ) - -if(OS_WIN) - target_compile_definitions(camera_u - PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES - ) -endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fd1d475..11c68cd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -19,6 +19,7 @@ project(mynteye_test VERSION 2.0.0 LANGUAGES C CXX) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) include(${PRO_DIR}/cmake/Common.cmake) +include(${PRO_DIR}/cmake/Utils.cmake) # flags @@ -64,10 +65,9 @@ LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") -LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) +include(${PRO_DIR}/cmake/DetectOpenCV.cmake) -find_package(OpenCV REQUIRED) -message(STATUS "Found OpenCV: ${OpenCV_VERSION}") +#LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) ## gtest @@ -105,27 +105,8 @@ include_directories( file(GLOB TEST_INTERNAL_SRC "internal/*.cc") file(GLOB TEST_PUBLIC_SRC "public/*.cc") -add_executable(${PROJECT_NAME} - gtest_main.cc - ${TEST_INTERNAL_SRC} - ${TEST_PUBLIC_SRC} +make_executable(${PROJECT_NAME} + SRCS gtest_main.cc ${TEST_INTERNAL_SRC} ${TEST_PUBLIC_SRC} + LINK_LIBS mynteye ${GTEST_LIBS} ${OpenCV_LIBS} + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} ) -target_link_libraries(${PROJECT_NAME} mynteye ${GTEST_LIBS} ${OpenCV_LIBS}) -target_create_scripts(${PROJECT_NAME} DLL_SEARCH_PATHS - ${PRO_DIR}/_install/bin - ${OpenCV_LIB_SEARCH_PATH} -) - -if(OS_WIN) - target_compile_definitions(${PROJECT_NAME} - PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES - ) -endif() - -#find_package(Threads REQUIRED) -#if(THREADS_HAVE_PTHREAD_ARG) -# target_compile_options(PUBLIC ${PROJECT_NAME} "-pthread") -#endif() -#if(CMAKE_THREAD_LIBS_INIT) -# target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}") -#endif() diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index abbcbaf..a617541 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -19,6 +19,7 @@ project(mynteye_tools VERSION 2.0.0 LANGUAGES C CXX) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) include(${PRO_DIR}/cmake/Common.cmake) +include(${PRO_DIR}/cmake/Utils.cmake) # flags @@ -50,21 +51,9 @@ LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake) find_package(mynteye REQUIRED) message(STATUS "Found mynteye: ${mynteye_VERSION}") -LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) +include(${PRO_DIR}/cmake/DetectOpenCV.cmake) -find_package(OpenCV REQUIRED) -message(STATUS "Found OpenCV: ${OpenCV_VERSION}") -if(OpenCV_VERSION VERSION_LESS 3.0) - add_definitions(-DUSE_OPENCV2) -else() - add_definitions(-DUSE_OPENCV3) -endif() - -if(OS_WIN) - get_filename_component(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}/../bin" ABSOLUTE) -else() - set(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}") -endif() +#LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) # targets diff --git a/tools/dataset/CMakeLists.txt b/tools/dataset/CMakeLists.txt index 404bd33..33d8809 100644 --- a/tools/dataset/CMakeLists.txt +++ b/tools/dataset/CMakeLists.txt @@ -22,15 +22,8 @@ set_outdir( ## record -add_executable(record record.cc dataset.cc) -target_link_libraries(record mynteye ${OpenCV_LIBS}) -target_create_scripts(record DLL_SEARCH_PATHS - ${PRO_DIR}/_install/bin - ${OpenCV_LIB_SEARCH_PATH} +make_executable(record + SRCS record.cc dataset.cc + LINK_LIBS mynteye ${OpenCV_LIBS} + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} ) - -if(OS_WIN) - target_compile_definitions(record - PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES - ) -endif() diff --git a/tools/writer/CMakeLists.txt b/tools/writer/CMakeLists.txt index 7577107..ff9983f 100644 --- a/tools/writer/CMakeLists.txt +++ b/tools/writer/CMakeLists.txt @@ -29,49 +29,26 @@ include_directories( add_library(device_writer STATIC device_writer.cc) target_link_libraries(device_writer mynteye ${OpenCV_LIBS}) -set(LINK_LIBS device_writer) - ## device_info_writer -add_executable(device_info_writer device_info_writer.cc) -target_link_libraries(device_info_writer ${LINK_LIBS}) -target_create_scripts(device_info_writer DLL_SEARCH_PATHS - ${PRO_DIR}/_install/bin - ${OpenCV_LIB_SEARCH_PATH} +make_executable(device_info_writer + SRCS device_info_writer.cc + LINK_LIBS device_writer + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} ) -if(OS_WIN) - target_compile_definitions(device_info_writer - PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES - ) -endif() - ## img_params_writer -add_executable(img_params_writer img_params_writer.cc) -target_link_libraries(img_params_writer ${LINK_LIBS}) -target_create_scripts(img_params_writer DLL_SEARCH_PATHS - ${PRO_DIR}/_install/bin - ${OpenCV_LIB_SEARCH_PATH} +make_executable(img_params_writer + SRCS img_params_writer.cc + LINK_LIBS device_writer + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} ) -if(OS_WIN) - target_compile_definitions(img_params_writer - PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES - ) -endif() - ## imu_params_writer -add_executable(imu_params_writer imu_params_writer.cc) -target_link_libraries(imu_params_writer ${LINK_LIBS}) -target_create_scripts(imu_params_writer DLL_SEARCH_PATHS - ${PRO_DIR}/_install/bin - ${OpenCV_LIB_SEARCH_PATH} +make_executable(imu_params_writer + SRCS imu_params_writer.cc + LINK_LIBS device_writer + DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH} ) - -if(OS_WIN) - target_compile_definitions(imu_params_writer - PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES - ) -endif()