set source file property for all .cpp files of a target
I am working on a library that allows to offload functions to different processor types like CPUs, Nvidia GPUs or AMD GPUs. Therefore CMake has to handle different configurations depending on the available SDK. For example, a foo.cpp
can be compiled with the nvcc
if the CUDA SDK is available, or with the g++
if not. Therefore, we need to set the language property of each .cpp
file to CUDA. At the moment, this is done by a macro. But we want to change cmake to a target_link_libraries
version, which means you only need to link your target with alpaka::cuda
and the .cpp
files will be compiled with the nvcc. So I need a generic approach to set the language of all .cpp
files. Something like: set_source_files_properties("*.cpp" PROPERTIES LANGUAGE CUDA)
.
Is there a solution in CMake to implement my idea? I have already tried with generator expressions, but I think it does not work for the source file names.