mesonbuild / meson

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

The CMake module doesn't allow for native dependencies when cross compiling #8043

Open robbert-vdh opened 3 years ago

robbert-vdh commented 3 years ago

I'm not sure whether this counts as a bug or as a feature request.

Describe the bug When cross compiling (i.e. with --cross-file), it is not possible to use include('cmake').subproject('foo').dependency('bar') in a native build target. This is possible when using regular subprojects and with dependency(). <cmake_subproject>.dependency() also does not support the native option.

To Reproduce

  1. Create a project with a meson.build file like this:

    # meson.build
    project('projectname', 'cpp', version : '1.0.0')
    
    cmake = import('cmake')
    vst3_sdk_options = cmake.subproject_options()
    vst3_sdk_options.add_cmake_defines({
     'SMTG_ADD_VST3_HOSTING_SAMPLES': 'OFF',
     'SMTG_ADD_VST3_PLUGINS_SAMPLES': 'OFF',
     'SMTG_ADD_VSTGUI': 'OFF',
    })
    vst3_sdk = cmake.subproject('vst3', options : vst3_sdk_options)
    vst3_pluginterfaces_dep = vst3_sdk.dependency('pluginterfaces')
    
    shared_library(
     'some-library',
     ['src/some-library.cpp'],
     native : true,
     dependencies : [vst3_pluginterfaces_dep],
    )

    With some arbitrary cross.conf file, for instance:

    # cross.conf
    [binaries]
    c = 'gcc'
    cpp = 'g++'
    ar = 'ar'
    strip = 'strip'
    pkgconfig = 'pkg-config'

    And the following wrap file in subprojects/vst3.wrap (any CMake project will work, this is just how I ran into this issue):

    # subprojects/vst3.wrap
    [wrap-git]
    url = https://github.com/robbert-vdh/vst3sdk.git
    revision = 2a1a230d45766532360a2f432083f0795f2b0d93
    clone-recursive = true
    depth = 1
  2. Create an empty src/some-library.cpp file.

  3. Now try to initialize the project with meson setup build --cross-file cross.conf.

Expected behavior The project gets created without any errors. Running ninja -C build should compile the empty file without any issues.

Observed behavior Meson errors out during meson setup with the following error:

meson.build:14:3: ERROR: Tried to mix libraries for machines 0 and 1 in target 'some-library' This is not possible in a cross build.

system parameters

mensinda commented 3 years ago

As far as I know, CMake does not have the equivalent of the meson native system. So a CMake project is either completely cross, or completely native.

Do you want to compile the entire subproject as native?

robbert-vdh commented 3 years ago

I would want to have the subproject both as native and as non-native in the same meson.build file, so having both a vst3_sdk_native and a vst3_sdk_cross in that example meson.build I posted above would be perfect. I'm building an application that consists of both a native library and a cross compiled binary that both share most of the same dependencies.

mensinda commented 3 years ago

This should be fairly easy to implement with the cmake.subproject_options() to specifically set the native kwarg for all/some targets.

Assuming the project itself does not specify platform-specific defines/compiler options that mess up the final build...

robbert-vdh commented 3 years ago

Ouch yeah side effects like that sound like it could make having both a native and a non-native copy of the same CMake subproject a bit tricky. I didn't want to reinvent the wheel so I tried making it work with the CMake module first, but I'll just write my own meson.build file for the subproject for the time being. Cross-builds are always a bit tricky, so I'm interested to see how if a good solution to this issue is possible!

robbert-vdh commented 3 years ago

I came to the conclusion that using native library dependencies from subprojects also doesn't work when cross compiling, is this correct or am I missing something? So in a subproject (using wrap-git) I have a Meson build definition that defines a static library and declares a dependency for it. I couldn't figure out a way to use this dependency with both my native and my non-native targets. For the time being I've just resorted to exporting all of the sources, include directories and compiler options needed to build those libraries and then I just assemble the dependencies myself in my own project's meson.build file, but that of course is one giant hack.

dcbaker commented 3 years ago

Ya, its a know deficiency, it's on my list is things to fix, but it's non trivial