Using #BASENAME# with install_dir of custom_target() in Meson - meson-build

#BASENAME# does not appear to work in the install_dir: parameter of the Meson custom_target() function.
protoc = find_program('protoc')
protobuf_sources= [
'apples.proto',
'oranges.proto',
'pears.proto'
]
protobuf_generated_go = []
foreach protobuf_definition : protobuf_sources
protobuf_generated_go += custom_target('go_' + protobuf_definition,
command: [protoc, '--proto_path=#CURRENT_SOURCE_DIR#', '--go_out=paths=source_relative:#OUTDIR#', '#INPUT#'],
input: protobuf_definition,
output: '#BASENAME#.pb.go',
install: true,
install_dir: 'share/gocode/src/github.com/foo/bar/protobuf/go/#BASENAME#/'
)
endforeach
I need the generated files to end up in at directory based on the basename of the input file:
share/gocode/src/github.com/foo/bar/protobuf/go/apples/apples.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/oranges/oranges.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/pears/pears.pb.go
If I use #BASENAME# in install_dir: to try and create the directory needed, it does not expand, and instead just creates a literal '#BASENAME#' directory.
share/gocode/src/github.com/foo/bar/protobuf/go/#BASENAME#/apples.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/#BASENAME#/oranges.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/#BASENAME#/pears.pb.go
How can the required installed directory location based on the basename be achieved?
(just 3 files in the above example, I actually have 30+ files)

Yes, it looks as there is no support for placeholders like BASENAME for install_dir parameter since this feature aims at file names not directories. But you can process iterator that is string in a loop:
foreach protobuf_definition : protobuf_sources
...
install_dir: '.../go/#0#'.format(protobuf_definition.split('.')[0])
endforeach

Related

Converting a meson.build library to CMakeLists

So, one of my uni courses uses a meson.build system for one of the libraries we have to use.
The library is organized like
this
Now, using CLion, I have trouble linking to that library. Earlier I have been trying cloning it, and setting target_include_directories to the src and includefolders.
For some reason that didn't do the trick, and I'm now trying to convert the meson.build file to a CMakeFiles which I can just add/compile.
The file looks like:
project('animationwindow', ['c', 'cpp'], version: '0.01', default_options: ['cpp_std=c++17', 'default_library=static', 'buildtype=debugoptimized'])
if host_machine.system() == 'windows'
sdl2_dep = subproject('sdl2_windows').get_variable('sdl2_windows_dep')
sdl2image_dep = subproject('sdl2_image_windows').get_variable('sdl2_image_windows_dep')
else
sdl2_dep = dependency('sdl2')
sdl2image_dep = dependency('sdl2_image')
endif
build_files = [
'src/internal/FontCache.cpp',
'src/internal/KeyboardKeyConverter.cpp',
'src/internal/nuklear_implementation.cpp',
'src/widgets/Button.cpp',
'src/widgets/TextInput.cpp',
'src/widgets/DropdownList.cpp',
'src/AnimationWindow.cpp',
'src/Color.cpp',
'src/Image.cpp',
'src/Widget.cpp']
incdir = include_directories('include')
animationwindow = static_library('animationwindow', build_files, include_directories: incdir, dependencies: [sdl2_dep, sdl2image_dep], install: true)
install_subdir('include', install_dir: '.')
install_subdir('src', install_dir: '.')
animationwindow_dep = declare_dependency(link_with: animationwindow, include_directories: incdir)
import('pkgconfig').generate(animationwindow)
# ex = executable('prog', 'src/test.cpp', include_directories: incdir, dependencies: [sdl2_dep, imgui_dep], link_with: animationwindow)
I have converted that to:
cmake_minimum_required(VERSION 3.16)
project(animationwindow)
set(CMAKE_CXX_STANDARD 17)
find_package(SDL2 REQUIRED)
add_executable(
animationwindow
src/internal/FontCache.cpp
src/internal/KeyboardKeyConverter.cpp
src/internal/nuklear_implementation.cpp
src/widgets/TextInput.cpp
src/widgets/Button.cpp
src/widgets/DropdownList.cpp
src/AnimationWindow.cpp
src/Color.cpp
src/Image.cpp
src/Widget.cpp
)
include_directories(animationwindow include)
The question now is, how do I link this from the main file. Can I just somehow link the CMakeLists, or do I have to precomile the library and then somehow add it?

use 'source_group' generate the Xcode project can't jump the right directory path

