diff --git a/cmake/vecmem-check-language.cmake b/cmake/vecmem-check-language.cmake index 084f5272..4830c8d8 100644 --- a/cmake/vecmem-check-language.cmake +++ b/cmake/vecmem-check-language.cmake @@ -4,16 +4,18 @@ # # Mozilla Public License Version 2.0 -# Make sure that the code is not included more than once. -include_guard( GLOBAL ) - # CMake include(s). include( CheckLanguage ) +# Cache the location of this directory. +set( VECMEM_LANGUAGE_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH + "Directory holding the VecMem language files" ) +mark_as_advanced( VECMEM_LANGUAGE_DIR ) + # Teach CMake about VecMem's custom language files. list( INSERT CMAKE_MODULE_PATH 0 - "${CMAKE_CURRENT_LIST_DIR}/hip" - "${CMAKE_CURRENT_LIST_DIR}/sycl" ) + "${VECMEM_LANGUAGE_DIR}/hip" + "${VECMEM_LANGUAGE_DIR}/sycl" ) # Code mimicking CMake's CheckLanguage.cmake module. But making sure that the # VecMem specific code is used while looking for the non-standard languages. @@ -46,8 +48,8 @@ macro( vecmem_check_language lang ) "cmake_minimum_required( VERSION ${CMAKE_VERSION} )\n" "project( Check${lang} LANGUAGES CXX )\n" "list( INSERT CMAKE_MODULE_PATH 0 " - " \"${CMAKE_CURRENT_LIST_DIR}/hip\" " - " \"${CMAKE_CURRENT_LIST_DIR}/sycl\" )\n" + " \"${VECMEM_LANGUAGE_DIR}/hip\" " + " \"${VECMEM_LANGUAGE_DIR}/sycl\" )\n" "enable_language( ${lang} )\n" "file( WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"\n" " \"set( CMAKE_${lang}_COMPILER \\\"\${CMAKE_${lang}_COMPILER}\\\" )\" )" ) diff --git a/cmake/vecmem-config.cmake.in b/cmake/vecmem-config.cmake.in index 929bd271..b5c73709 100644 --- a/cmake/vecmem-config.cmake.in +++ b/cmake/vecmem-config.cmake.in @@ -13,11 +13,50 @@ set_and_check( vecmem_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@" ) set_and_check( vecmem_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@" ) set_and_check( vecmem_CMAKE_DIR "@PACKAGE_CMAKE_INSTALL_CMAKEDIR@" ) +# Include the file listing all the imported targets and options. +include( "${vecmem_CMAKE_DIR}/vecmem-config-targets.cmake" ) + +# Set up additional variables, based on the imported targets. These are mostly +# just here for handling COMPONENT arguments for find_package(...). +set( vecmem_CORE_LIBRARY vecmem::core ) +if( TARGET vecmem::cuda ) + set( vecmem_CUDA_LIBRARY vecmem::cuda ) +else() + set( vecmem_CUDA_LIBRARY vecmem::cuda-NOTFOUND ) +endif() +if( TARGET vecmem::hip ) + set( vecmem_HIP_LIBRARY vecmem::hip ) +else() + set( vecmem_HIP_LIBRARY vecmem::hip-NOTFOUND ) +endif() +if( TARGET vecmem::sycl ) + set( vecmem_SYCL_LIBRARY vecmem::sycl ) +else() + set( vecmem_SYCL_LIBRARY vecmem::sycl-NOTFOUND ) +endif() + +# If the user asked for the CUDA/HIP/SYCL components explicitly, make +# sure that they would exist in the installation. +set( vecmem_REQUIRED_LIBS vecmem_CORE_LIBRARY ) +foreach( comp "CUDA" "HIP" "SYCL" ) + if( "${vecmem_FIND_COMPONENTS}" MATCHES "${comp}" ) + list( APPEND vecmem_REQUIRED_LIBS vecmem_${comp}_LIBRARY ) + endif() +endforeach() + # Print a standard information message about the package being found. include( FindPackageHandleStandardArgs ) find_package_handle_standard_args( vecmem REQUIRED_VARS - CMAKE_CURRENT_LIST_FILE + CMAKE_CURRENT_LIST_FILE ${vecmem_REQUIRED_LIBS} VERSION_VAR vecmem_VERSION ) -# Include the file listing all the imported targets and options. -include( "${vecmem_CMAKE_DIR}/vecmem-config-targets.cmake" ) +# Clean up. +unset( vecmem_REQUIRED_LIBS ) + +# Set up the "language helper code" coming with the installation, if the +# user asks for it. +set_and_check( vecmem_LANGUAGE_FILE + "${vecmem_CMAKE_DIR}/vecmem-check-language.cmake" ) +if( "${vecmem_FIND_COMPONENTS}" MATCHES "LANGUAGE" ) + include( "${vecmem_LANGUAGE_FILE}" ) +endif() diff --git a/cmake/vecmem-packaging.cmake b/cmake/vecmem-packaging.cmake index be680d74..cdf3afe2 100644 --- a/cmake/vecmem-packaging.cmake +++ b/cmake/vecmem-packaging.cmake @@ -29,3 +29,13 @@ install( FILES "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/vecmem-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/vecmem-config-version.cmake" DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" ) + +# Install the "language helper" files. +install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/vecmem-check-language.cmake" + DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" ) +install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/hip" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sycl" + DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" ) + +# Clean up. +unset( CMAKE_INSTALL_CMAKEDIR )