question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `@CURRENT_SOURCE_DIR@` to `custom_command`

See original GitHub issue

Describe the bug Continuing from #7511

There may be a possible regression with 0.57 where @CURRENT_SOURCE_DIR@ has been removed from custom_target. I realize that’s not in the manual, but removing CURRENT_SOURCE_DIR broke my build and I can’t figure out a working replacement.

0.56.2 generates this build.ninja

...
build proto/settings.pb.cc: CUSTOM_COMMAND ../proto/settings.proto | /usr/bin/protoc
 COMMAND = /usr/bin/protoc --proto_path=../proto --cpp_out=proto ../proto/settings.proto
 description = Generating$ settings_pb_cc$ with$ a$ custom$ command

build proto/settings.pb.h: CUSTOM_COMMAND ../proto/settings.proto | /usr/bin/protoc
 COMMAND = /usr/bin/protoc --proto_path=../proto --cpp_out=proto ../proto/settings.proto
 description = Generating$ settings_pb_h$ with$ a$ custom$ command
 ...

0.57 generates:

build proto/settings.pb.cc: CUSTOM_COMMAND ../proto/settings.proto | /usr/bin/protoc
COMMAND = /usr/bin/protoc --proto_path=@CURRENT_SOURCE_DIR@ --cpp_out=proto ../proto/settings.proto
description = Generating$ settings_pb_cc$ with$ a$ custom$ command

build proto/settings.pb.h: CUSTOM_COMMAND ../proto/settings.proto | /usr/bin/protoc
COMMAND = /usr/bin/protoc --proto_path=@CURRENT_SOURCE_DIR@ --cpp_out=proto ../proto/settings.proto
description = Generating$ settings_pb_h$ with$ a$ custom$ command

To Reproduce

meson.build

protobuf = dependency('protobuf', version: '>=3.0.0')
protoc = find_program('protoc')

# many thanks to @marcelhollerbach for his solution.
# https://github.com/mesonbuild/meson/issues/7511#issuecomment-665470520

settings_pb_cc = custom_target('settings_pb_cc',
  input: ['settings.proto'],
  output: ['@BASENAME@.pb.cc'],
  command: [
    protoc,
    '--proto_path=@CURRENT_SOURCE_DIR@',
    '--cpp_out=@OUTDIR@',
    '@INPUT@',
  ]
)

settings_pb_h = custom_target('settings_pb_h',
  input: ['settings.proto'],
  output: ['@BASENAME@.pb.h'],
  command: [
    protoc,
    '--proto_path=@CURRENT_SOURCE_DIR@',
    '--cpp_out=@OUTDIR@',
    '@INPUT@',
  ],
  install: true,
  install_dir: get_option('includedir') / meson.project_name(),
)

settings_incdir = include_directories('.')

libazabacheproto = library(meson.project_name() + 'proto', settings_pb_cc,
  version: meson.project_version(),
  dependencies: protobuf,
  # FIXME(mdegans): remove this when moving to a 20.04 rootfs with new protobuf
  # becuase of this bug: https://github.com/protocolbuffers/protobuf/issues/4628
  cpp_args: ['-Wno-unused-parameter'],
  install: true,
)

azabacheproto_dep = declare_dependency(
  link_with: libazabacheproto,
  include_directories: include_directories('.'),
  dependencies: protobuf,
)

# generate a separate .pc for just the protobuf code.
pkg = import('pkgconfig')
azabacheproto_pc = pkg.generate(libazabacheproto,
  description: 'Azabache Camera Metadata Library',
  url: project_url,
  # for consistency with existing cmake install:
  install_dir: get_option('datadir') / 'pkgconfig',
  subdirs: meson.project_name(),
)

Any setttings.proto should do.

As a workaround, i tried '--proto_path=' + meson.current_source_dir(), but this doesn’t seem to do the same thing. protoc does not like absolute paths, apparently:

[1/56] Generating settings_pb_cc with a custom command
FAILED: proto/settings.pb.cc 
/usr/bin/protoc --proto_path=/home/user/Projects/lib-azabache/proto --cpp_out=proto ../proto/settings.proto
../proto/settings.proto: File does not reside within any path specified using --proto_path (or -I).  You must specify a --proto_path which encompasses this file.  Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
[2/56] Generating settings_pb_h with a custom command
FAILED: proto/settings.pb.h 
/usr/bin/protoc --proto_path=/home/user/Projects/lib-azabache/proto --cpp_out=proto ../proto/settings.proto
../proto/settings.proto: File does not reside within any path specified using --proto_path (or -I).  You must specify a --proto_path which encompasses this file.  Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
[3/56] Compiling C++ object src/libazabache-0.1.so.p/encoder.cpp.o
FAILED: src/libazabache-0.1.so.p/encoder.cpp.o 

Expected behavior @CURRENT_SOURCE_DIR in custom_target to be replaced with the crurrent source dir, or for there to be a usable replacement. Per the referenced issue, generator was unsuitable for this task. I’m using custom target, actually two of them, since I couldn’t figure out a cleaner way.

system parameters

  • plain, native build
  • Ubuntu 18.04 aarch64 (Tegra)
  • Python 3.6.9
  • meson 0.57
  • ninja 1.8.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
xclaessecommented, Feb 16, 2021

@mdegans Indeed, also notice how replace_paths() does not exist in vs2010backend.py, so those never worked there.

1reaction
xclaessecommented, Feb 15, 2021

There are millions of subtle inconsistencies in what is supported in add_*_script(), run_target(), custom_target(), and generator(). I’m working on refactoring them all to use as much as possible the same code path there: https://github.com/mesonbuild/meson/pull/8342.

That refactor is for 0.58, not sure we want a “fix” for 0.57 since it was never documented…

Read more comments on GitHub >

github_iconTop Results From Across the Web

CMake Tutorial — CMake 3.18.6 Documentation
Specify Compile Definition. Adding a Custom Command and Generated File (Step 6). Building an Installer (Step 7). Adding Support for a Dashboard (Step...
Read more >
How to copy contents of a directory into build directory after ...
To copy the directory itself instead of the contents, you can add /${FOLDER_NAME} to the end of the second parameter. Like this:
Read more >
Development/Tools/Automoc4 - KDE TechBase
The automoc4 macro adds a custom command that outputs a source file that is then added to the sources for the target.
Read more >
root/RootMacros.cmake at master · root-project/root - GitHub
The official repository for ROOT: analyzing, storing and visualizing big data, scientifically - root/RootMacros.cmake at master · root-project/root.
Read more >
CMake-tutorial-pdf.pdf - BogoToBogo
Add an executable to the project using the specified source files. ... for command : add custom command, in order to add some....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found