summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-06-22 14:04:34 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-06-22 14:04:37 (GMT)
commit396b618c523d042df1c96cb08be1163e5c72d150 (patch)
treece540d2974d815148c95a9618db5dbed6a054bab
parent416e7919ec92d2899e27949132fce59a1926aeab (diff)
parent3b75421515835b2fc6713be3015cc3f7324bb5a8 (diff)
downloadCMake-396b618c523d042df1c96cb08be1163e5c72d150.zip
CMake-396b618c523d042df1c96cb08be1163e5c72d150.tar.gz
CMake-396b618c523d042df1c96cb08be1163e5c72d150.tar.bz2
Merge topic 'vs-cuda-fix-flags'
3b754215 VS: Improve workaround for CUDA -Xcompiler placement bug f2059585 VS: Fix target_compile_options for CUDA Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !996
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx45
-rw-r--r--Tests/CudaOnly/SeparateCompilation/CMakeLists.txt4
-rw-r--r--Tests/CudaOnly/WithDefs/CMakeLists.txt1
-rw-r--r--Tests/CudaOnly/WithDefs/main.notcu4
4 files changed, 44 insertions, 10 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index d3884d8..d932245 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"
@@ -2241,10 +2242,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(
@@ -2255,6 +2273,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") {
@@ -2263,10 +2283,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);
@@ -2500,6 +2516,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 =
@@ -2525,9 +2543,16 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
cudaOptions.AddTable(gg->GetCudaHostFlagTable());
cudaOptions.Reparse("AdditionalCompilerOptions");
- // `CUDA 8.0.targets` places these before nvcc! Just drop whatever
- // did not parse and hope it works.
- cudaOptions.RemoveFlag("AdditionalCompilerOptions");
+ // `CUDA 8.0.targets` places AdditionalCompilerOptions before nvcc!
+ // Pass them through -Xcompiler in AdditionalOptions instead.
+ if (const char* acoPtr = cudaOptions.GetFlag("AdditionalCompilerOptions")) {
+ std::string aco = acoPtr;
+ cudaOptions.RemoveFlag("AdditionalCompilerOptions");
+ if (!aco.empty()) {
+ aco = this->LocalGenerator->EscapeForShell(aco, false);
+ cudaOptions.AppendFlag("AdditionalOptions", "-Xcompiler=" + aco);
+ }
+ }
cudaOptions.FixCudaCodeGeneration();
diff --git a/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt b/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt
index 55fd79f..b946e3f 100644
--- a/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt
+++ b/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt
@@ -15,6 +15,10 @@ set(CMAKE_CUDA_STANDARD 11)
add_library(CUDASeparateLibA STATIC file1.cu file2.cu file3.cu)
+if(CMAKE_CUDA_SIMULATE_ID STREQUAL "MSVC")
+ target_compile_options(CUDASeparateLibA PRIVATE -Xcompiler=-bigobj)
+endif()
+
#Having file4/file5 in a shared library causes serious problems
#with the nvcc linker and it will generate bad entries that will
#cause a segv when trying to run the executable
diff --git a/Tests/CudaOnly/WithDefs/CMakeLists.txt b/Tests/CudaOnly/WithDefs/CMakeLists.txt
index fe0ccc6..0bc4e5c 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 80ed3a5..d2eff3f 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