From 4fe99052f41d55c83bf0e5ffea657dc0af09780f Mon Sep 17 00:00:00 2001 From: Riccardo Schirone <562321+ret2libc@users.noreply.github.com> Date: Wed, 6 May 2026 12:04:34 +0200 Subject: [PATCH] build: propagate OpenSSL in CMake exports (#6284) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: NOT XVilka --- librz/RizinConfig.cmake.in | 32 ++++++++++++++++---------------- librz/RzModulesConfig.cmake.in | 26 ++++++++++++++++++++++++++ librz/meson.build | 5 +++++ librz/socket/meson.build | 9 +++++++-- librz/util/meson.build | 6 ++++++ 5 files changed, 60 insertions(+), 18 deletions(-) diff --git a/librz/RizinConfig.cmake.in b/librz/RizinConfig.cmake.in index 47872389b8..87688a93b3 100644 --- a/librz/RizinConfig.cmake.in +++ b/librz/RizinConfig.cmake.in @@ -79,33 +79,33 @@ set(_supported_components Util ) -get_filename_component(_rizin_cmake_path "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) +get_filename_component(_rizin_package_cmake_path "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) -foreach(_comp ${Rizin_FIND_COMPONENTS}) - string(TOLOWER ${_comp} _comp_lower) - if(NOT ";${_supported_components};" MATCHES ";${_comp};") +foreach(_rizin_component_name ${Rizin_FIND_COMPONENTS}) + string(TOLOWER ${_rizin_component_name} _rizin_component_lower) + if(NOT ";${_supported_components};" MATCHES ";${_rizin_component_name};") set(Rizin_FOUND False) - set(Rizin_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") + set(Rizin_NOT_FOUND_MESSAGE "Unsupported component: ${_rizin_component_name}") return() endif() - if (TARGET "Rizin::${_comp}") + if (TARGET "Rizin::${_rizin_component_name}") # Already got this component, trying to re-add the # target below would be an error continue() endif() - find_package(rz_${_comp_lower} PATHS ${_rizin_cmake_path} NO_DEFAULT_PATH) - if (NOT rz_${_comp_lower}_FOUND) + find_package(rz_${_rizin_component_lower} PATHS ${_rizin_package_cmake_path} NO_DEFAULT_PATH) + if (NOT rz_${_rizin_component_lower}_FOUND) set(Rizin_FOUND False) - set(Rizin_NOT_FOUND_MESSAGE "Failed to find Rizin component ${_comp}") + set(Rizin_NOT_FOUND_MESSAGE "Failed to find Rizin component ${_rizin_component_name}") return() endif() - add_library(Rizin::${_comp} UNKNOWN IMPORTED) - get_target_property(Rizin_${_comp}_LOCATION rz_${_comp_lower}::rz_${_comp_lower} IMPORTED_LOCATION) - set_target_properties(Rizin::${_comp} PROPERTIES - IMPORTED_LOCATION "${Rizin_${_comp}_LOCATION}" - IMPORTED_LINK_INTERFACE_LIBRARIES "${rz_${_comp_lower}_LIBRARIES}" - INTERFACE_LINK_DIRECTORIES "${rz_${_comp_lower}_LIBRARY_DIRS}" - INTERFACE_INCLUDE_DIRECTORIES "${rz_${_comp_lower}_INCLUDE_DIRS}") + add_library(Rizin::${_rizin_component_name} UNKNOWN IMPORTED) + get_target_property(Rizin_${_rizin_component_name}_LOCATION rz_${_rizin_component_lower}::rz_${_rizin_component_lower} IMPORTED_LOCATION) + set_target_properties(Rizin::${_rizin_component_name} PROPERTIES + IMPORTED_LOCATION "${Rizin_${_rizin_component_name}_LOCATION}" + IMPORTED_LINK_INTERFACE_LIBRARIES "${rz_${_rizin_component_lower}_LIBRARIES}" + INTERFACE_LINK_DIRECTORIES "${rz_${_rizin_component_lower}_LIBRARY_DIRS}" + INTERFACE_INCLUDE_DIRECTORIES "${rz_${_rizin_component_lower}_INCLUDE_DIRS}") endforeach() set(Rizin_PLUGINDIR @INSTALL_PLUGDIR@) diff --git a/librz/RzModulesConfig.cmake.in b/librz/RzModulesConfig.cmake.in index 8ce1f2665d..c0f39c6858 100644 --- a/librz/RzModulesConfig.cmake.in +++ b/librz/RzModulesConfig.cmake.in @@ -35,6 +35,7 @@ set_and_check(@RIZIN_MODULE@_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/@INSTALL_LIBDIR find_library(@RIZIN_MODULE@_LIBRARY NAMES @RIZIN_MODULE@ HINTS "${@RIZIN_MODULE@_LIBRARY_DIRS}" NO_DEFAULT_PATH REQUIRED) set(@RIZIN_MODULE@_LIBRARIES "${@RIZIN_MODULE@_LIBRARY}") set(_@RIZIN_MODULE@_DEPENDENCIES @RIZIN_MODULE_DEPS@) +set(_@RIZIN_MODULE@_EXTERNAL_CMAKE_DEPS "@RIZIN_MODULE_EXTERNAL_CMAKE_DEPS@") set(@RIZIN_MODULE@_PLUGINDIR @INSTALL_PLUGDIR@) include(CMakeFindDependencyMacro) @@ -55,6 +56,31 @@ foreach(_module_dep ${_@RIZIN_MODULE@_DEPENDENCIES}) list(APPEND _@RIZIN_MODULE@_DEPENDENCY_TARGETS "${_module_dep}::${_module_dep}") endforeach() +foreach(_rizin_external_cmake_dep ${_@RIZIN_MODULE@_EXTERNAL_CMAKE_DEPS}) + string(REPLACE "|" ";" _rizin_external_cmake_dep_parts "${_rizin_external_cmake_dep}") + list(GET _rizin_external_cmake_dep_parts 0 _rizin_external_cmake_dep_package) + list(GET _rizin_external_cmake_dep_parts 1 _rizin_external_cmake_dep_target) + + if (NOT ${_rizin_external_cmake_dep_package}_FOUND) + find_dependency(${_rizin_external_cmake_dep_package}) + endif() + + if (NOT ${_rizin_external_cmake_dep_package}_FOUND) + set(@RIZIN_MODULE@_FOUND False) + return() + endif() + + list(APPEND @RIZIN_MODULE@_LIBRARIES "${_rizin_external_cmake_dep_target}") + list(APPEND _@RIZIN_MODULE@_DEPENDENCY_TARGETS "${_rizin_external_cmake_dep_target}") + + if(TARGET "${_rizin_external_cmake_dep_target}") + get_target_property(_rizin_external_cmake_dep_include_dirs "${_rizin_external_cmake_dep_target}" INTERFACE_INCLUDE_DIRECTORIES) + if(_rizin_external_cmake_dep_include_dirs AND NOT _rizin_external_cmake_dep_include_dirs STREQUAL "_rizin_external_cmake_dep_include_dirs-NOTFOUND") + list(APPEND @RIZIN_MODULE@_INCLUDE_DIRS "${_rizin_external_cmake_dep_include_dirs}") + endif() + endif() +endforeach() + list(REMOVE_DUPLICATES @RIZIN_MODULE@_INCLUDE_DIRS) list(REMOVE_DUPLICATES @RIZIN_MODULE@_LIBRARIES) diff --git a/librz/meson.build b/librz/meson.build index 8ea5a4294e..aea186af95 100644 --- a/librz/meson.build +++ b/librz/meson.build @@ -60,6 +60,11 @@ foreach module_name, module : modules conf.set('RZ_VERSION', rizin_version) conf.set('RIZIN_MODULE', module['target'].name()) conf.set('RIZIN_MODULE_DEPS', ' '.join(module['dependencies'])) + if 'cmake_external_deps' in module + conf.set('RIZIN_MODULE_EXTERNAL_CMAKE_DEPS', ';'.join(module['cmake_external_deps'])) + else + conf.set('RIZIN_MODULE_EXTERNAL_CMAKE_DEPS', '') + endif conf.set('PACKAGE_RELATIVE_PATH', cmake_package_relative_path) conf.set('INSTALL_INCDIR', rizin_incdir) conf.set('INSTALL_LIBDIR', rizin_libdir) diff --git a/librz/socket/meson.build b/librz/socket/meson.build index e97c9c5c32..0c70ac54e5 100644 --- a/librz/socket/meson.build +++ b/librz/socket/meson.build @@ -10,9 +10,13 @@ rz_socket_sources = [ dependencies = [utl, rz_util_dep, platform_deps] rz_socket_deps = [] +rz_socket_public_deps = [] +rz_socket_public_cmake_deps = [] if sys_openssl.found() dependencies += [sys_openssl] + rz_socket_public_deps += [sys_openssl] + rz_socket_public_cmake_deps += ['OpenSSL|OpenSSL::Crypto'] endif if host_machine.system() == 'haiku' @@ -41,11 +45,12 @@ rz_socket = library('rz_socket', rz_socket_sources, ) rz_socket_dep = declare_dependency(link_with: rz_socket, - dependencies: [rz_util_dep], + dependencies: [rz_util_dep] + rz_socket_public_deps, include_directories: [platform_inc]) meson.override_dependency('rz_socket', rz_socket_dep) modules += { 'rz_socket': { 'target': rz_socket, - 'dependencies': ['rz_util'] + 'dependencies': ['rz_util'], + 'cmake_external_deps': rz_socket_public_cmake_deps }} diff --git a/librz/util/meson.build b/librz/util/meson.build index 21ad51c401..dbc304e0a8 100644 --- a/librz/util/meson.build +++ b/librz/util/meson.build @@ -103,6 +103,8 @@ rz_util_common_sources = [ rz_util_sources = rz_util_common_sources rz_util_deps = [ldl, lrt, mth, th, utl, pcre2_dep, softfloat_dep] + platform_deps +rz_util_public_deps = [] +rz_util_public_cmake_deps = [] if zlib_dep.found() rz_util_deps += [zlib_dep] endif @@ -123,6 +125,8 @@ endif if sys_openssl.found() rz_util_deps += [sys_openssl] + rz_util_public_deps += [sys_openssl] + rz_util_public_cmake_deps += ['OpenSSL|OpenSSL::Crypto'] rz_util_sources += ['big-ssl.c'] else rz_util_sources += ['big.c'] @@ -144,6 +148,7 @@ rz_util = library('rz_util', rz_util_sources, libsdb_sources, rz_util_dep = declare_dependency( link_with: rz_util, + dependencies: rz_util_public_deps, include_directories: rz_util_includes, ) meson.override_dependency('rz_util', rz_util_dep) @@ -203,6 +208,7 @@ endif modules += { 'rz_util': { 'target': rz_util, 'dependencies': [], + 'cmake_external_deps': rz_util_public_cmake_deps, 'include_subdirs_extra': ['librz/sdb'] }}