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}") message(STATUS "Found glog: ${glog_VERSION}")
if(WITH_API) if(WITH_API)
find_package(OpenCV REQUIRED) include(cmake/DetectOpenCV.cmake)
message(STATUS "Found OpenCV: ${OpenCV_VERSION}")
if(OpenCV_VERSION VERSION_LESS 3.0)
add_definitions(-DUSE_OPENCV2)
else()
add_definitions(-DUSE_OPENCV3)
endif()
endif() endif()
LIST(APPEND CMAKE_MODULE_PATH cmake) LIST(APPEND CMAKE_MODULE_PATH cmake)

View File

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

View File

@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake)
cmake_include_guard()
include(CMakeParseArguments) include(CMakeParseArguments)
set(CUR_DIR ${CMAKE_CURRENT_LIST_DIR}) set(CUR_DIR ${CMAKE_CURRENT_LIST_DIR})

View File

@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake)
cmake_include_guard()
if(MSVC) if(MSVC)
# Support For C++11/14/17 Features (Modern C++) # 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) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
include(${PRO_DIR}/cmake/Common.cmake) include(${PRO_DIR}/cmake/Common.cmake)
include(${PRO_DIR}/cmake/Utils.cmake)
# options # options
@ -54,21 +55,9 @@ LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake)
find_package(mynteye REQUIRED) find_package(mynteye REQUIRED)
message(STATUS "Found mynteye: ${mynteye_VERSION}") message(STATUS "Found mynteye: ${mynteye_VERSION}")
LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) include(${PRO_DIR}/cmake/DetectOpenCV.cmake)
find_package(OpenCV REQUIRED) #LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake)
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()
# targets # targets

View File

