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