1# Detect if we want to build samples with library binaries or not 2if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR) 3# 4# BUILD CASE 1: Build samples with library sources 5# 6 7 8# ---------------------------------------------------------------------------- 9# CMake file for samples. See root CMakeLists.txt 10# 11# ---------------------------------------------------------------------------- 12 13add_subdirectory(cpp) 14add_subdirectory(gpu) 15add_subdirectory(tapi) 16 17if(WIN32 AND HAVE_DIRECTX) 18 add_subdirectory(directx) 19endif() 20 21if(ANDROID AND BUILD_ANDROID_EXAMPLES) 22 add_subdirectory(android) 23endif() 24 25if(INSTALL_PYTHON_EXAMPLES) 26 add_subdirectory(python2) 27endif() 28 29# 30# END OF BUILD CASE 1: Build samples with library sources 31# 32else() 33# 34# BUILD CASE 2: Build samples with library binaries 35# 36cmake_minimum_required(VERSION 2.8) 37 38project(samples C CXX) 39option(BUILD_EXAMPLES "Build samples" ON) 40 41find_package(OpenCV REQUIRED) 42 43if(MSVC) 44 add_definitions(-D_CRT_SECURE_NO_WARNINGS) 45 46 if(NOT OpenCV_SHARED) 47 foreach(flag_var 48 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE 49 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO 50 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE 51 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) 52 if(${flag_var} MATCHES "/MD") 53 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") 54 endif() 55 if(${flag_var} MATCHES "/MDd") 56 string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}") 57 endif() 58 endforeach(flag_var) 59 60 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib") 61 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib") 62 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib") 63 endif() 64endif() 65 66add_subdirectory(cpp) 67# FIXIT: can't use cvconfig.h in samples: add_subdirectory(gpu) 68 69if(WIN32) 70 add_subdirectory(directx) 71endif() 72 73# 74# END OF BUILD CASE 2: Build samples with library binaries 75# 76endif() 77