diff --git a/CMakeLists.txt b/CMakeLists.txt index eeafe753bb1c0271b527e3f59cd07f83ae3db105..6a3063f0ce3b1e07af38c8b76bbdc30cffbf1ac4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,8 +66,9 @@ if (NOT CMAKE_BUILD_TYPE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "debug" "release") endif() -# When we find threads, prefer -pthread option. -set(THREADS_PREFER_PTHREAD_FLAG ON) +# When we find threads, prefer not to use the -pthread option +# in order to avoid a CMake 3.12 issue. +set(THREADS_PREFER_PTHREAD_FLAG OFF) # Add CUDA as a language if GPU support requested. # (This has to be set early so as to enable CUDA tests in generator @@ -329,6 +330,27 @@ write_basic_package_version_file( # Template file will use contents of arbor_export_dependencies to include the # required `find_dependency` statements, and arbor_supported_components will # be used to check feature support. +# +# To avoid CMake users of the installed arbor library conditionally requiring +# that they add CUDA to their project language, explicitly munge the import +# language and library dependencies on the installed target if ARB_WITH_GPU +# is set, via the variables arbor_override_import_lang and arbor_add_import_libs. +# arbor_build_config records our build type in a way compatible with the +# generated export cmake files. + +set(arbor_build_config NOCONFIG) +if(CMAKE_BUILD_TYPE) + string(TOUPPER "${CMAKE_BUILD_TYPE}" arbor_build_config) +endif() + +set(arbor_override_import_lang) +set(arbor_add_import_libs) + +if(ARB_WITH_GPU) + set(arbor_override_import_lang CXX) + find_package(CUDA REQUIRED) + set(arbor_add_import_libs ${CUDA_LIBRARIES}) +endif() configure_file( cmake/arbor-config.cmake.in diff --git a/arbor/CMakeLists.txt b/arbor/CMakeLists.txt index 6664cb56097cc8341454e63a8b0403dbee87f188..b8d199bc720df0d2362d74b9811900b28f1acc5c 100644 --- a/arbor/CMakeLists.txt +++ b/arbor/CMakeLists.txt @@ -111,6 +111,7 @@ add_library(arbor ${arbor_sources} ${arbor_mechanism_sources}) add_dependencies(arbor build_all_mods) target_link_libraries(arbor PRIVATE arbor-private-deps arbor-private-headers) target_link_libraries(arbor PUBLIC arbor-public-deps arbor-public-headers) +set_target_properties(arbor PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON) install(TARGETS arbor EXPORT arbor-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/cmake/arbor-config.cmake.in b/cmake/arbor-config.cmake.in index 71448ec5decf116bca0899a6c78af593086b165b..2d8a3cb6e6d5de804f3125af5d5c3f6599dd2e92 100644 --- a/cmake/arbor-config.cmake.in +++ b/cmake/arbor-config.cmake.in @@ -15,3 +15,20 @@ foreach(component ${arbor_FIND_COMPONENTS}) endif() endforeach() +# Patch properties to remove unnecessary external CUDA dependencies. + +set(_override_lang @arbor_override_import_lang@) +if(_override_lang) + set_target_properties(arbor::arbor PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_@arbor_build_config@ "${_override_lang}") +endif() + +set(_add_libs @arbor_add_import_libs@) +if(_add_libs) + get_target_property(_arbor_interface_libs arbor::arbor INTERFACE_LINK_LIBRARIES) + if(_arbor_interface_libs) + list(APPEND _arbor_interface_libs ${_add_libs}) + else() + set(_arbor_interface_libs ${_add_libs}) + endif() + set_target_properties(arbor::arbor PROPERTIES INTERFACE_LINK_LIBRARIES "${_arbor_interface_libs}") +endif()