CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR)
  2. #===================================================================================================
  3. #
  4. # Build as part of OpenCV
  5. #
  6. #===================================================================================================
  7. include("${CMAKE_CURRENT_LIST_DIR}/samples_utils.cmake")
  8. function(ocv_install_example_src relpath)
  9. if(INSTALL_C_EXAMPLES)
  10. file(GLOB files ${ARGN})
  11. install(FILES ${files}
  12. DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${relpath}"
  13. COMPONENT samples)
  14. endif()
  15. endfunction()
  16. if((TARGET Threads::Threads OR HAVE_PTHREAD OR MSVC OR APPLE) AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
  17. add_definitions(-DHAVE_THREADS=1)
  18. endif()
  19. add_subdirectory(cpp)
  20. add_subdirectory(java/tutorial_code)
  21. add_subdirectory(dnn)
  22. add_subdirectory(gpu)
  23. add_subdirectory(tapi)
  24. add_subdirectory(opencl)
  25. add_subdirectory(sycl)
  26. if(WIN32 AND HAVE_DIRECTX)
  27. add_subdirectory(directx)
  28. endif()
  29. if((NOT ANDROID) AND HAVE_OPENGL)
  30. add_subdirectory(opengl)
  31. endif()
  32. if(HAVE_OPENVX)
  33. add_subdirectory(openvx)
  34. endif()
  35. if(UNIX AND NOT ANDROID AND HAVE_VA)
  36. add_subdirectory(va_intel)
  37. endif()
  38. if(ANDROID AND (BUILD_ANDROID_EXAMPLES OR INSTALL_ANDROID_EXAMPLES))
  39. add_subdirectory(android)
  40. endif()
  41. if(INSTALL_PYTHON_EXAMPLES)
  42. add_subdirectory(python)
  43. endif()
  44. # The examples in this folder will work with a semihosting version of
  45. # OpenCV. For more information about semihosting, see
  46. # https://developer.arm.com/documentation/100863/latest
  47. if(OPENCV_SEMIHOSTING)
  48. add_subdirectory(semihosting)
  49. endif()
  50. ocv_install_example_src("." CMakeLists.txt samples_utils.cmake)
  51. if(INSTALL_C_EXAMPLES)
  52. install(DIRECTORY data DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}" COMPONENT samples_data)
  53. endif()
  54. else()
  55. #===================================================================================================
  56. #
  57. # Standalone mode
  58. #
  59. #===================================================================================================
  60. cmake_minimum_required(VERSION 3.1)
  61. project(samples C CXX)
  62. option(BUILD_EXAMPLES "Build samples" ON)
  63. # Assuming following installation folder structure (default for UNIX):
  64. # <install_root>/share/
  65. # └── OpenCV/ <-- OPENCV_CONFIG_INSTALL_PATH
  66. # ├── OpenCVConfig.cmake <-- file to be found by find_package
  67. # ├── ...
  68. # ├── samples/ <-- OPENCV_SAMPLES_SRC_INSTALL_PATH
  69. # │   ├── CMakeLists.txt <-- this file
  70. # │   ├── cpp/
  71. find_package(OpenCV REQUIRED PATHS "..")
  72. include("${CMAKE_CURRENT_LIST_DIR}/samples_utils.cmake")
  73. function(ocv_install_example_src)
  74. # not used in this branch
  75. endfunction()
  76. if(MSVC)
  77. if(NOT ENABLE_BUILD_HARDENING)
  78. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  79. endif()
  80. if(NOT OpenCV_SHARED)
  81. foreach(flag_var
  82. CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  83. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  84. CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  85. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  86. if(${flag_var} MATCHES "/MD")
  87. string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
  88. endif()
  89. if(${flag_var} MATCHES "/MDd")
  90. string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
  91. endif()
  92. endforeach(flag_var)
  93. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcrtd.lib")
  94. if(NOT BUILD_WITH_STATIC_CRT)
  95. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib")
  96. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib")
  97. endif()
  98. endif()
  99. endif()
  100. if(OPENCV_EXAMPLES_DISABLE_THREADS)
  101. # nothing
  102. elseif(MSVC OR APPLE)
  103. set(HAVE_THREADS 1)
  104. else()
  105. find_package(Threads)
  106. endif()
  107. if((TARGET Threads::Threads OR HAVE_THREADS) AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
  108. set(HAVE_THREADS 1)
  109. add_definitions(-DHAVE_THREADS=1)
  110. endif()
  111. add_subdirectory(cpp)
  112. if(WIN32)
  113. add_subdirectory(directx)
  114. endif()
  115. add_subdirectory(dnn)
  116. # add_subdirectory(gpu)
  117. add_subdirectory(opencl)
  118. add_subdirectory(sycl)
  119. # add_subdirectory(opengl)
  120. # add_subdirectory(openvx)
  121. add_subdirectory(tapi)
  122. # add_subdirectory(va_intel)
  123. endif()