Update CMakeLists.txt

This commit is contained in:
John Zhao 2018-05-11 16:15:26 +08:00
parent 76d12ccec7
commit ff70cc47f3
16 changed files with 171 additions and 156 deletions

View File

@ -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)

View File

@ -31,6 +31,10 @@ help:
.PHONY: help
all: test tools samples
.PHONY: all
# doc
apidoc:

View File

@ -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})

View File

@ -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++)

30
cmake/DetectOpenCV.cmake Normal file
View File

@ -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()

23
cmake/IncludeGuard.cmake Normal file
View File

@ -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()

51
cmake/Utils.cmake Normal file
View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -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()