1 cmake_minimum_required(VERSION 3.22.1)
 2 project(opencl_backend)
 3 
 4 set(CMAKE_CXX_STANDARD 14)
 5 
 6 find_package(OpenCL)
 7 if(OPENCL_FOUND)
 8     message("OPENCL")
 9     if ("${OPENCL_BACKEND}EMPTY" STREQUAL "EMPTY")
10         set (OPENCL_BACKEND "${CMAKE_SOURCE_DIR}")
11         message("OPENCL_BACKEND=${OPENCL_BACKEND}")
12     endif()
13 
14     if ("${SHARED_BACKEND}EMPTY" STREQUAL "EMPTY")
15         set (SHARED_BACKEND "${CMAKE_SOURCE_DIR}/../shared")
16         message("SHARED_BACKEND=${SHARED_BACKEND}")
17     endif()
18 
19     if (APPLE)
20        set(OPENCL_INCLUDE_DIR "-framework OpenCL")
21        set(OPENCL_LIB "-framework OpenCL")
22     else()
23        set(OPENCL_LIB "OpenCL")
24     endif()
25 
26     include_directories(
27         ${OPENCL_BACKEND}/include
28         ${SHARED_BACKEND}/include
29         ${OPENCL_INCLUDE_DIR}
30     )
31     link_directories(
32         ${CMAKE_BINARY_DIR}
33     )
34 
35     add_library(opencl_backend SHARED
36         ${SHARED_BACKEND}/cpp/shared.cpp
37         ${SHARED_BACKEND}/include/shared.h
38         ${SHARED_BACKEND}/cpp/buffer.cpp
39         ${SHARED_BACKEND}/include/buffer.h
40         ${SHARED_BACKEND}/cpp/schema_cursor.cpp
41         ${SHARED_BACKEND}/include/schema_cursor.h
42         ${SHARED_BACKEND}/cpp/buffer_cursor.cpp
43         ${SHARED_BACKEND}/include/buffer_cursor.h
44         ${SHARED_BACKEND}/cpp/hex.cpp
45         ${SHARED_BACKEND}/include/hex.h
46         ${SHARED_BACKEND}/cpp/json.cpp
47         ${SHARED_BACKEND}/include/json.h
48         ${SHARED_BACKEND}/cpp/fsutil.cpp
49         ${SHARED_BACKEND}/include/fsutil.h
50         ${SHARED_BACKEND}/cpp/strutil.cpp
51         ${SHARED_BACKEND}/include/strutil.h
52 
53         ${OPENCL_BACKEND}/include/opencl_backend.h
54         ${OPENCL_BACKEND}/cpp/opencl_backend.cpp
55         ${OPENCL_BACKEND}/cpp/opencl_backend_buffer.cpp
56         ${OPENCL_BACKEND}/cpp/opencl_backend_info.cpp
57         ${OPENCL_BACKEND}/cpp/opencl_backend_queue.cpp
58         ${OPENCL_BACKEND}/cpp/opencl_backend_kernel.cpp
59         ${OPENCL_BACKEND}/cpp/opencl_backend_program.cpp
60     )
61 
62     target_link_libraries(opencl_backend
63         ${OPENCL_LIB}
64     )
65 
66     add_executable(opencl_info
67             ${OPENCL_BACKEND}/include/opencl_backend.h
68             ${OPENCL_BACKEND}/cpp/info.cpp
69     )
70     add_executable(opencl_squares
71             ${OPENCL_BACKEND}/include/opencl_backend.h
72             ${OPENCL_BACKEND}/cpp/squares.cpp
73         )
74 
75     target_link_libraries(opencl_squares
76         opencl_backend
77         ${OPENCL_LIB}
78     )
79     target_link_libraries(opencl_info
80         opencl_backend
81         ${OPENCL_LIB}
82     )
83 
84     add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/extractFile
85             COMMAND echo jextract stuff
86             #COMMAND BANNER jextract stuff
87             COMMAND touch ${CMAKE_BINARY_DIR}/extractFile
88             #COMMAND ${CMAKE_COMMAND} -E touch ${LIBFOO_TAR_HEADERS}
89             WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
90             #DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/libfoo/foo.tar"
91             COMMENT "Extracting opencl"
92             VERBATIM
93     )
94 
95     add_custom_target(extract DEPENDS ${CMAKE_BINARY_DIR}/extractFile)
96 
97 endif()