mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.51k stars 1.6k forks source link

Possible bug: dependencies isolated from cmake projects? #13588

Open ethindp opened 3 weeks ago

ethindp commented 3 weeks ago

I'm using the openssl wrap but I need it for a CMake dependency. The problem is that CMake can't find it even though I've dependency()'d it. An example snippet from my meson.build:

# Project setup...
openssl = dependency('openssl', static: true)
caf_opts = cmake.subproject_options()
caf_opts.add_cmake_defines(
    {
        'CAF_ENABLE_CURL_EXAMPLES': false,
        'CAF_ENABLE_PROTOBUF_EXAMPLES': false,
        'CAF_ENABLE_QT6_EXAMPLES': false,
        'CAF_ENABLE_ROBOT_TESTS': false,
        'CAF_ENABLE_RUNTIME_CHECKS': get_option('buildtype').startswith('debug')? true : false,
        'CAF_ENABLE_EXAMPLES': false,
        'CAF_ENABLE_EXCEPTIONS': true,
        'CAF_ENABLE_IO_MODULE': true,
        'CAF_ENABLE_NET_MODULE': true,
        'CAF_ENABLE_TESTING': false,
        'CAF_ENABLE_OPENSSL_MODULE': true,
        'CAF_CXX_VERSION': 20,
    },
)
caf_proj = cmake.subproject('caf', options: caf_opts)
caf = declare_dependency(
    dependencies: [
        caf_proj.dependency('core'),
        caf_proj.dependency('io'),
        caf_proj.dependency('net'),
    ],
)

With wrap:

[wrap-git]
url=https://github.com/actor-framework/actor-framework.git
revision=1.0.1

Is this a bug, or intended behavior? Is there some way of getting dependencies to propagate to CMake projects?

dcbaker commented 3 weeks ago

How does the caf CMake build expect to find OpenSSL?

ethindp commented 3 weeks ago

@dcbaker It uses the standard find_package system.

dcbaker commented 3 weeks ago

Which means it's using FindOpenSSL. It looks like there's a -DOPENSSL_ROOT_DIR option to pass to cmake in this case, but figuring out we need that option and passing it around might not be trivial... hmmm.

dcbaker commented 3 weeks ago

Or correctly intercepting the find_package call. I'll have to dig into what the cmake module is doing a bit more

dcbaker commented 3 weeks ago

Out of curiosity, does it work with static : false (or the static option removed)?

ethindp commented 3 weeks ago

Uh... No, it doesn't appear to find it if it's configured without static either. It's not on my system, either, or at least, not in a path CMake knows about, hence my desire to just tell Meson to build it.

eli-schwartz commented 3 weeks ago

This is actually just #8089

There was an attempt at getting -uninstalled.pc files forwarded into the cmake subproject so that find_package(PkgConfig) and pkg_check_modules(OPENSSL IMPORTED_TARGET GLOBAL openssl) would work. But the PR had, uh, teething problems, so it ended up being closed.

ethindp commented 2 weeks ago

I'm wondering if we could just generate findXXXX.cmake/XXXX-Config.cmake files that just use pkgconfig (ensuring that CMake finds ours) and then let's CMake do the rest? It's uncommon, but I think it might be better to start with.