CUDA: Refactor CMakeCUDAInformation to prepare for separable compilation.

This commit is contained in:
Robert Maynard 2016-09-27 14:29:30 -04:00
parent 5b20d0abfa
commit 5dec403103
2 changed files with 71 additions and 9 deletions

View File

@ -18,6 +18,44 @@ if(CMAKE_CUDA_COMPILER_ID)
include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CUDA_COMPILER_ID}-CUDA OPTIONAL) include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CUDA_COMPILER_ID}-CUDA OPTIONAL)
endif() endif()
if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG)
set(CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
endif()
if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG_SEP)
set(CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
endif()
if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_CUDA_FLAG)
set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
endif()
if(NOT DEFINED CMAKE_EXE_EXPORTS_CUDA_FLAG)
set(CMAKE_EXE_EXPORTS_CUDA_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
endif()
if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_CUDA_FLAG)
set(CMAKE_SHARED_LIBRARY_SONAME_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
endif()
if(NOT CMAKE_EXECUTABLE_RUNTIME_CUDA_FLAG)
set(CMAKE_EXECUTABLE_RUNTIME_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG})
endif()
if(NOT CMAKE_EXECUTABLE_RUNTIME_CUDA_FLAG_SEP)
set(CMAKE_EXECUTABLE_RUNTIME_CUDA_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG_SEP})
endif()
if(NOT CMAKE_EXECUTABLE_RPATH_LINK_CUDA_FLAG)
set(CMAKE_EXECUTABLE_RPATH_LINK_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_CUDA_FLAG})
endif()
if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CUDA_WITH_RUNTIME_PATH)
set(CMAKE_SHARED_LIBRARY_LINK_CUDA_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
endif()
# for most systems a module is the same as a shared library # for most systems a module is the same as a shared library
# so unless the variable CMAKE_MODULE_EXISTS is set just # so unless the variable CMAKE_MODULE_EXISTS is set just
# copy the values from the LIBRARY variables # copy the values from the LIBRARY variables
@ -99,12 +137,27 @@ if(NOT DEFINED CMAKE_CUDA_ARCHIVE_FINISH)
set(CMAKE_CUDA_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>") set(CMAKE_CUDA_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
endif() endif()
#Specify how to compile when ptx has been requested
if(NOT CMAKE_CUDA_COMPILE_PTX_COMPILATION)
set(CMAKE_CUDA_COMPILE_PTX_COMPILATION
"<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -ptx <SOURCE> -o <OBJECT>")
endif()
# compile a cu file into an object file #Specify how to compile when separable compilation has been requested
if(NOT CMAKE_CUDA_COMPILE_OBJECT) if(NOT CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION)
set(CMAKE_CUDA_COMPILE_OBJECT set(CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION
"<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -dc <SOURCE> -o <OBJECT>")
endif()
#Specify how to compile when whole compilation has been requested
if(NOT CMAKE_CUDA_COMPILE_WHOLE_COMPILATION)
set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION
"<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -c <SOURCE> -o <OBJECT>") "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -c <SOURCE> -o <OBJECT>")
endif()
if(CMAKE_GENERATOR STREQUAL "Ninja")
set(CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION
"<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -M <SOURCE> -MT <OBJECT> -o $DEP_FILE")
#The Ninja generator uses the make file dependency files to determine what #The Ninja generator uses the make file dependency files to determine what
#files need to be recompiled. Unfortunately, nvcc doesn't support building #files need to be recompiled. Unfortunately, nvcc doesn't support building
#a source file and generating the dependencies of said file in a single #a source file and generating the dependencies of said file in a single
@ -112,19 +165,23 @@ if(NOT CMAKE_CUDA_COMPILE_OBJECT)
# #
#The makefile generators uses the custom CMake dependency scanner, and thus #The makefile generators uses the custom CMake dependency scanner, and thus
#it is exempt from this logic. #it is exempt from this logic.
if(CMAKE_GENERATOR STREQUAL "Ninja") list(APPEND CMAKE_CUDA_COMPILE_PTX_COMPILATION "${CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION}")
list(APPEND CMAKE_CUDA_COMPILE_OBJECT list(APPEND CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION "${CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION}")
"<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <DEFINES> <INCLUDES> <FLAGS> -x cu -M <SOURCE> -MT <OBJECT> -o $DEP_FILE") list(APPEND CMAKE_CUDA_COMPILE_WHOLE_COMPILATION "${CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION}")
endif()
endif() endif()
# compile a cu file into an executable # compile a cu file into an executable
if(NOT CMAKE_CUDA_LINK_EXECUTABLE) if(NOT CMAKE_CUDA_LINK_EXECUTABLE)
set(CMAKE_CUDA_LINK_EXECUTABLE set(CMAKE_CUDA_LINK_EXECUTABLE
"<CMAKE_CUDA_HOST_LINK_LAUNCHER> <CMAKE_CUDA_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_LINKS}") "<CMAKE_CUDA_HOST_LINK_LAUNCHER> <CMAKE_CUDA_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_LINKS}")
endif() endif()
#These are used when linking relocatable (dc) cuda code
set(CMAKE_CUDA_DEVICE_LINK_LIBRARY
"<CMAKE_CUDA_COMPILER> <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE
"<CMAKE_CUDA_COMPILER> <CMAKE_CUDA_LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
mark_as_advanced( mark_as_advanced(
CMAKE_CUDA_FLAGS CMAKE_CUDA_FLAGS

View File

@ -10,6 +10,11 @@ set(CMAKE_SHARED_LIBRARY_CREATE_CUDA_FLAGS -shared)
set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA -isystem=) set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA -isystem=)
set(CMAKE_CUDA_COMPILE_OPTIONS_VISIBILITY -Xcompiler=-fvisibility=) set(CMAKE_CUDA_COMPILE_OPTIONS_VISIBILITY -Xcompiler=-fvisibility=)
set(CMAKE_CUDA_FLAGS_INIT " ")
set(CMAKE_CUDA_FLAGS_DEBUG_INIT " -g")
set(CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG")
set(CMAKE_CUDA_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
set(CMAKE_CUDA98_STANDARD_COMPILE_OPTION "") set(CMAKE_CUDA98_STANDARD_COMPILE_OPTION "")
set(CMAKE_CUDA98_EXTENSION_COMPILE_OPTION "") set(CMAKE_CUDA98_EXTENSION_COMPILE_OPTION "")