Redifinition of CMAKE_CUDA_FLAGS
By default CMake has
CMAKE_CUDA_FLAGS:STRING=
CMAKE_CUDA_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
If we pass -O3
in CMAKE_CUDA_FLAGS
it will build most of the time but when we specify a Release build type this will cause an nvcc error
nvcc fatal : redefinition of argument 'optimize'
because CMAKE_CUDA_FLAGS_RELEASE
is simply appended after CMAKE_CUDA_FLAGS
as we can see from the source code
std::string configFlagsVar = std::string("CMAKE_CUDA_FLAGS_") + CONFIG;
std::string flags = this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS") + " " + this->Makefile->GetSafeDefinition(configFlagsVar);
this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",configName);
This seems like a bug to me but maybe it's intended? However, without documentation, it's just difficult and frustrating to debug when this error happens.