CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # ---------------------------------------------------------------------------
  2. # Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. #
  4. # Distributed under the Boost Software License, Version 1.0
  5. # See accompanying file LICENSE_1_0.txt or copy at
  6. # http://www.boost.org/LICENSE_1_0.txt
  7. #
  8. # ---------------------------------------------------------------------------
  9. include_directories(../include)
  10. set(EXAMPLES
  11. amd_cpp_kernel
  12. black_scholes
  13. copy_data
  14. fizz_buzz
  15. hello_world
  16. host_sort
  17. inline_ptx
  18. longest_vector
  19. list_devices
  20. mapped_view
  21. memory_limits
  22. monte_carlo
  23. point_centroid
  24. price_cross
  25. print_vector
  26. sort_vector
  27. simple_kernel
  28. time_copy
  29. transform_sqrt
  30. vector_addition
  31. simple_moving_average
  32. matrix_transpose
  33. )
  34. # boost library link dependencies
  35. set(EXAMPLE_BOOST_COMPONENTS program_options)
  36. if (${BOOST_COMPUTE_USE_OFFLINE_CACHE})
  37. set(EXAMPLE_BOOST_COMPONENTS ${EXAMPLE_BOOST_COMPONENTS} system filesystem)
  38. endif()
  39. if(${BOOST_COMPUTE_THREAD_SAFE} AND NOT ${BOOST_COMPUTE_USE_CPP11})
  40. set(EXAMPLE_BOOST_COMPONENTS ${EXAMPLE_BOOST_COMPONENTS} system thread)
  41. endif()
  42. if(MSVC AND EXAMPLE_BOOST_COMPONENTS)
  43. set(EXAMPLE_BOOST_COMPONENTS ${EXAMPLE_BOOST_COMPONENTS} chrono)
  44. endif()
  45. if(EXAMPLE_BOOST_COMPONENTS)
  46. list(REMOVE_DUPLICATES EXAMPLE_BOOST_COMPONENTS)
  47. endif()
  48. find_package(Boost 1.54 REQUIRED COMPONENTS ${EXAMPLE_BOOST_COMPONENTS})
  49. include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
  50. foreach(EXAMPLE ${EXAMPLES})
  51. add_executable(${EXAMPLE} ${EXAMPLE}.cpp)
  52. target_link_libraries(${EXAMPLE} ${OpenCL_LIBRARIES} ${Boost_LIBRARIES})
  53. # add example program to list of tests (if testing is enabled)
  54. if(${BOOST_COMPUTE_BUILD_TESTS})
  55. add_test("example.${EXAMPLE}" ${EXAMPLE})
  56. endif()
  57. endforeach()
  58. # opencl test example
  59. add_executable(opencl_test opencl_test.cpp)
  60. target_link_libraries(opencl_test ${OpenCL_LIBRARIES})
  61. # eigen examples
  62. if(${BOOST_COMPUTE_HAVE_EIGEN})
  63. find_package(Eigen REQUIRED)
  64. include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS})
  65. add_executable(batched_determinant batched_determinant.cpp)
  66. target_link_libraries(batched_determinant ${OpenCL_LIBRARIES} ${Boost_LIBRARIES})
  67. endif()
  68. # opencv examples
  69. if(${BOOST_COMPUTE_HAVE_OPENCV})
  70. find_package(OpenCV REQUIRED)
  71. include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
  72. set(OPENCV_EXAMPLES
  73. k_means
  74. opencv_flip
  75. random_walk
  76. opencv_optical_flow
  77. opencv_convolution
  78. opencv_sobel_filter
  79. opencv_histogram
  80. )
  81. foreach(EXAMPLE ${OPENCV_EXAMPLES})
  82. add_executable(${EXAMPLE} ${EXAMPLE}.cpp)
  83. target_link_libraries(${EXAMPLE} ${OpenCL_LIBRARIES} ${Boost_LIBRARIES} ${OpenCV_LIBS})
  84. endforeach()
  85. endif()
  86. # opengl/vtk examples
  87. if(${BOOST_COMPUTE_HAVE_VTK})
  88. find_package(VTK REQUIRED)
  89. include(${VTK_USE_FILE})
  90. add_executable(opengl_sphere opengl_sphere.cpp)
  91. target_link_libraries(opengl_sphere ${OpenCL_LIBRARIES} ${Boost_LIBRARIES} ${VTK_LIBRARIES})
  92. if(APPLE)
  93. target_link_libraries(opengl_sphere "-framework OpenGL")
  94. elseif(UNIX)
  95. target_link_libraries(opengl_sphere GL)
  96. endif()
  97. endif()
  98. # qt examples
  99. if(${BOOST_COMPUTE_HAVE_QT})
  100. # look for Qt4 in the first place
  101. find_package(Qt4 QUIET)
  102. if(${QT4_FOUND})
  103. # build with Qt4
  104. find_package(Qt4 REQUIRED COMPONENTS QtCore QtGui QtOpenGL)
  105. set(QT_USE_QTOPENGL TRUE)
  106. include(${QT_USE_FILE})
  107. else()
  108. # look for Qt5
  109. find_package(Qt5Widgets QUIET)
  110. if(${Qt5Widgets_FOUND})
  111. # build with Qt5
  112. find_package(Qt5Core REQUIRED)
  113. find_package(Qt5Widgets REQUIRED)
  114. find_package(Qt5OpenGL REQUIRED)
  115. include_directories(${Qt5OpenGL_INCLUDE_DIRS})
  116. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5OpenGL_EXECUTABLE_COMPILE_FLAGS}")
  117. set(QT_LIBRARIES ${Qt5OpenGL_LIBRARIES})
  118. else()
  119. # no valid Qt framework found
  120. message(FATAL_ERROR "Error: Did not find Qt4 or Qt5")
  121. endif()
  122. endif()
  123. # required by both versions
  124. set(CMAKE_AUTOMOC TRUE)
  125. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  126. # add examples
  127. add_executable(qimage_blur qimage_blur.cpp)
  128. target_link_libraries(qimage_blur ${OpenCL_LIBRARIES} ${Boost_LIBRARIES} ${QT_LIBRARIES})
  129. set(QT_OPENGL_EXAMPLES
  130. mandelbrot
  131. nbody
  132. resize_image
  133. )
  134. foreach(EXAMPLE ${QT_OPENGL_EXAMPLES})
  135. add_executable(${EXAMPLE} ${EXAMPLE}.cpp)
  136. target_link_libraries(${EXAMPLE} ${OpenCL_LIBRARIES} ${Boost_LIBRARIES} ${QT_LIBRARIES})
  137. if(APPLE)
  138. target_link_libraries(${EXAMPLE} "-framework OpenGL")
  139. elseif(UNIX)
  140. target_link_libraries(${EXAMPLE} GL)
  141. endif()
  142. endforeach()
  143. endif()