@ -22,15 +22,8 @@ set_outdir(
## camera_a ## camera_a
add_executable(camera_a camera.cc) make_executable(camera_a
target_link_libraries(camera_a mynteye ${OpenCV_LIBS}) SRCS camera.cc
target_create_scripts(camera_a DLL_SEARCH_PATHS LINK_LIBS mynteye ${OpenCV_LIBS}
${PRO_DIR}/_install/bin DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
${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 ## camera_d
add_executable(camera_d camera.cc) make_executable(camera_d
target_link_libraries(camera_d mynteye ${OpenCV_LIBS}) SRCS camera.cc
target_create_scripts(camera_d DLL_SEARCH_PATHS LINK_LIBS mynteye ${OpenCV_LIBS}
${PRO_DIR}/_install/bin DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
${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}" "${OUT_DIR}/bin/${DIR_NAME}"
) )
# make_executable(NAME # make_executable2(NAME
# [SRCS src1 src2 ...]) # [SRCS src1 src2 ...]
# [WITH_OPENCV] # [WITH_OPENCV]
# [WITH_PCL]) # [WITH_PCL])
macro(make_executable NAME) macro(make_executable2 NAME)
set(options WITH_OPENCV WITH_PCL) set(options WITH_OPENCV WITH_PCL)
set(oneValueArgs) set(oneValueArgs)
set(multiValueArgs SRCS) set(multiValueArgs SRCS)
@ -88,29 +88,29 @@ endif()
# data # data
make_executable(get_device_info SRCS data/get_device_info.cc) make_executable2(get_device_info SRCS data/get_device_info.cc)
make_executable(get_img_params SRCS data/get_img_params.cc) make_executable2(get_img_params SRCS data/get_img_params.cc)
make_executable(get_imu_params SRCS data/get_imu_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_executable2(get_stereo SRCS data/get_stereo.cc WITH_OPENCV)
make_executable(get_stereo_rectified SRCS data/get_stereo_rectified.cc WITH_OPENCV) make_executable2(get_stereo_rectified SRCS data/get_stereo_rectified.cc WITH_OPENCV)
make_executable(get_disparity SRCS data/get_disparity.cc WITH_OPENCV) make_executable2(get_disparity SRCS data/get_disparity.cc WITH_OPENCV)
make_executable(get_depth SRCS data/get_depth.cc WITH_OPENCV) make_executable2(get_depth SRCS data/get_depth.cc WITH_OPENCV)
if(PCL_FOUND) if(PCL_FOUND)
make_executable(get_points make_executable2(get_points
SRCS data/get_points.cc data/pc_viewer.cc SRCS data/get_points.cc data/pc_viewer.cc
WITH_OPENCV WITH_PCL WITH_OPENCV WITH_PCL
) )
endif() endif()
make_executable(get_imu SRCS data/get_imu.cc data/cv_painter.cc WITH_OPENCV) make_executable2(get_imu SRCS data/get_imu.cc data/cv_painter.cc WITH_OPENCV)
make_executable(get_from_callbacks make_executable2(get_from_callbacks
SRCS data/get_from_callbacks.cc data/cv_painter.cc SRCS data/get_from_callbacks.cc data/cv_painter.cc
WITH_OPENCV 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 # control
make_executable(ctrl_infrared SRCS control/infrared.cc WITH_OPENCV) make_executable2(ctrl_infrared SRCS control/infrared.cc WITH_OPENCV)
endif() endif()

View File

@ -26,15 +26,8 @@ include_directories(
## camera_u ## camera_u
add_executable(camera_u camera.cc) make_executable(camera_u
target_link_libraries(camera_u mynteye ${OpenCV_LIBS}) SRCS camera.cc
target_create_scripts(camera_u DLL_SEARCH_PATHS LINK_LIBS mynteye ${OpenCV_LIBS}
${PRO_DIR}/_install/bin DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
${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) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
include(${PRO_DIR}/cmake/Common.cmake) include(${PRO_DIR}/cmake/Common.cmake)
include(${PRO_DIR}/cmake/Utils.cmake)
# flags # flags
@ -64,10 +65,9 @@ LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake)
find_package(mynteye REQUIRED) find_package(mynteye REQUIRED)
message(STATUS "Found mynteye: ${mynteye_VERSION}") message(STATUS "Found mynteye: ${mynteye_VERSION}")
LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) include(${PRO_DIR}/cmake/DetectOpenCV.cmake)
find_package(OpenCV REQUIRED) #LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake)
message(STATUS "Found OpenCV: ${OpenCV_VERSION}")
## gtest ## gtest
@ -105,27 +105,8 @@ include_directories(
file(GLOB TEST_INTERNAL_SRC "internal/*.cc") file(GLOB TEST_INTERNAL_SRC "internal/*.cc")
file(GLOB TEST_PUBLIC_SRC "public/*.cc") file(GLOB TEST_PUBLIC_SRC "public/*.cc")
add_executable(${PROJECT_NAME} make_executable(${PROJECT_NAME}
gtest_main.cc SRCS gtest_main.cc ${TEST_INTERNAL_SRC} ${TEST_PUBLIC_SRC}
${TEST_INTERNAL_SRC} LINK_LIBS mynteye ${GTEST_LIBS} ${OpenCV_LIBS}
${TEST_PUBLIC_SRC} 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) get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
include(${PRO_DIR}/cmake/Common.cmake) include(${PRO_DIR}/cmake/Common.cmake)
include(${PRO_DIR}/cmake/Utils.cmake)
# flags # flags
@ -50,21 +51,9 @@ LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake)
find_package(mynteye REQUIRED) find_package(mynteye REQUIRED)
message(STATUS "Found mynteye: ${mynteye_VERSION}") message(STATUS "Found mynteye: ${mynteye_VERSION}")
LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake) include(${PRO_DIR}/cmake/DetectOpenCV.cmake)
find_package(OpenCV REQUIRED) #LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake)
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()
# targets # targets

View File

@ -22,15 +22,8 @@ set_outdir(
## record ## record
add_executable(record record.cc dataset.cc) make_executable(record
target_link_libraries(record mynteye ${OpenCV_LIBS}) SRCS record.cc dataset.cc
target_create_scripts(record DLL_SEARCH_PATHS LINK_LIBS mynteye ${OpenCV_LIBS}
${PRO_DIR}/_install/bin DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
${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) add_library(device_writer STATIC device_writer.cc)
target_link_libraries(device_writer mynteye ${OpenCV_LIBS}) target_link_libraries(device_writer mynteye ${OpenCV_LIBS})
set(LINK_LIBS device_writer)
## device_info_writer ## device_info_writer
add_executable(device_info_writer device_info_writer.cc) make_executable(device_info_writer
target_link_libraries(device_info_writer ${LINK_LIBS}) SRCS device_info_writer.cc
target_create_scripts(device_info_writer DLL_SEARCH_PATHS LINK_LIBS device_writer
${PRO_DIR}/_install/bin DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
${OpenCV_LIB_SEARCH_PATH}
) )
if(OS_WIN)
target_compile_definitions(device_info_writer
PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
)
endif()
## img_params_writer ## img_params_writer
add_executable(img_params_writer img_params_writer.cc) make_executable(img_params_writer
target_link_libraries(img_params_writer ${LINK_LIBS}) SRCS img_params_writer.cc
target_create_scripts(img_params_writer DLL_SEARCH_PATHS LINK_LIBS device_writer
${PRO_DIR}/_install/bin DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
${OpenCV_LIB_SEARCH_PATH}
) )
if(OS_WIN)
target_compile_definitions(img_params_writer
PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
)
endif()
## imu_params_writer ## imu_params_writer
add_executable(imu_params_writer imu_params_writer.cc) make_executable(imu_params_writer
target_link_libraries(imu_params_writer ${LINK_LIBS}) SRCS imu_params_writer.cc
target_create_scripts(imu_params_writer DLL_SEARCH_PATHS LINK_LIBS device_writer
${PRO_DIR}/_install/bin DLL_SEARCH_PATHS ${PRO_DIR}/_install/bin ${OpenCV_LIB_SEARCH_PATH}
${OpenCV_LIB_SEARCH_PATH}
) )
if(OS_WIN)
target_compile_definitions(imu_params_writer
PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
)
endif()