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