Fabian
Fabian

Reputation: 607

How to build multiple executables with different compilers with cmake?

following situation:

At the moment, I have a C++/CUDA project and I use make to produce two different executables: The first one is only a CPU version, which ignores the CUDA parts, and the second one is the GPU version.

I can run make to build both versions, make cpu to only build the CPU version and make gpu to only build the GPU version. For the CPU version, the Intel compiler is used , and for the GPU version, nvcc with g++ is used instead.

Why I consider using cmake:

Now I would also like to be able to build the project under Windows with nmake. Therefore, I thought that cmake was the appropriate solution to generate a make or nmake file based on the platform.

Problem:

However, it seems to be difficult to specify a compiler based on a target (Using CMake with multiple compilers for the same language).

Question:

Which is the best way to achieve the behavior as described above, building different executables for different architectures with different compilers out of the same code base as well for Windows as for Linux, by using cmake?

Upvotes: 2

Views: 1609

Answers (1)

David Marquant
David Marquant

Reputation: 2237

In your situation you can just use cmake's CUDA support: FindCUDA.

Your cmake lists would then look like:

find_package(CUDA)

add_executable(cpu ${SRC_LIST})
CUDA_ADD_EXECUTABLE(gpu ${SRC_LIST})

Upvotes: 1

Related Questions