meson: How to get a target 's name in meson - meson-build

I add a shared_library target in meson.build
libmali = shared_library(
'mali',
dummy_source,
install : true,
version : meson.project_version()
)
I want to get the libmali's name "mali" by code elsewhere in this meson.build.
how to get?
is there any api like libmali.getname() ?

Yes, but only since Meson 0.45; shared_library() returns a build target object, which has a method name() since the aforementioned version.

Related

CMake set per configuration linker flag

As the title states, is there a 'neat' way to set per configuration linker flag? It is not possible for me to use target_link_options() since I'm trying to link into a static library. Ideally, what I would want to achieve is to set Visual Studio's Librarian -> Additional Dependencies and Additional Library Directories and achieve the same result in XCode as well.
Here is what I've achieved so far:
set(LIB_LINKS_RUNTIME
${Vulkan_LIBRARIES}
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/SDL2maind.lib
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/SDL2d.lib
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/imgui.lib
)
foreach(lib ${LIB_LINKS_RUNTIME})
set (CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${lib}")
endforeach()
According to https://cmake.org/cmake/help/latest/prop_tgt/STATIC_LIBRARY_OPTIONS.html STATIC_LIBRARY_OPTIONS property does the trick
set_property(TARGET Runtime PROPERTY STATIC_LIBRARY_OPTIONS ${LIB_LINKS_RUNTIME})

Add compiler flag only if --default-library=shared is used

The meson build system allows to either build shared or static libraries with the option --default-library. However I am not able to know if a shared or static library is being built and I need that to pass at least a define. Is there a way to query the library type?
This was my guess:
libtype = get_option('default-library')
if libtype = 'shared'
build_dll = ['-DBUILDING_DLL', '-fvisibility=hidden']
else
build_dll = ''
endif
But apparently I get:
Meson encountered an error in file meson.build, line 10, column 0:
Tried to access unknown option "default-library".
In case someone else has this issue, the solution is simple:
libtype = get_option('default_library')
(note the underscore instead of the dash)
(Credit for the answer goes to jpakkane (the creator of meson), who answered on IRC)

Specifying build parameters to FAKE

I am essentially asking for an update to date answer to the already answered question: Can I pass a parameter to a F# FAKE build script?
Here is build.fsx
let revisionNumber = getBuildParamOrDefault "rev" "123"
Target "Log" (fun _ ->
trace ("Revision Number: " + revisionNumber)
)
RunTargetOrDefault "Log"
Output running Fake.exe .\build.fsx:
Perfect!
Output running Fake.exe .\build.fsx rev=456 (as suggested by this answer: https://stackoverflow.com/a/26597179/2382536):
Starts with
But at the bottom gives the correct result:
What format do I need to pass the parameters in to get rid of the warning message?
Passing parameters is done using the --envvar parameter. Until recently you can just add parameters in a way you did after the build target but not anymore. I believe this was changed in order not to confuse build parameters with (optional) build target name.
So, try this:
fake build.fsx Push --envvar rev 456
I just want to share the link to the official documentation:
TLDR:
You can either use
--envvar [-ev] <name:string> <value:string>
to set a variable to a custom value, or
--envflag [-ef] <name:string>
to set a variable to true, or
--fsiargs --debug+ buildscript.fsx someArg1 anotherArg2
to pass all arguments (including build script name, importent!) direcly to fsi.exe

Link static library to shared library or to a binary

I have a static library from the project A (let's call it liba.so) and I want to compile a shared library in my project B (let's call it libb.so) and embed liba.so in it.
Also, I have a binary in that project B which also depends on liba.so, so I want to embed it in the binary.
Is that possible? How?
When A is a Separate Code Base
What you do is build and install project A. Then create a dependency on project A in project B's definition.
That looks like this:
a_dep = dependency('a', version : '>=1.2.8')
lib_b = shared_library('proj_b', sources: 'prog_b.c', dependencies : a_dep)
The version section in dependency is optional.
When A is in the Same Meson Project as B
When A and B are in the same meson project, it's a little uglier. You have to declare a dependency anchor in A.
That looks like this:
incdirs = include_directories('include')
lib_a = static_library('a', 'proj_a.c', include_directories : indirs)
liba_dependency = declare_dependency(
include_directories : incdirs,
link_with : lib_a,
sources : ['proj_a.c'])
Then project B becomes:
lib_b = shared_library('proj_b', sources: 'prog_b.c', dependencies : lib_a)
If you have an existing, precompiled library, then you can directly wrap it in a dependency:
cpp = meson.get_compiler('cpp')
# (Meson requires an absolute path for find_library().)
libdir = meson.current_source_dir() + './lib/
precompiledA_dep = cpp.find_library('A', dirs : libdir) # ./lib/libA.lib
...
# Link against libA.lib here ...
B_lib = library('libB', 'libB.cpp', dependencies : precompiledA_dep)
B_exe = executable('exeB', 'source.cpp', dependencies : precompiledA_dep)
(tested with Meson 0.57)

How to get BuildId in MSBuild?

When I build my project, I can get ${BuildNumber} variable.
BuildNumber can be customized by "UpdateBuildNumber" activity. In this activity we can use ${BuildId} to formate ${BuildNumber}.
But how to get separately ${BuildId} variable?
If you're looking for the BuildNumber:
Use the BuildDetail's BuildNumber property when setting the BuildNumberFormat property of the UpdateBuildNumber build step.
In the example build XAML below, the BuildNumberFormat property is set to:
newBuildString + BuildDetail.BuildNumber
newBuildString is a variable, but could also be a string:
"v1.2.0." + BuildDetail.BuildNumber
If you're looking for the BuildID:
The TFS internal BuildID can be extracted from the URI for the build, as accessed from the IBuildDetail object (see above).
This can be accessed using the following code:
LinkingUtilities.DecodeUri(BuildDetail.Uri.ToString()).ToolSpecificId;
See: https://social.msdn.microsoft.com/Forums/vstudio/en-US/ab8140a2-a236-40d0-b146-dd8f6f4eb4ce/getting-buildid-value-in-a-tfs-2010-build-workflow-activity?forum=tfsbuild