# Using Thrust with CMake Thrust provides configuration files that simplify using Thrust from other CMake projects. Requirements: - Thrust >= 1.9.10 - CMake >= 3.15 See the [Fixing Legacy FindThrust.cmake](#fixing-legacy-findthrustcmake) section for solutions that work on older Thrust versions. ## User Guide #### Default Configuration (CUDA) Thrust is configured using a `thrust_create_target` CMake function that assembles a complete interface to the Thrust library: ```cmake find_package(Thrust REQUIRED CONFIG) thrust_create_target(Thrust) target_link_libraries(MyProgram Thrust) ``` The first argument is the name of the interface target to create, and any additional options will be used to configure the target. By default, `thrust_create_target` will configure its result to use CUDA acceleration. If desired, `thrust_create_target` may be called multiple times to build several unique Thrust interface targets with different configurations, as detailed below. **Note:** If CMake is unable to locate Thrust, specify the path to Thrust's CMake configuration directory (where this README file is located) as `Thrust_DIR`. If cloning Thrust from github, this would be ``` $ cmake . -DThrust_DIR=/thrust/cmake/ ``` #### TBB / OpenMP To explicitly specify host/device systems, `HOST` and `DEVICE` arguments can be passed to `thrust_create_target`. If an explicit system is not specified, the target will default to using CPP for host and/or CUDA for device. ```cmake thrust_create_target(ThrustTBB DEVICE TBB) thrust_create_target(ThrustOMP HOST CPP DEVICE OMP) ``` will create targets `ThrustTBB` and `ThrustOMP`. Both will use the serial `CPP` host system, but will find and use TBB or OpenMP for the device system. #### Configure Target from Cache Options To allow a Thrust target to be configurable easily via `cmake-gui` or `ccmake`, pass the `FROM_OPTIONS` flag to `thrust_create_target`. This will add `THRUST_HOST_SYSTEM` and `THRUST_DEVICE_SYSTEM` options to the CMake cache that allow selection from the systems supported by this version of Thrust. ```cmake thrust_create_target(Thrust FROM_OPTIONS [HOST_OPTION