From bbaf24341026cdacd1e313dd3f8e3501e9c4070e Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Sun, 4 Sep 2016 16:29:44 -0400 Subject: CUDA: add support for specifying an explicit host compiler. --- Modules/CMakeCUDAInformation.cmake | 14 ++++++++++---- Modules/CMakeDetermineCUDACompiler.cmake | 13 ++++++++++++- Source/cmCoreTryCompile.cxx | 3 +++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 41ed34f..858fee7 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -59,10 +59,16 @@ include(CMakeCommonLanguageInclude) # CMAKE_CUDA_COMPILE_OBJECT # CMAKE_CUDA_LINK_EXECUTABLE +if(CMAKE_CUDA_HOST_COMPILER) + set(CMAKE_CUDA_HOST_FLAGS "-ccbin \"${CMAKE_CUDA_HOST_COMPILER}\" ") +else() + set(CMAKE_CUDA_HOST_FLAGS "") +endif() + # create a shared library if(NOT CMAKE_CUDA_CREATE_SHARED_LIBRARY) set(CMAKE_CUDA_CREATE_SHARED_LIBRARY - " -o ") + " ${CMAKE_CUDA_HOST_FLAGS} -o ") endif() # create a shared module copy the shared library rule by default @@ -85,7 +91,7 @@ endif() # compile a cu file into an object file if(NOT CMAKE_CUDA_COMPILE_OBJECT) set(CMAKE_CUDA_COMPILE_OBJECT - " -x cu -c -o ") + " ${CMAKE_CUDA_HOST_FLAGS} -x cu -c -o ") #The Ninja generator uses the make file dependency files to determine what #files need to be recompiled. Unfortunately, nvcc doesn't support building @@ -96,7 +102,7 @@ if(NOT CMAKE_CUDA_COMPILE_OBJECT) #it is exempt from this logic. if(CMAKE_GENERATOR STREQUAL "Ninja") list(APPEND CMAKE_CUDA_COMPILE_OBJECT - " -x cu -M -MT -o $DEP_FILE") + " ${CMAKE_CUDA_HOST_FLAGS} -x cu -M -MT -o $DEP_FILE") endif() endif() @@ -104,7 +110,7 @@ endif() # compile a cu file into an executable if(NOT CMAKE_CUDA_LINK_EXECUTABLE) set(CMAKE_CUDA_LINK_EXECUTABLE - " -o ") + " ${CMAKE_CUDA_HOST_FLAGS} -o ") endif() diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index a6863ef..d5dc9f4 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -23,6 +23,10 @@ endif() mark_as_advanced(CMAKE_CUDA_COMPILER) +#Allow the user to specify a host compiler +#todo: need to specify this to compiler test passes +set(CMAKE_CUDA_HOST_COMPILER "" CACHE FILEPATH "Host compiler to be used by nvcc") + # Build a small source file to identify the compiler. if(NOT CMAKE_CUDA_COMPILER_ID_RUN) set(CMAKE_CUDA_COMPILER_ID_RUN 1) @@ -39,9 +43,16 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_REGEX "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerIdCUDA/(\\./)?(CompilerIdCUDA.xctest/)?CompilerIdCUDA[ \t\n\\\"]") set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_INDEX 2) + if(CMAKE_CUDA_HOST_COMPILER) + # Each entry in this list is a set of extra flags to try + # adding to the compile line to see if it helps produce + # a valid identification file. In our case this would just + # be the explicit host compiler + set(CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "-ccbin=${CMAKE_CUDA_HOST_COMPILER}") + endif() + include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) CMAKE_DETERMINE_COMPILER_ID(CUDA CUDAFLAGS CMakeCUDACompilerId.cu) - endif() include(CMakeFindBinUtils) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 3b46fc0..b1d3775 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -44,6 +44,8 @@ static std::string const kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES = "CMAKE_TRY_COMPILE_OSX_ARCHITECTURES"; static std::string const kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES = "CMAKE_TRY_COMPILE_PLATFORM_VARIABLES"; +static std::string const kCMAKE_CUDA_HOST_COMPILER = + "CMAKE_CUDA_HOST_COMPILER"; int cmCoreTryCompile::TryCompileCode(std::vector const& argv, bool isTryRun) @@ -453,6 +455,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, vars.insert(kCMAKE_OSX_SYSROOT); vars.insert(kCMAKE_POSITION_INDEPENDENT_CODE); vars.insert(kCMAKE_SYSROOT); + vars.insert(kCMAKE_CUDA_HOST_COMPILER); if (const char* varListStr = this->Makefile->GetDefinition( kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES)) { -- cgit v0.12