mesonbuild / meson

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

dependency('Ceres') does not extract include paths via CMake #6661

Open nh2 opened 4 years ago

nh2 commented 4 years ago

Describe the bug

When I use ceres-solver 1.13, which is detected via Meson's CMake integration, like this:

ceres_dep = dependency('Ceres')

and use ceres_dep in my project dependencies, -I flags do not get added as expected.

build/meson-info/intro-dependencies.json shows:

  {
    "name": "Ceres",
    "version": "1.13.0",
    "compile_args": [],
    "link_args": [
      "/nix/store/9ffwh04wqhz1daq0hllj4sgsjwbby7k6-ceres-solver/lib64/libceres.so.1.13.0"
    ]
  },

and compile_args, where the -I include flags usually are, is empty.

However, if I log them manually with

ceres_dep = dependency('Ceres')
ceres_includes = ceres_dep.get_variable(cmake: 'PACKAGE_INCLUDE_DIRS')
error('@0@'.format(ceres_includes))

then they get printed as expected.

Relevant log output in build/meson-logs/meson-log.txt:

Called `/nix/store/6v4qwcbgzz8vflcdh10waimm75bpvqpc-pkg-config-0.29.2/bin/pkg-config --modversion Ceres` -> 1

CMake binary for MachineChoice.HOST is not cached
CMake binary missing from cross or native file, or env var undefined.
Trying a default CMake fallback at cmake
Trying CMake binary cmake for machine MachineChoice.HOST at ['/nix/store/bk0ckiyq2dspfli699mscpd5qmdnqhnv-cmake-3.16.3/bin/cmake']
Found CMake: /nix/store/bk0ckiyq2dspfli699mscpd5qmdnqhnv-cmake-3.16.3/bin/cmake (3.16.3)
Extracting basic cmake information
Try CMake generator: auto
No CFLAGS in the environment, not changing global flags.
No LDFLAGS in the environment, not changing global flags.
No CPPFLAGS in the environment, not changing global flags.
Called `/nix/store/bk0ckiyq2dspfli699mscpd5qmdnqhnv-cmake-3.16.3/bin/cmake --trace-expand .` in /home/niklas/src/myproject/cpp/build/meson-private/cmake_Ceres -> 0
  -- Module search paths:    ['/nix/store/bk0ckiyq2dspfli699mscpd5qmdnqhnv-cmake-3.16.3']
  -- CMake root:             /nix/store/bk0ckiyq2dspfli699mscpd5qmdnqhnv-cmake-3.16.3/share/cmake-3.16
  -- CMake architectures:    ['i386-linux-gnu', 'x86_64-linux-gnu']
  -- CMake lib search paths: ['lib', 'lib32', 'lib64', 'libx32', 'share', 'lib/i386-linux-gnu', 'lib/x86_64-linux-gnu']

Determining dependency 'Ceres' with CMake executable '/nix/store/bk0ckiyq2dspfli699mscpd5qmdnqhnv-cmake-3.16.3/bin/cmake'
Try CMake generator: auto
No CFLAGS in the environment, not changing global flags.
No LDFLAGS in the environment, not changing global flags.
No CPPFLAGS in the environment, not changing global flags.
Called `/nix/store/bk0ckiyq2dspfli699mscpd5qmdnqhnv-cmake-3.16.3/bin/cmake --trace-expand -DNAME=Ceres -DARCHS=i386-linux-gnu;x86_64-linux-gnu -DCMAKE_PREFIX_PATH=/nix/store/bk0ckiyq2dspfli699mscpd5qmdnqhnv-cmake-3.16.3;/nix/store/awh5gnf5p0a97bl0h9pfpbf8g1iv4fkf-meson-0.53.1;/nix/store/v3rwd0gqjzvr8zppxy3w0nli2q7n0j54-ninja-1.8.2;/nix/store/vis2cx3qs20kxvx8590v5zhjf5ff12cx-ccache-3.4.1;[...stuff...];/nix/store/9ffwh04wqhz1daq0hllj4sgsjwbby7k6-ceres-solver;[...stuff...];/nix/store/3vzaz5x80psv2r8hr72zq2x8kv7wcpia-lz4-131 .` in /home/niklas/src/myproject/cpp/build/meson-private/cmake_Ceres -> 0
Guessed CMake target 'ceres'
CMake TARGET:
  -- name:      ceres
  -- type:      SHARED
  -- imported:  True
  -- properties: {
      'IMPORTED_CONFIGURATIONS': ['RELEASE']
      'IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE': ['/nix/store/965fzm6404ny21b0v6wbh3x6wgwf6diy-glog-0.3.5/lib/libglog.so']
      'IMPORTED_LOCATION_RELEASE': ['/nix/store/9ffwh04wqhz1daq0hllj4sgsjwbby7k6-ceres-solver/lib64/libceres.so.1.13.0']
      'IMPORTED_SONAME_RELEASE': ['libceres.so.1']
     }
  -- tline: CMake TRACE: /nix/store/9ffwh04wqhz1daq0hllj4sgsjwbby7k6-ceres-solver/lib/cmake/Ceres/CeresTargets.cmake:54 add_library(['ceres', 'SHARED', 'IMPORTED'])
Include Dirs:         []
Compiler Definitions: []
Compiler Options:     []
Libraries:            ['/nix/store/9ffwh04wqhz1daq0hllj4sgsjwbby7k6-ceres-solver/lib64/libceres.so.1.13.0']
Run-time dependency ceres found: YES 1.13.0

It determines Libraries: correctly, but sets Include Dirs to [].

The output Guessed CMake target 'ceres' suggests that we're in this branch:

https://github.com/mesonbuild/meson/blob/76ae8658645c3e697bdf95777bbd36df7c1dd622/mesonbuild/dependencies/base.py#L1340-L1349

system parameters

mensinda commented 3 years ago

Could you please try again with a newer version of Meson (0.58.0)? I am unable to reproduce this bug with Ceres 2.0.0:

Guessed CMake target 'Ceres::ceres'
CMake TARGET:
  -- name:      Ceres::ceres
  -- type:      SHARED
  -- imported:  True
  -- properties: {
      'INTERFACE_COMPILE_FEATURES': ['cxx_std_14']
      'INTERFACE_INCLUDE_DIRECTORIES': ['/usr/include']
      'INTERFACE_LINK_LIBRARIES': ['Threads::Threads', 'glog::glog', 'gflags', 'Eigen3::Eigen']
      'IMPORTED_CONFIGURATIONS': ['RELEASE']
      'IMPORTED_LOCATION_RELEASE': ['/usr/lib/libceres.so.2.0.0']
      'IMPORTED_SONAME_RELEASE': ['libceres.so.2']
     }
  -- tline: CMake TRACE: /usr/lib64/cmake/Ceres/CeresTargets.cmake:63 add_library(['Ceres::ceres', 'SHARED', 'IMPORTED'])
[
  {
    "name": "Ceres",
    "version": "2.0.0",
    "compile_args": [
      "-DGFLAGS_IS_A_DLL=0",
      "-I/usr/include",
      "-I/usr/include/eigen3"
    ],
    "link_args": [
      "-lpthread",
      "/usr/lib/libceres.so.2.0.0",
      "/usr/lib/libgflags.so.2.2.2",
      "/usr/lib/libglog.so.0.5.0"
    ]
  }
]

Also, if the include dirs are only stored in PACKAGE_INCLUDE_DIRS, then I would argue that the CMake files are broken since this is a very non-standard variable to store them in. Even more so if they are not present in the imported target definitions...