Building VexCL programs with CMakeΒΆ
In order to build a VexCL program with the CMake build system you need just
a couple of lines in your CmakeLists.txt
:
cmake_minimum_required(VERSION 3.1)
project(example)
find_package(VexCL)
add_executable(example example.cpp)
target_link_libraries(example VexCL::OpenCL)
VexCL provides interface targets for the backends supported on the current
system. Possible choices are VexCL::OpenCL
for the OpenCL backend,
VexCL::Compute
for Boost.Compute, VexCL::CUDA
for CUDA, and
VexCL::JIT
for the just-in-time compiled OpenMP kernels.
The targets will take care of the appropriate compiler and linker flags for the
selected backend.
If you are interested in generating all possible backends, you can use
vexcl_add_executables(example example.cpp)
, which will generate up to
four different versions of the same program, with _cl
, _comp
, _cuda
,
and _jit
appended, depending on what backends were discovered. An interface
target is available for you to add dependencies to all targets at once:
vexcl_add_executables(example example.cpp)
target_link_libraries(example INTERFACE MyDependenices)
target_link_libraries(example_cl OpenCLOnlyDependency)
find_package(VexCL)
may be used when VexCL was installed system wide. If
that is not the case, you can just copy the VexCL into a subdirectory of your
project (or use git submodules) and replace the line with
add_subdirectory(vexcl)