How to tell CMake to compile all cpp files as CUDA sources

67 Views Asked by At

I have a project that has many .cpp files. Mainly for testing, I like to compile these .cpp files as CUDA files.

I can overwrite the language automatically detected by CMake with this like for each file.

... loop of ${TEST_FILE} (from a list list of cpp files)
        set(TEST_EXE "${TEST_FILE}.x")
        add_executable(${TEST_EXE} ${TEST_FILE})

        if(FORCE_CUDA)
            set_source_files_properties(${TEST_FILE} PROPERTIES LANGUAGE CUDA)
        endif()
...

Is there a global setting by which I can tell CMake to compile .cpp files as if they were .cu (CUDA) sources?

There is this related question, How to compile C++ as CUDA using CMake, but it only answers for individual or explicit lists of files (one has to set_source_file_properties in all locations of a long and subdirectory nested CMake files).

1

There are 1 best solutions below

0
einpoklum On BEST ANSWER

After scouring the CMake documentation for something relevant, I conclude that this is not currently possible, and you will have to set the language file-by-file.