I used the CMake to build an iOS XCode project, I have multiple level source code, so I use 'source_group' to organize them, here is my CMake code
file(GLOB_RECURSE MODULE_DEMO_DIR_FILES
"${MODULE_DEMO_DIR}/*.h"
"${MODULE_DEMO_DIR}/*.m"
"${MODULE_DEMO_DIR}/*.c"
"${MODULE_DEMO_DIR}/*.cc"
"${MODULE_DEMO_DIR}/*.cpp"
"${MODULE_DEMO_DIR}/info.plist"
"${MODULE_DEMO_DIR}/LaunchScreen.storyboard"
"${MODULE_DEMO_DIR}/*.entitlements"
)
foreach(file IN LISTS MODULE_DEMO_DIR_FILES)
message(DEBUG "file:${file}")
get_filename_component(fileDirectory ${file} DIRECTORY)
include_directories(${fileDirectory})
endforeach()
set(${MODULE_DEMO_SOURCES} ${MODULE_DEMO_DIR_FILES} PARENT_SCOPE)
source_group(TREE ${MODULE_DEMO_DIR} FILES ${MODULE_DEMO_DIR_FILES})
when I select any directory and right-click and select 'show in Finder', it does not jump right directory, in the xcodeproj file, I find the directory PBXGroup is this:
8CD0C75957674E25982ACF10 /* IQTextView */ = {
isa = PBXGroup;
children = (
8D7EEDCDA3CC4AA6A444A78F /* /Users/lee/Desktop/xx1/demo/company/xx2/xx3/demo/Vendor/IQKeyboardManager/IQTextView/IQTextView.h */,
F54B85341C9A4BC7BD92320D /* /Users/lee/Desktop/xx1/demo/company/xx2/xx3/demo/Vendor/IQKeyboardManager/IQTextView/IQTextView.m */,
);
name = IQTextView;
sourceTree = "<group>";
};
when I change the "name = IQTextView;" to "path = IQTextView;",it works!
my question is:
how let the PBXGroup use 'path' instead of 'name' when using CMake, so that I can jump to the true path when clicking "show in Finder" at a directory in XCode project?

Why do I get a `java.nio.file.ProviderMismatchException` when I access `isEmpty()` on a staged file

I am getting a java.nio.file.ProviderMismatchException when I run the following script:
process a {
output:
file _biosample_id optional true into biosample_id
script:
"""
touch _biosample_id
"""
}
process b {
input:
file _biosample_id from biosample_id.ifEmpty{file("_biosample_id")}
script:
def biosample_id_option = _biosample_id.isEmpty() ? '' : "--biosample_id \$(cat _biosample_id)"
"""
echo \$(cat ${_biosample_id})
"""
}
i'm using a slightly modified version of Optional Input pattern.
Any ideas on why I'm getting the java.nio.file.ProviderMismatchException?
In your script block, _biosample_id is actually an instance of the nextflow.processor.TaskPath class. So to check if the file (or directory) is empty you can just call it's .empty() method. For example:
script:
def biosample_id_option = _biosample_id.empty() ? '' : "--biosample_id \$(< _biosample_id)"
I like your solution - I think it's neat. And I think it should be robust (but I haven't tested it). The optional input pattern that is recommended will fail when attempting to stage missing input files to a remote filesystem/object store. There is a solution however, which is to keep an empty file in your $baseDir and point to it in your scripts. For example:
params.inputs = 'prots/*{1,2,3}.fa'
params.filter = "${baseDir}/assets/null/NO_FILE"
prots_ch = Channel.fromPath(params.inputs)
opt_file = file(params.filter)
process foo {
input:
file seq from prots_ch
file opt from opt_file
script:
def filter = opt.name != 'NO_FILE' ? "--filter $opt" : ''
"""
your_commad --input $seq $filter
"""
}

Is there QMake analogue for ".." from bash?

I'm writing a unit test using QtTest framework. I have a .pro file representing test project where i want to specify a relative path to the source files i want to test with INCLUDEPATH keyword. The source files are in the source folder, which is 2 levels above the .pro file in folder hierarchy. So, if i were to get there with bash i would go with cd .. then cd .. then cd source. I tried INCLUDEPATH += $$PWD/../../source, but this doesn't seem to work. I also couldn't find any related info in Qt docs.
How can i achieve the behaviour i want from qmake? Any help would be great.
There is a builtin (replace) function called clean_path. Documented here.
The following code did the trick for me:
defineReplace(cleanPath) {
win32:1 ~= s|\\\\|/|g
contains(1, ^/.*):pfx = /
else:pfx =
segs = $$split(1, /)
out =
for(seg, segs) {
equals(seg, ..):out = $$member(out, 0, -2)
else:!equals(seg, .):out += $$seg
}
win32:return($$join(out, \\, $$pfx))
return($$join(out, /, $$pfx))
}
srs_path = $$_PRO_FILE_PWD_/../../source
srs_path_clean = $$cleanPath($$srs_path)
INCLUDEPATH += $$srs_path_clean

How to use exec statement in a sourced file in Tcl

I am trying to use the following command in a file sourced by another one but the variable doesn't seem to be usefull. The PYTHONPATH var is filled by lib//site-packages and not lib/python2.7/site-packages
my_path:
set pyver [ exec python -c {import sys;print 'python%d.%d'%(sys.version_info[0],sys.version_info[1])} ]enter code here
array set paths {
PATH bin
PYTHONPATH lib/$pyver/site-packages
}
main:
#%Module1.0########################################
##
## Modulefile for texworks
#
source my_path
foreach p [array names paths] {
prepend-path $p $paths($p)
}
If you initialize the array paths like this:
array set paths {
PATH bin
PYTHONPATH lib/$pyver/site-packages
}
the braces around the member initializations prevent variable substitution of the variable pyver. To allow the variable to be substituted, you need to either replace the braces by double quotes (which is somewhat poor style) or write this as
array set paths [list \
PATH bin \
PYTHONPATH lib/$pyver/site-packages \
]
or (setting each member individually)
set paths(PATH) bin
set paths(PYTHONPATH) lib/$pyver/site-packages
or (forcing substitution)
array set paths [subst {
PATH bin
PYTHONPATH lib/$pyver/site-packages
}]
Documentation: array, list, set, subst