From a2bc075924fb393a068d3097da40e2c2f01d1b81 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Mon, 25 Jun 2018 17:02:58 +0300 Subject: [PATCH] cmake: function for application creation (#11736) * apps: add Win32 friendly opencv_version app Improve experience of launching app from explorer: - application just flash (open/close) the console window Suggested Win32 application flavor additionally shows MessageBox and waits for User interaction. * cmake: added unified application creation function --- apps/CMakeLists.txt | 33 ++++++++++++++ apps/annotation/CMakeLists.txt | 39 ++-------------- apps/createsamples/CMakeLists.txt | 40 ++--------------- apps/interactive-calibration/CMakeLists.txt | 41 ++--------------- apps/traincascade/CMakeLists.txt | 45 ++----------------- apps/version/CMakeLists.txt | 50 ++------------------- apps/visualisation/CMakeLists.txt | 39 ++-------------- 7 files changed, 52 insertions(+), 235 deletions(-) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 95e98e6e08..260a08fab6 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,6 +1,39 @@ add_definitions(-D__OPENCV_BUILD=1) add_definitions(-D__OPENCV_APPS=1) +# Unified function for creating OpenCV applications: +# ocv_add_application(tgt [MODULES [ ...]] SRCS [ ...]) +function(ocv_add_application the_target) + cmake_parse_arguments(APP "" "" "MODULES;SRCS" ${ARGN}) + ocv_check_dependencies(${APP_MODULES}) + if(NOT OCV_DEPENDENCIES_FOUND) + return() + endif() + + project(${the_target}) + ocv_target_include_modules_recurse(${the_target} ${APP_MODULES}) + ocv_target_include_directories(${the_target} PRIVATE "${OpenCV_SOURCE_DIR}/include/opencv") + ocv_add_executable(${the_target} ${APP_SRCS}) + ocv_target_link_libraries(${the_target} ${APP_MODULES}) + set_target_properties(${the_target} PROPERTIES + DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" + ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} + RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} + OUTPUT_NAME "${the_target}") + + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${the_target} PROPERTIES FOLDER "applications") + endif() + + if(INSTALL_CREATE_DISTRIB) + if(BUILD_SHARED_LIBS) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) + endif() + else() + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) + endif() +endfunction() + link_libraries(${OPENCV_LINKER_LIBS}) macro(ocv_add_app directory) diff --git a/apps/annotation/CMakeLists.txt b/apps/annotation/CMakeLists.txt index 9288e86b42..a30846db41 100644 --- a/apps/annotation/CMakeLists.txt +++ b/apps/annotation/CMakeLists.txt @@ -1,36 +1,3 @@ -SET(OPENCV_ANNOTATION_DEPS opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio) -ocv_check_dependencies(${OPENCV_ANNOTATION_DEPS}) - -if(NOT OCV_DEPENDENCIES_FOUND) - return() -endif() - -project(annotation) -set(the_target opencv_annotation) - -ocv_target_include_directories(${the_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv") -ocv_target_include_modules_recurse(${the_target} ${OPENCV_ANNOTATION_DEPS}) - -file(GLOB SRCS *.cpp) - -set(annotation_files ${SRCS}) -ocv_add_executable(${the_target} ${annotation_files}) -ocv_target_link_libraries(${the_target} ${OPENCV_ANNOTATION_DEPS}) - -set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - OUTPUT_NAME "opencv_annotation") - -if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "applications") -endif() - -if(INSTALL_CREATE_DISTRIB) - if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) - endif() -else() - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) -endif() +ocv_add_application(opencv_annotation + MODULES opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio + SRCS opencv_annotation.cpp) diff --git a/apps/createsamples/CMakeLists.txt b/apps/createsamples/CMakeLists.txt index a285c69e41..7fb2b679c2 100644 --- a/apps/createsamples/CMakeLists.txt +++ b/apps/createsamples/CMakeLists.txt @@ -1,38 +1,4 @@ -set(OPENCV_CREATESAMPLES_DEPS opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs opencv_highgui opencv_calib3d opencv_features2d opencv_videoio) -ocv_check_dependencies(${OPENCV_CREATESAMPLES_DEPS}) - -if(NOT OCV_DEPENDENCIES_FOUND) - return() -endif() - -project(createsamples) -set(the_target opencv_createsamples) - -ocv_target_include_directories(${the_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv") -ocv_target_include_modules_recurse(${the_target} ${OPENCV_CREATESAMPLES_DEPS}) - file(GLOB SRCS *.cpp) -file(GLOB HDRS *.h*) - -set(createsamples_files ${SRCS} ${HDRS}) - -ocv_add_executable(${the_target} ${createsamples_files}) -ocv_target_link_libraries(${the_target} ${OPENCV_CREATESAMPLES_DEPS}) - -set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - OUTPUT_NAME "opencv_createsamples") - -if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "applications") -endif() - -if(INSTALL_CREATE_DISTRIB) - if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) - endif() -else() - install(TARGETS ${the_target} OPTIONAL RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) -endif() +ocv_add_application(opencv_createsamples + MODULES opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs opencv_highgui opencv_calib3d opencv_features2d opencv_videoio + SRCS ${SRCS}) diff --git a/apps/interactive-calibration/CMakeLists.txt b/apps/interactive-calibration/CMakeLists.txt index 4a1a7446a8..dacbb13c79 100644 --- a/apps/interactive-calibration/CMakeLists.txt +++ b/apps/interactive-calibration/CMakeLists.txt @@ -1,41 +1,6 @@ -set(OPENCV_INTERACTIVECALIBRATION_DEPS opencv_core opencv_imgproc opencv_features2d opencv_highgui opencv_calib3d opencv_videoio) +set(DEPS opencv_core opencv_imgproc opencv_features2d opencv_highgui opencv_calib3d opencv_videoio) if(${BUILD_opencv_aruco}) - list(APPEND OPENCV_INTERACTIVECALIBRATION_DEPS opencv_aruco) + list(APPEND DEPS opencv_aruco) endif() -ocv_check_dependencies(${OPENCV_INTERACTIVECALIBRATION_DEPS}) - -if(NOT OCV_DEPENDENCIES_FOUND) - return() -endif() - -project(interactive-calibration) -set(the_target opencv_interactive-calibration) - -ocv_target_include_directories(${the_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv") -ocv_target_include_modules_recurse(${the_target} ${OPENCV_INTERACTIVECALIBRATION_DEPS}) - file(GLOB SRCS *.cpp) -file(GLOB HDRS *.h*) - -set(interactive-calibration_files ${SRCS} ${HDRS}) - -ocv_add_executable(${the_target} ${interactive-calibration_files}) -ocv_target_link_libraries(${the_target} ${OPENCV_INTERACTIVECALIBRATION_DEPS}) - -set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - OUTPUT_NAME "opencv_interactive-calibration") - -if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "applications") -endif() - -if(INSTALL_CREATE_DISTRIB) - if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) - endif() -else() - install(TARGETS ${the_target} OPTIONAL RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) -endif() +ocv_add_application(opencv_interactive-calibration MODULES ${DEPS} SRCS ${SRCS}) diff --git a/apps/traincascade/CMakeLists.txt b/apps/traincascade/CMakeLists.txt index 96b9781067..ef80ce8b2f 100644 --- a/apps/traincascade/CMakeLists.txt +++ b/apps/traincascade/CMakeLists.txt @@ -1,42 +1,5 @@ -set(OPENCV_TRAINCASCADE_DEPS opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs opencv_highgui opencv_calib3d opencv_features2d) -ocv_check_dependencies(${OPENCV_TRAINCASCADE_DEPS}) - -if(NOT OCV_DEPENDENCIES_FOUND) - return() -endif() - -project(traincascade) -set(the_target opencv_traincascade) - -ocv_warnings_disable(CMAKE_CXX_FLAGS -Woverloaded-virtual - -Winconsistent-missing-override -Wsuggest-override -) - -ocv_target_include_directories(${the_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv") -ocv_target_include_modules_recurse(${the_target} ${OPENCV_TRAINCASCADE_DEPS}) - +ocv_warnings_disable(CMAKE_CXX_FLAGS -Woverloaded-virtual -Winconsistent-missing-override -Wsuggest-override) file(GLOB SRCS *.cpp) -file(GLOB HDRS *.h*) - -set(traincascade_files ${SRCS} ${HDRS}) - -ocv_add_executable(${the_target} ${traincascade_files}) -ocv_target_link_libraries(${the_target} ${OPENCV_TRAINCASCADE_DEPS}) - -set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - OUTPUT_NAME "opencv_traincascade") - -if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "applications") -endif() - -if(INSTALL_CREATE_DISTRIB) - if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) - endif() -else() - install(TARGETS ${the_target} OPTIONAL RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) -endif() +ocv_add_application(opencv_traincascade + MODULES opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs opencv_highgui opencv_calib3d opencv_features2d + SRCS ${SRCS}) diff --git a/apps/version/CMakeLists.txt b/apps/version/CMakeLists.txt index cc4abb33aa..89e739b1ba 100644 --- a/apps/version/CMakeLists.txt +++ b/apps/version/CMakeLists.txt @@ -1,49 +1,5 @@ -set(OPENCV_APPLICATION_DEPS opencv_core) -ocv_check_dependencies(${OPENCV_APPLICATION_DEPS}) -if(NOT OCV_DEPENDENCIES_FOUND) - return() -endif() - -project(opencv_version) -set(the_target opencv_version) -ocv_target_include_modules_recurse(${the_target} ${OPENCV_APPLICATION_DEPS}) -ocv_add_executable(${the_target} opencv_version.cpp) -ocv_target_link_libraries(${the_target} ${OPENCV_APPLICATION_DEPS}) - -set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - OUTPUT_NAME "opencv_version") - -set_target_properties(${the_target} PROPERTIES FOLDER "applications") - -if(INSTALL_CREATE_DISTRIB) - if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT libs) - endif() -else() - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs) -endif() - +ocv_add_application(opencv_version MODULES opencv_core SRCS opencv_version.cpp) if(WIN32) - project(opencv_version_win32) - set(the_target opencv_version_win32) - ocv_target_include_modules_recurse(${the_target} ${OPENCV_APPLICATION_DEPS}) - ocv_add_executable(${the_target} opencv_version.cpp) - ocv_target_link_libraries(${the_target} ${OPENCV_APPLICATION_DEPS}) - target_compile_definitions(${the_target} PRIVATE "OPENCV_WIN32_API=1") - set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - OUTPUT_NAME "opencv_version_win32") - - set_target_properties(${the_target} PROPERTIES FOLDER "applications") - - if(INSTALL_CREATE_DISTRIB) - if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT libs) - endif() - else() - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs) - endif() + ocv_add_application(opencv_version_win32 MODULES opencv_core SRCS opencv_version.cpp) + target_compile_definitions(opencv_version_win32 PRIVATE "OPENCV_WIN32_API=1") endif() diff --git a/apps/visualisation/CMakeLists.txt b/apps/visualisation/CMakeLists.txt index 6f748103e4..eaddf776ec 100644 --- a/apps/visualisation/CMakeLists.txt +++ b/apps/visualisation/CMakeLists.txt @@ -1,36 +1,3 @@ -SET(OPENCV_VISUALISATION_DEPS opencv_core opencv_highgui opencv_imgproc opencv_videoio opencv_imgcodecs) -ocv_check_dependencies(${OPENCV_VISUALISATION_DEPS}) - -if(NOT OCV_DEPENDENCIES_FOUND) - return() -endif() - -project(visualisation) -set(the_target opencv_visualisation) - -ocv_target_include_directories(${the_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv") -ocv_target_include_modules_recurse(${the_target} ${OPENCV_VISUALISATION_DEPS}) - -file(GLOB SRCS *.cpp) - -set(visualisation_files ${SRCS}) -ocv_add_executable(${the_target} ${visualisation_files}) -ocv_target_link_libraries(${the_target} ${OPENCV_VISUALISATION_DEPS}) - -set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} - RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - OUTPUT_NAME "opencv_visualisation") - -if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "applications") -endif() - -if(INSTALL_CREATE_DISTRIB) - if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) - endif() -else() - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) -endif() +ocv_add_application(opencv_visualisation + MODULES opencv_core opencv_highgui opencv_imgproc opencv_videoio opencv_imgcodecs + SRCS opencv_visualisation.cpp)