Skip to content

Commit

Permalink
Made VecMem export its "language files" during installation.
Browse files Browse the repository at this point in the history
Making it possible to make use of VecMem's SYCL and HIP build
infrastructure after "finding" an installed version of VecMem.

Introduced "component flags" for the CUDA, HIP and SYCL libraries,
so that find_package(...) calls could explicitly ask for some of
the optional libraries to be available.
  • Loading branch information
krasznaa committed Nov 8, 2021
1 parent 1e9b565 commit 87d316d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
16 changes: 9 additions & 7 deletions cmake/vecmem-check-language.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}\\\" )\" )" )
Expand Down
45 changes: 42 additions & 3 deletions cmake/vecmem-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 10 additions & 0 deletions cmake/vecmem-packaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

0 comments on commit 87d316d

Please sign in to comment.