Skip to content

Commit

Permalink
FindCUDA: Resolve a host compiler symlink only if it is Apple cc -> c…
Browse files Browse the repository at this point in the history
…lang

Otherwise using a "cc -> ccache" or similar symlink as the compiler
causes FindCUDA to select ccache as the host compiler.  Update the logic
added by commit v3.1.0-rc1~354^2 (FindCUDA: Fix OSX Clang & no C
language enabled, 2014-06-12) to apply only in the specific case it is
needed.
  • Loading branch information
billhoffman authored and bradking committed Jun 15, 2015
1 parent 03e2248 commit b405f01
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Modules/FindCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,31 @@ set(CUDA_NVCC_FLAGS "" CACHE STRING "Semi-colon delimit multiple arguments.")
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(CUDA_HOST_COMPILER "$(VCInstallDir)bin" CACHE FILEPATH "Host side compiler used by NVCC")
else()
# Using cc which is symlink to clang may let NVCC think it is GCC and issue
# unhandled -dumpspecs option to clang. Also in case neither
# CMAKE_C_COMPILER is defined (project does not use C language) nor
# CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let
# nvcc use its own default C compiler.
if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER)
get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
if(APPLE
AND "${CMAKE_C_COMPILER_ID}" MATCHES "Clang"
AND "${CMAKE_C_COMPILER}" MATCHES "/cc$")
# Using cc which is symlink to clang may let NVCC think it is GCC and issue
# unhandled -dumpspecs option to clang. Also in case neither
# CMAKE_C_COMPILER is defined (project does not use C language) nor
# CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let
# nvcc use its own default C compiler.
# Only care about this on APPLE with clang to avoid
# following symlinks to things like ccache
if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER)
get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
# if the real path does not end up being clang then
# go back to using CMAKE_C_COMPILER
if(NOT "${c_compiler_realpath}" MATCHES "/clang$")
set(c_compiler_realpath "${CMAKE_C_COMPILER}")
endif()
else()
set(c_compiler_realpath "")
endif()
set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC")
else()
set(c_compiler_realpath "")
set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}"
CACHE FILEPATH "Host side compiler used by NVCC")
endif()
set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC")
endif()

# Propagate the host flags to the host compiler via -Xcompiler
Expand Down

1 comment on commit b405f01

@ax3l
Copy link
Contributor

@ax3l ax3l commented on b405f01 Sep 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the update, this caused trouble cross-compiling in cray environments and this fixes it.
(in the cray environment, the simlink must not be resolved, aka ABSOLUTE instead of REALPATH)

the problem was introduced in 32bcec5#diff-4740178b5defb85b802090e7f04ae7e2
and exists in all CMake releases from 3.1.0 to the latest 3.3.1 release

Please sign in to comment.