From 6f66d82c2a7a21c0f071ebe1467247caa6644cc6 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 2 Sep 2026 17:02:27 -0300 Subject: [PATCH 1/3] Minor CMake fixes to accomodate for Meson See: https://github.com/sourcemeta/blaze/pull/1024 Signed-off-by: Juan Cruz Viotti --- cmake/FindMimalloc.cmake | 10 +++++++--- cmake/common/targets/library.cmake | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/cmake/FindMimalloc.cmake b/cmake/FindMimalloc.cmake index 9ac939c40..29258863d 100644 --- a/cmake/FindMimalloc.cmake +++ b/cmake/FindMimalloc.cmake @@ -40,8 +40,14 @@ if(NOT Mimalloc_FOUND) add_library(mimalloc ${MIMALLOC_SOURCES}) sourcemeta_add_default_options(PRIVATE mimalloc) + # Link the resolved thread library rather than the imported target, as the + # latter obliges every consumer of the exported package to run FindThreads, + # whose try_compile cannot run inside build systems that read the export by + # tracing CMake instead of calling it find_package(Threads REQUIRED) - target_link_libraries(mimalloc PRIVATE Threads::Threads) + if(CMAKE_THREAD_LIBS_INIT) + target_link_libraries(mimalloc PRIVATE "${CMAKE_THREAD_LIBS_INIT}") + endif() target_include_directories(mimalloc PUBLIC "$" @@ -145,8 +151,6 @@ if(NOT Mimalloc_FOUND) COMPONENT sourcemeta_core_dev) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/mimalloc-config.cmake - "include(CMakeFindDependencyMacro)\n" - "find_dependency(Threads)\n" "include(\"\${CMAKE_CURRENT_LIST_DIR}/mimalloc.cmake\")\n" "check_required_components(\"mimalloc\")\n") install(FILES diff --git a/cmake/common/targets/library.cmake b/cmake/common/targets/library.cmake index 8085dee0d..6358236cd 100644 --- a/cmake/common/targets/library.cmake +++ b/cmake/common/targets/library.cmake @@ -133,6 +133,25 @@ function(sourcemeta_library) endif() endfunction() +# A static library records its private dependencies as $ in the +# exported link interface. Build systems that read the export without evaluating +# generator expressions drop those entries and lose the transitive link closure, +# so unwrap them on the way out. CMake consumers are unaffected, as the wrapper +# only suppresses usage requirements that an installed interface does not carry +function(sourcemeta_library_export_flatten TARGET_NAME) + get_target_property(SOURCEMETA_LIBRARY_INTERFACE + ${TARGET_NAME} INTERFACE_LINK_LIBRARIES) + if(SOURCEMETA_LIBRARY_INTERFACE) + set(SOURCEMETA_LIBRARY_FLATTENED) + foreach(entry IN LISTS SOURCEMETA_LIBRARY_INTERFACE) + string(REGEX REPLACE "\\$]+)>" "\\1" entry "${entry}") + list(APPEND SOURCEMETA_LIBRARY_FLATTENED "${entry}") + endforeach() + set_property(TARGET ${TARGET_NAME} + PROPERTY INTERFACE_LINK_LIBRARIES ${SOURCEMETA_LIBRARY_FLATTENED}) + endif() +endfunction() + function(sourcemeta_library_install) cmake_parse_arguments(SOURCEMETA_LIBRARY "" "NAMESPACE;PROJECT;NAME;VARIANT" "" ${ARGN}) @@ -173,6 +192,12 @@ function(sourcemeta_library_install) NAMELINK_COMPONENT ${COMPONENT_NAME}_dev ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT ${COMPONENT_NAME}_dev) + # Deferred, as callers link their dependencies after installing the target. + # The target name is expanded into the deferred call, as its arguments are + # not evaluated until the call runs, by which point the variable is gone + cmake_language(EVAL CODE + "cmake_language(DEFER CALL sourcemeta_library_export_flatten ${TARGET_NAME})") + install(EXPORT ${TARGET_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${SOURCEMETA_LIBRARY_PROJECT}" NAMESPACE ${NAMESPACE_PREFIX} From 18200e24cc953d0609960629f4b64cdf9c7eabeb Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 2 Sep 2026 17:13:02 -0300 Subject: [PATCH 2/3] More Signed-off-by: Juan Cruz Viotti --- cmake/FindPCRE2.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/FindPCRE2.cmake b/cmake/FindPCRE2.cmake index 21756978b..ad73b552d 100644 --- a/cmake/FindPCRE2.cmake +++ b/cmake/FindPCRE2.cmake @@ -201,6 +201,7 @@ if(NOT PCRE2_FOUND) NAMELINK_COMPONENT sourcemeta_core_dev ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT sourcemeta_core_dev) + sourcemeta_library_export_flatten(pcre2) install(EXPORT pcre2 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/pcre2" NAMESPACE PCRE2:: From 5246af4efd111870aab5f9c5a9d129c7dbc71efa Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 2 Sep 2026 17:25:02 -0300 Subject: [PATCH 3/3] Fix Signed-off-by: Juan Cruz Viotti --- cmake/FindMimalloc.cmake | 6 +++++- cmake/common/targets/library.cmake | 15 +++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cmake/FindMimalloc.cmake b/cmake/FindMimalloc.cmake index 29258863d..f6f14f937 100644 --- a/cmake/FindMimalloc.cmake +++ b/cmake/FindMimalloc.cmake @@ -43,8 +43,12 @@ if(NOT Mimalloc_FOUND) # Link the resolved thread library rather than the imported target, as the # latter obliges every consumer of the exported package to run FindThreads, # whose try_compile cannot run inside build systems that read the export by - # tracing CMake instead of calling it + # tracing CMake instead of calling it. The imported target also carries a + # compile option on the platforms whose threads need one, which we set here find_package(Threads REQUIRED) + if(THREADS_HAVE_PTHREAD_ARG) + target_compile_options(mimalloc PRIVATE -pthread) + endif() if(CMAKE_THREAD_LIBS_INIT) target_link_libraries(mimalloc PRIVATE "${CMAKE_THREAD_LIBS_INIT}") endif() diff --git a/cmake/common/targets/library.cmake b/cmake/common/targets/library.cmake index 6358236cd..94a817177 100644 --- a/cmake/common/targets/library.cmake +++ b/cmake/common/targets/library.cmake @@ -136,16 +136,23 @@ endfunction() # A static library records its private dependencies as $ in the # exported link interface. Build systems that read the export without evaluating # generator expressions drop those entries and lose the transitive link closure, -# so unwrap them on the way out. CMake consumers are unaffected, as the wrapper -# only suppresses usage requirements that an installed interface does not carry +# so unwrap them for the installed interface. The build interface keeps the +# wrapper, so that consumers within this project do not start inheriting the +# usage requirements that a private dependency is not meant to hand them function(sourcemeta_library_export_flatten TARGET_NAME) get_target_property(SOURCEMETA_LIBRARY_INTERFACE ${TARGET_NAME} INTERFACE_LINK_LIBRARIES) if(SOURCEMETA_LIBRARY_INTERFACE) set(SOURCEMETA_LIBRARY_FLATTENED) foreach(entry IN LISTS SOURCEMETA_LIBRARY_INTERFACE) - string(REGEX REPLACE "\\$]+)>" "\\1" entry "${entry}") - list(APPEND SOURCEMETA_LIBRARY_FLATTENED "${entry}") + string(REGEX REPLACE "^\\$$" "\\1" unwrapped "${entry}") + if(unwrapped STREQUAL entry) + list(APPEND SOURCEMETA_LIBRARY_FLATTENED "${entry}") + else() + list(APPEND SOURCEMETA_LIBRARY_FLATTENED + "$" + "$") + endif() endforeach() set_property(TARGET ${TARGET_NAME} PROPERTY INTERFACE_LINK_LIBRARIES ${SOURCEMETA_LIBRARY_FLATTENED})