Merge pull request #3189 from mshabunin:python_cross_build
[profile/ivi/opencv.git] / samples / CMakeLists.txt
1 # Detect if we want to build samples with library binaries or not
2 if(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
13 add_subdirectory(cpp)
14 add_subdirectory(gpu)
15 add_subdirectory(tapi)
16
17 if(WIN32 AND HAVE_DIRECTX)
18   add_subdirectory(directx)
19 endif()
20
21 if(ANDROID AND BUILD_ANDROID_EXAMPLES)
22   add_subdirectory(android)
23 endif()
24
25 #
26 # END OF BUILD CASE 1: Build samples with library sources
27 #
28 else()
29 #
30 # BUILD CASE 2: Build samples with library binaries
31 #
32 cmake_minimum_required(VERSION 2.8)
33
34 project(samples C CXX)
35 option(BUILD_EXAMPLES "Build samples" ON)
36
37 find_package(OpenCV REQUIRED)
38
39 if(MSVC)
40   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
41
42   if(NOT OpenCV_SHARED)
43     foreach(flag_var
44             CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
45             CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
46             CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
47             CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
48       if(${flag_var} MATCHES "/MD")
49         string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
50       endif()
51       if(${flag_var} MATCHES "/MDd")
52         string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
53       endif()
54     endforeach(flag_var)
55
56     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib")
57     set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib")
58     set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib")
59   endif()
60 endif()
61
62 add_subdirectory(cpp)
63 # FIXIT: can't use cvconfig.h in samples: add_subdirectory(gpu)
64
65 if(WIN32)
66   add_subdirectory(directx)
67 endif()
68
69 #
70 # END OF BUILD CASE 2: Build samples with library binaries
71 #
72 endif()