Created
January 12, 2017 22:15
-
-
Save robertmaynard/349be0916732c06dc20ee29d879bc576 to your computer and use it in GitHub Desktop.
cuda_wrap_srcs_example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set(srcs | |
cpp_source1.cpp | |
) | |
set(cuda_srcs | |
cuda_source1.cu | |
) | |
set(GPGPU_BUILD_TYPE STATIC) | |
if(BUILD_SHARED_LIBS) | |
set(GPGPU_BUILD_TYPE SHARED) | |
endif() | |
######## | |
## Pass the proper visibility controls to cuda_wrap_srcs | |
## | |
######## | |
set(compile_options) | |
if(BUILD_SHARED_LIBS AND NOT WIN32) | |
list(APPEND compile_options -Xcompiler=${CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY}hidden) | |
endif() | |
set(seperable_state ${CUDA_SEPARABLE_COMPILATION}) | |
set(CUDA_SEPARABLE_COMPILATION ON) | |
cuda_wrap_srcs(exampleTarget OBJ | |
cuda_compiled_sources | |
${cuda_srcs} | |
${GPGPU_BUILD_TYPE} | |
OPTIONS "${compile_options}" | |
) | |
# Compute the file name of the intermediate link file used for separable | |
# compilation. | |
cuda_compute_separable_compilation_object_file_name(link_file | |
exampleTarget | |
${cuda_compiled_sources}) | |
add_library(exampleTarget | |
${srcs} | |
${cuda_compiled_sources} | |
${cuda_srcs} | |
${link_file} | |
) | |
cuda_link_separable_compilation_objects("${link_file}" | |
exampleTarget | |
"${compile_options}" | |
"${cuda_compiled_sources}") | |
set_target_properties(exampleTarget | |
PROPERTIES LINKER_LANGUAGE CXX | |
) | |
######## | |
## make sure we link to cudadevrt so separable compilation works | |
## | |
######## | |
get_filename_component(CUDA_CUDA_LIBRARY_PATH ${CUDA_CUDA_LIBRARY} DIRECTORY) | |
find_library(CUDA_cudadevrt_LIBRARY cudadevrt PATHS ${CUDA_CUDA_LIBRARY_PATH}) | |
target_link_libraries(exampleTarget | |
LINK_PRIVATE ${CUDA_LIBRARIES} ${CUDA_cudadevrt_LIBRARY} | |
) | |
set(CUDA_SEPARABLE_COMPILATION ${seperable_state}) | |
set(cache_state ${CUDA_NVCC_FLAGS_CACHE}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment