From 47ece1795068dedc1ee118dab1aaf00fd25fc4ff Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Wed, 25 Feb 2026 16:28:30 +0100 Subject: [PATCH] AddThallium cmake --- CMake/FindThallium.cmake | 167 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 CMake/FindThallium.cmake diff --git a/CMake/FindThallium.cmake b/CMake/FindThallium.cmake new file mode 100644 index 000000000..1c1f431a9 --- /dev/null +++ b/CMake/FindThallium.cmake @@ -0,0 +1,167 @@ +# FindThallium +# --------- +# +# Find Thallium include dirs and libraries. +# +# Use this module by invoking find_package with the form:: +# +# find_package(Thallium +# [version] [EXACT] # Minimum or EXACT version e.g. 0.6.2 +# [REQUIRED] # Fail with error if Thallium is not found +# ) +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module provides the following imported targets, if found: +# +# ``Thallium::Thallium`` +# The Thallium library +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This will define the following variables: +# +# ``Thallium_FOUND`` +# True if the system has the Thallium library. +# ``Thallium_VERSION`` +# The version of the Thallium library which was found. +# ``Thallium_INCLUDE_DIRS`` +# Include directories needed to use Thallium. +# +# Cache Variables +# ^^^^^^^^^^^^^^^ +# +# The following cache variables may also be set: +# +# ``THALLIUM_INCLUDE_DIR`` +# The directory containing ``thallium.hpp``. +# + +function(_get_pkgconfig_paths target_var) + set(_lib_dirs) + if (NOT DEFINED CMAKE_SYSTEM_NAME + OR (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$" + AND NOT CMAKE_CROSSCOMPILING) + ) + if (EXISTS "/etc/debian_version") # is this a debian system ? + if (CMAKE_LIBRARY_ARCHITECTURE) + list(APPEND _lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig") + endif () + else () + # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties + get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS) + if (uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) + list(APPEND _lib_dirs "lib32/pkgconfig") + endif () + get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) + if (uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8) + list(APPEND _lib_dirs "lib64/pkgconfig") + endif () + get_property(uselibx32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIBX32_PATHS) + if (uselibx32 AND CMAKE_INTERNAL_PLATFORM_ABI STREQUAL "ELF X32") + list(APPEND _lib_dirs "libx32/pkgconfig") + endif () + endif () + endif () + if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND NOT CMAKE_CROSSCOMPILING) + list(APPEND _lib_dirs "libdata/pkgconfig") + endif () + list(APPEND _lib_dirs "lib/pkgconfig") + list(APPEND _lib_dirs "share/pkgconfig") + + set(_extra_paths) + list(APPEND _extra_paths ${CMAKE_PREFIX_PATH}) + list(APPEND _extra_paths ${CMAKE_FRAMEWORK_PATH}) + list(APPEND _extra_paths ${CMAKE_APPBUNDLE_PATH}) + + # Check if directories exist and eventually append them to the + # pkgconfig path list + foreach (_prefix_dir ${_extra_paths}) + foreach (_lib_dir ${_lib_dirs}) + if (EXISTS "${_prefix_dir}/${_lib_dir}") + list(APPEND _pkgconfig_paths "${_prefix_dir}/${_lib_dir}") + list(REMOVE_DUPLICATES _pkgconfig_paths) + endif () + endforeach () + endforeach () + + set("${target_var}" + ${_pkgconfig_paths} + PARENT_SCOPE + ) +endfunction() + +if (NOT PKG_CONFIG_FOUND) + find_package(PkgConfig) +endif () + +if (PKG_CONFIG_FOUND) + pkg_check_modules(PC_THALLIUM QUIET thallium) + + find_path( + THALLIUM_INCLUDE_DIR + NAMES thallium.hpp + PATHS ${PC_THALLIUM_INCLUDE_DIRS} + PATH_SUFFIXES include + ) + + set(Thallium_VERSION ${PC_THALLIUM_VERSION}) +else () + find_path( + THALLIUM_INCLUDE_DIR + NAMES thallium.hpp + PATH_SUFFIXES include + ) + + # even if pkg-config is not available, try to find thallium.pc + _get_pkgconfig_paths(_pkgconfig_paths) + + find_file(_thallium_pc_file thallium.pc PATHS "${_pkgconfig_paths}") + + if (NOT _thallium_pc_file) + message( + FATAL_ERROR + "ERROR: Could not find 'thallium.pc' file. Unable to determine library version" + ) + endif () + + file(STRINGS "${_thallium_pc_file}" _thallium_pc_file_contents REGEX "Version: ") + + if ("${_thallium_pc_file_contents}" MATCHES "Version: ([0-9]+\\.[0-9]+\\.[0-9]+)") + set(Thallium_VERSION ${CMAKE_MATCH_1}) + else () + message(FATAL_ERROR "ERROR: Failed to determine library version") + endif () + + unset(_pkgconfig_paths) + unset(_thallium_pc_file_contents) +endif () + +mark_as_advanced(THALLIUM_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + Thallium + FOUND_VAR Thallium_FOUND + REQUIRED_VARS THALLIUM_INCLUDE_DIR + VERSION_VAR Thallium_VERSION +) + +if (Thallium_FOUND) + set(Thallium_INCLUDE_DIRS ${THALLIUM_INCLUDE_DIR}) + if (NOT TARGET thallium) + add_library(thallium INTERFACE IMPORTED) + set_target_properties( + thallium + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${THALLIUM_INCLUDE_DIR}" + ) + + # Thallium wraps Margo, Mercury, and Argobots + find_package(Margo REQUIRED) + find_package(Mercury REQUIRED) + find_package(Argobots REQUIRED) + target_link_libraries(thallium INTERFACE Margo::Margo Mercury::Mercury Argobots::Argobots) + endif () +endif () -- GitLab