1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00
Files
opencv/samples/CMakeLists.txt
T
Maksim Shabunin 2200e13c71 cmake: refactored scripts with samples building:
- allow installing samples sources on all platforms
  even if BUILD_EXAMPLES is disabled,  fixed minor
  issues in sources installation process
- use 'example_<group>_<name>' scheme for target and binary file naming
- use single function for sample executable creation
2018-02-12 18:42:36 +03:00

132 lines
4.3 KiB
CMake
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Utility function: adds sample executable target with name "example_<group>_<file_name>"
# Usage:
# ocv_define_sample(<output target> <relative filename> <group>)
function(ocv_define_sample out_target source sub)
get_filename_component(name "${source}" NAME_WE)
set(the_target "example_${sub}_${name}")
add_executable(${the_target} "${source}")
set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}")
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sub}")
endif()
if(WIN32 AND MSVC AND NOT BUILD_SHARED_LIBS)
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
endif()
if(WIN32)
install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${sub}" COMPONENT samples)
endif()
set(${out_target} ${the_target} PARENT_SCOPE)
endfunction()
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR)
#===================================================================================================
#
# Build as part of OpenCV
#
#===================================================================================================
function(ocv_install_example_src relpath)
if(INSTALL_C_EXAMPLES)
file(GLOB files ${ARGN})
install(FILES ${files}
DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${relpath}"
COMPONENT samples)
endif()
endfunction()
add_subdirectory(cpp)
add_subdirectory(java/tutorial_code)
add_subdirectory(dnn)
add_subdirectory(gpu)
add_subdirectory(tapi)
add_subdirectory(opencl)
if(WIN32 AND HAVE_DIRECTX)
add_subdirectory(directx)
endif()
if((NOT ANDROID) AND HAVE_OPENGL)
add_subdirectory(opengl)
endif()
if(HAVE_OPENVX)
add_subdirectory(openvx)
endif()
if(UNIX AND NOT ANDROID AND (HAVE_VA OR HAVE_VA_INTEL))
add_subdirectory(va_intel)
endif()
if(ANDROID AND BUILD_ANDROID_EXAMPLES)
add_subdirectory(android)
endif()
if(INSTALL_PYTHON_EXAMPLES)
add_subdirectory(python)
endif()
ocv_install_example_src("." CMakeLists.txt)
if(INSTALL_C_EXAMPLES)
install(DIRECTORY data
DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/data"
COMPONENT samples)
endif()
else()
#===================================================================================================
#
# Standalone mode
#
#===================================================================================================
cmake_minimum_required(VERSION 2.8)
project(samples C CXX)
option(BUILD_EXAMPLES "Build samples" ON)
# Assuming following installation folder structure (default for UNIX):
# <install_root>/share/
# └── OpenCV/ <-- OPENCV_CONFIG_INSTALL_PATH
# ├── OpenCVConfig.cmake <-- file to be found by find_package
# ├── ...
# ├── samples/ <-- OPENCV_SAMPLES_SRC_INSTALL_PATH
# │   ├── CMakeLists.txt <-- this file
# │   ├── cpp/
find_package(OpenCV REQUIRED PATHS "..")
function(ocv_install_example_src)
# not used in this branch
endfunction()
if(MSVC)
if(NOT ENABLE_BUILD_HARDENING)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
if(NOT OpenCV_SHARED)
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
if(${flag_var} MATCHES "/MDd")
string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib")
endif()
endif()
add_subdirectory(cpp)
if(WIN32)
add_subdirectory(directx)
endif()
add_subdirectory(dnn)
# add_subdirectory(gpu)
add_subdirectory(opencl)
# add_subdirectory(opengl)
# add_subdirectory(openvx)
add_subdirectory(tapi)
# add_subdirectory(va_intel)
endif()