CMakeLists.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. cmake_minimum_required(VERSION 2.8)
  2. set(ALL_SAMPLES
  3. DumpAllFeatures
  4. ListDevices
  5. LoopDetect
  6. ForceDeviceIP
  7. NetStatistic
  8. DeviceStorage
  9. SimpleView_FetchFrame
  10. SimpleView_Callback
  11. SimpleView_Registration
  12. SimpleView_PixelsRegistration
  13. SimpleView_FetchHisto
  14. SimpleView_MultiDevice
  15. SimpleView_TriggerMode0
  16. SimpleView_TriggerMode1
  17. SimpleView_TriggerMode18
  18. SimpleView_TriggerMode19
  19. SimpleView_TriggerMode20
  20. SimpleView_TriggerMode21
  21. SimpleView_TriggerMode30
  22. SimpleView_TriggerMode31
  23. SimpleView_TriggerMode_M2S1
  24. SimpleView_TriggerMode_M3S1
  25. SimpleView_KeepAlive
  26. SimpleView_TriggerDelay
  27. SimpleView_StreamAsync
  28. SimpleView_StreamAsync1
  29. SimpleView_ImuData
  30. SimpleView_DI_DO
  31. SimpleView_OpenWithIP
  32. SimpleView_HDR
  33. SimpleView_SGBM
  34. )
  35. set(SAMPLES_USED_GLUT
  36. SimpleView_Point3D
  37. SimpleView_Point3D_XYZ48
  38. )
  39. if (MSVC)
  40. option(OpenCV_STATIC "Using static opencv" OFF)
  41. endif()
  42. option(OPENGL_VIEW "Enable GLUT OpenGL point cloud view " OFF)
  43. if (NOT TARGET tycam)
  44. #only build samples
  45. option (OpenCV_STATIC OFF)
  46. set(INCLUDE_PATH ../include)
  47. include_directories(${INCLUDE_PATH})
  48. set(ABSOLUTE_TARGET_LIB tycam)
  49. add_library(${ABSOLUTE_TARGET_LIB} SHARED IMPORTED)
  50. if (MSVC)#for windows
  51. set (LIB_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../lib/win/hostapp/)
  52. if(CMAKE_CL_64) #x64
  53. set_property(TARGET ${ABSOLUTE_TARGET_LIB} PROPERTY IMPORTED_LOCATION ${LIB_ROOT_PATH}/x64/tycam.dll)
  54. set_property(TARGET ${ABSOLUTE_TARGET_LIB} PROPERTY IMPORTED_IMPLIB ${LIB_ROOT_PATH}/x64/tycam.lib)
  55. else()
  56. set_property(TARGET ${ABSOLUTE_TARGET_LIB} PROPERTY IMPORTED_LOCATION ${LIB_ROOT_PATH}/x86/tycam.dll)
  57. set_property(TARGET ${ABSOLUTE_TARGET_LIB} PROPERTY IMPORTED_IMPLIB ${LIB_ROOT_PATH}/x86/tycam.lib)
  58. endif()
  59. else()
  60. if(ARCH)
  61. set_property(TARGET ${ABSOLUTE_TARGET_LIB} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../lib/linux/lib_${ARCH}/libtycam.so)
  62. else()
  63. set(ABSOLUTE_TARGET_LIB -ltycam)
  64. endif()
  65. endif()
  66. endif()
  67. if (MSVC)
  68. if (OpenCV_STATIC)
  69. message("using static opencv")
  70. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
  71. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
  72. endif()
  73. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  74. endif()
  75. # ========================================
  76. # === common, build static lib to speed up
  77. # ========================================
  78. set(COMMON_SOURCES common/MatViewer.cpp common/TYThread.cpp common/ImageSpeckleFilter.cpp common/DepthInpainter.cpp)
  79. add_library(sample_common STATIC ${COMMON_SOURCES})
  80. if(UNIX)
  81. target_link_libraries(sample_common pthread)
  82. endif()
  83. # ========================================
  84. # === OpenCV
  85. # ========================================
  86. find_package(OpenCV REQUIRED)
  87. if (NOT OpenCV_FOUND)
  88. message(FATAL_ERROR "OpenCV library not found")
  89. else()
  90. include_directories(${OpenCV_INCLUDE_DIRS})
  91. include_directories(${OpenCV2_INCLUDE_DIRS})
  92. # if(CMAKE_BUILD_TYPE STREQUAL Debug)
  93. # link_directories(${OpenCV_LIB_DIR_DBG})
  94. # else()
  95. # link_directories(${OpenCV_LIB_DIR_OPT})
  96. # endif()
  97. link_directories(${OpenCV_LIB_DIR})
  98. endif()
  99. # ========================================
  100. # === OpenGL
  101. # ========================================
  102. if (OPENGL_VIEW)
  103. set (CLOUD_VIEW_DIR "${CMAKE_CURRENT_SOURCE_DIR}/common/cloud_viewer/")
  104. file (GLOB viewer_src ${CLOUD_VIEW_DIR}/*.c ${CLOUD_VIEW_DIR}/*.cpp )
  105. include_directories(${CLOUD_VIEW_DIR}/freeglut/include)
  106. add_library(cloud_viewer STATIC ${viewer_src})
  107. target_compile_definitions(cloud_viewer PUBLIC FREEGLUT_STATIC)
  108. if (WIN32)
  109. #build freeglut by ourselves
  110. include(ExternalProject)
  111. ExternalProject_Add( glut_proj
  112. PREFIX "${CMAKE_CURRENT_SOURCE_DIR}"
  113. SOURCE_DIR "${CLOUD_VIEW_DIR}/freeglut"
  114. BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/freeglut_build"
  115. CMAKE_ARGS
  116. -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/freeglut_install
  117. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  118. -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
  119. -DCMAKE_STATIC_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}
  120. -DCMAKE_STATIC_LINKER_FLAGS_DEBUG=${CMAKE_EXE_LINKER_FLAGS_DEBUG}
  121. -DCMAKE_STATIC_LINKER_FLAGS_RELEASE=${CMAKE_EXE_LINKER_FLAGS_RELEASE}
  122. -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
  123. -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
  124. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  125. -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
  126. -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
  127. )
  128. add_library(myglut STATIC IMPORTED)
  129. add_dependencies(myglut glut_proj)
  130. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/freeglut_install/include)
  131. set_target_properties(myglut PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/freeglut_install/include)
  132. set( glut_lib_file ${CMAKE_CURRENT_BINARY_DIR}/freeglut_install/lib/freeglut_staticd.lib)
  133. set_property(TARGET myglut PROPERTY IMPORTED_LOCATION_DEBUG ${glut_lib_file} )
  134. set( glut_lib_file ${CMAKE_CURRENT_BINARY_DIR}/freeglut_install/lib/freeglut_static.lib)
  135. set_property(TARGET myglut PROPERTY IMPORTED_LOCATION ${glut_lib_file} )
  136. add_dependencies(cloud_viewer glut_proj)
  137. target_link_libraries(cloud_viewer PUBLIC myglut)
  138. else()
  139. find_package(GLUT REQUIRED)
  140. find_package(OpenGL REQUIRED)
  141. include_directories(${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIRS})
  142. target_link_libraries(cloud_viewer PUBLIC ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES})
  143. endif()
  144. include_directories(common/cloud_viewer)
  145. set(ALL_SAMPLES ${ALL_SAMPLES} ${SAMPLES_USED_GLUT})
  146. set(CLOUD_VIEWER ${GLUT_LIBRARIES} cloud_viewer)
  147. endif()
  148. #install for sample header file
  149. file(GLOB SAMPLES_INC_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/common/*.h)
  150. install(FILES ${SAMPLES_INC_SRC} DESTINATION samples/common/ )
  151. foreach(sample ${ALL_SAMPLES})
  152. get_filename_component(spath "${sample}" ABSOLUTE )
  153. if (EXISTS "${spath}/")
  154. file(GLOB sources ${sample}/*.cpp)
  155. add_executable(${sample} ${sources})
  156. add_dependencies(${sample} sample_common ${TARGET_LIB})
  157. target_link_libraries(${sample} sample_common ${ABSOLUTE_TARGET_LIB} ${OpenCV_LIBS} ${CLOUD_VIEWER})
  158. set_target_properties(${sample} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
  159. set_target_properties(${sample} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON )
  160. install(TARGETS ${sample} RUNTIME DESTINATION samples/)
  161. endif()
  162. endforeach()