summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-06-21 13:44:43 -0400
committerBrad King <brad.king@kitware.com>2017-06-21 14:23:46 -0400
commitf2059585e6302446707560b123c7b785df5f5859 (patch)
treee29520e82e81a0e4fb5ffba8447bcf7edb7cded6
parentab4c3270ae7062a8f3296055b9f6443b80f3aef2 (diff)
downloadcmake-f2059585e6302446707560b123c7b785df5f5859.tar.gz
VS: Fix target_compile_options for CUDA
Fix the VS generator to honor `COMPILE_OPTIONS` for CUDA. The exclusion added by commit v3.9.0-rc1~431^2~7 (VS: Do not pass CUDA compile options to C compiler, 2017-03-07) was correct but we need additional logic to pass the CUDA compile options to the CUDA compiler. Also we should still pass the CXX or C options to MSVC (ClCompile) when those languages are enabled even if the link language is CUDA.
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx32
-rw-r--r--Tests/CudaOnly/WithDefs/CMakeLists.txt1
-rw-r--r--Tests/CudaOnly/WithDefs/main.notcu4
3 files changed, 30 insertions, 7 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 238c9e8834..2a7d96b428 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmVisualStudio10TargetGenerator.h"
+#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
#include "cmCustomCommandGenerator.h"
#include "cmGeneratedFileStream.h"
@@ -2227,10 +2228,27 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
this->Name.c_str());
return false;
}
- if (linkLanguage == "C" || linkLanguage == "CXX" ||
- linkLanguage == "Fortran" || linkLanguage == "CSharp") {
+
+ // Choose a language whose flags to use for ClCompile.
+ static const char* clLangs[] = { "CXX", "C", "Fortran", "CSharp" };
+ std::string langForClCompile;
+ if (std::find(cmArrayBegin(clLangs), cmArrayEnd(clLangs), linkLanguage) !=
+ cmArrayEnd(clLangs)) {
+ langForClCompile = linkLanguage;
+ } else {
+ std::set<std::string> languages;
+ this->GeneratorTarget->GetLanguages(languages, configName);
+ for (const char* const* l = cmArrayBegin(clLangs);
+ l != cmArrayEnd(clLangs); ++l) {
+ if (languages.find(*l) != languages.end()) {
+ langForClCompile = *l;
+ break;
+ }
+ }
+ }
+ if (!langForClCompile.empty()) {
std::string baseFlagVar = "CMAKE_";
- baseFlagVar += linkLanguage;
+ baseFlagVar += langForClCompile;
baseFlagVar += "_FLAGS";
flags =
this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
@@ -2241,6 +2259,8 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
flags +=
this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
flagVar.c_str());
+ this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
+ langForClCompile, configName);
}
// set the correct language
if (linkLanguage == "C") {
@@ -2249,10 +2269,6 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
if (linkLanguage == "CXX") {
clOptions.AddFlag("CompileAs", "CompileAsCpp");
}
- if (linkLanguage != "CUDA") {
- this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
- linkLanguage, configName.c_str());
- }
// Check IPO related warning/error.
this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName);
@@ -2480,6 +2496,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
std::string(this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS")) +
std::string(" ") +
std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
+ this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",
+ configName);
// Get preprocessor definitions for this directory.
std::string defineFlags =
diff --git a/Tests/CudaOnly/WithDefs/CMakeLists.txt b/Tests/CudaOnly/WithDefs/CMakeLists.txt
index 38f2a44a34..e25f141ea5 100644
--- a/Tests/CudaOnly/WithDefs/CMakeLists.txt
+++ b/Tests/CudaOnly/WithDefs/CMakeLists.txt
@@ -28,6 +28,7 @@ add_executable(CudaOnlyWithDefs ${main})
target_compile_options(CudaOnlyWithDefs
PRIVATE
+ -Xcompiler=-DHOST_DEFINE
$<$<CONFIG:DEBUG>:$<BUILD_INTERFACE:${debug_compile_flags}>>
)
diff --git a/Tests/CudaOnly/WithDefs/main.notcu b/Tests/CudaOnly/WithDefs/main.notcu
index 80ed3a5050..d2eff3f4b3 100644
--- a/Tests/CudaOnly/WithDefs/main.notcu
+++ b/Tests/CudaOnly/WithDefs/main.notcu
@@ -2,6 +2,10 @@
#include <cuda_runtime.h>
#include <iostream>
+#ifndef HOST_DEFINE
+#error "HOST_DEFINE not defined!"
+#endif
+
#ifndef PACKED_DEFINE
#error "PACKED_DEFINE not defined!"
#endif