How to get platform dependent output filename with QMake? - qt

Assume I have a qmake project file *.pro:
# some stuff ...
TARGET = my_binary
# other stuff...
include( $$PWD/post.pri )
And inside the post.pri file (because I would like to reuse whatever this *.pri file does), I would like to get the complete name of the output file.
For example if is an app, then on windows I would like to get my_binary.exe and on linux my_binary. Or if the project is a shared lib, I would like to get my_binary.dll or libmy_binary.so respectively. Same if is a static lib, I would expect my_binary.lib and libmy_binary.a.
I have already tried the undocumented qmake variable QMAKE_FILE_OUT but with no success.

You can do this in your .pro script:
load(resolve_target)
message($$QMAKE_RESOLVED_TARGET)
It will output the build path and target name, according to your platform and project TEMPLATE.

Related

Why does `getResourceAsStream` sometimes load a resource even when there is a typo in the resource path?

I have a Jar (we'll call it a.jar) with a resource in it at path foo/bar.txt and a function as follows:
object FooBarLoader {
fun loadFooBarText() = javaClass.getResourceAsStream("foo//bar.txt")
?.bufferedReader()
?.readLines()
?.joinToString("\n")
}
When I test the function in a unit test (JUnit 4, running with Gradle 6), it loads the text from the resource file despite the obvious typo (the // in the middle of the resource path).
I also have a CLI application (in b.jar) that has a dependency on a.jar. When the CLI application calls loadFooBarText(), it got a null result due to the resource not being found. This was fixed by fixing the typo (// -> /) in the function in a.jar. No other changes were needed to fix it.
So, my question is why did the wrong path work in one situation (unit tests of a.jar) and not the other (call from b.jar)?
How do you run the unit test with a.jar ? Just run it in your IDE or use command java -jar a.jar ?
If you ran it just in IDE,I think difference is the search path between local files and zip files .
Your first application searches the file in your target directory and the second application searches it in the jar which is a compressed file.
When searching files in local path, command will be changed to right one by system.
The two commands below are the same in both Windows/Linux.
cd work//abc/ddd
cd work/abc/ddd
But when searching files in a jar file which is actually compressed zip file, path should be a restrict written or else the program will find nothing.

Symfony 5 and webpack encore in prod env : avoid hash string in build filename

When I run the command yarn build, some files are created in the public/build directory, generated files get a new filename containing a random hash string :
For only files themes/light and theme/dark I need to remove automatically the random hash string when I run the yarn build, I want to keep the original filename. I mean, currently the command generate theses files :
public/build/themes/light.3ac94fb2.css
public/build/themes/dark.064ff2f6.css
And instead, I want to have :
public/build/themes/light.css
public/build/themes/dark.css
Is it possible to do that automatically ?
If you don't mind having the files twice, one with the hash, one without, then the copyFiles plugin is probably the way to go:
This work adding, in your Encore configuration in webpack.config.js something like:
Encore
// Your usual config comes here
.copyFiles([
{
from: './assets/themes/light.css',
// or wherever the file lives in the assets folder
to: 'public/build/themes/light.css'
},{
from: './assets/themes/dark.css',
// or wherever the file lives in the assets folder
to: 'public/build/themes/dark.css'
}
])
;
Notice: untested – find more explanation here: https://symfonycasts.com/screencast/webpack-encore/copy-files
There is also a configureFilenames function, but I am not sure you'll be able to fit conditionals in it.

How to detect if current project is an app, a shared library or dynamic library in qmake?

I have a .pri file which can be included both in a library project and in an app project. Some details in there are dependent on the current build type (lib or app).
What is the recommended way to detect if the current project is either an executable, a static library or a dynamic library?
What is the recommended way to detect if the current project is either an executable, a static library or a dynamic library?
The bundled scripts do inspect TEMPLATE and CONFIG variables. Here is an example code to perform such tests:
defineReplace(projectType) {
contains(TEMPLATE, ".*lib") {
CONFIG(shared, static|shared): return("dynlib")
return("lib")
}
contains(TEMPLATE, ".*app"): return("app")
return("other")
}
# example usage
prj = $$projectType()
equals(prj, "app"): message("Building the application")
else: message("Doing something different")

extract files which is compiled in make process

u-boot support many platform. and there are files with same file name. it's hard to determine which file is involved in the make process for a certain platform. how could I get all files that be used in make process?
You could:
first, build u-boot for your target platform,
then look for all object files that resulted from the compilation process.
For example, if your u-boot main makefile were located in /opt/u-boot-2019.01,
the following commands would give you all the object files that were compiled:
cd /opt/u-boot-2019.01
find . -name "*.o"
You can then correlate the list of files you retrieved with the content of your target board's config file, usually located in the configs sub-directory.
In my case, the first object files to be displayed are:
./scripts/kconfig/zconf.tab.o
./scripts/kconfig/conf.o
./scripts/dtc/srcpos.o
./scripts/dtc/dtc.o
./scripts/dtc/treesource.o
./scripts/dtc/util.o
./scripts/dtc/fstree.o
./scripts/dtc/checks.o
./scripts/dtc/flattree.o
./scripts/dtc/dtc-parser.tab.o
./scripts/dtc/livetree.o
./scripts/dtc/dtc-lexer.lex.o
./scripts/dtc/data.o
./arch/arm/cpu/built-in.o
./arch/arm/cpu/armv8/built-in.o
./arch/arm/cpu/armv8/cpu-dt.o
./arch/arm/cpu/armv8/cache_v8.o
./arch/arm/cpu/armv8/generic_timer.o
./arch/arm/cpu/armv8/exceptions.o
./arch/arm/cpu/armv8/lowlevel_init.o
./arch/arm/cpu/armv8/fwcall.o
./arch/arm/cpu/armv8/cpu.o
./arch/arm/cpu/armv8/start.o
./arch/arm/cpu/armv8/cache.o
./arch/arm/cpu/armv8/transition.o
./arch/arm/cpu/armv8/tlb.o
./arch/arm/mach-sunxi/built-in.o
./arch/arm/mach-sunxi/clock.o
./arch/arm/mach-sunxi/dram_helpers.o
./arch/arm/mach-sunxi/pinmux.o
./arch/arm/mach-sunxi/prcm.o
./arch/arm/mach-sunxi/board.o
./arch/arm/mach-sunxi/clock_sun6i.o
./arch/arm/mach-sunxi/cpu_info.o
./arch/arm/mach-sunxi/rsb.o
For example, the fact that the file ./arch/arm/mach-sunxi/rsb.o is in the list means that ./arch/arm/mach-sunxi/rsb.c was compiled during the build process and contributed to the resulting u-boot image.

QT: No rule to make target 'res/resources.qrc'

I've switched versions of QT (from 5.10.1 to 5.12.2) to get a more recent version of Mingw32 (from GCC/G++ 5.3 -> 7.3). The reasoning behind this is that have multiple products using the same library and using an old version of gcc is less than ideal. We've never had any issues with build before, but now I get the following error:
":-1: error: No rule to make target 'res/resources.qrc', needed by 'release/qrc_resources.cpp'. Stop."
Oddly enough, it does not stop the build from generating a completely functioning executable.
So far I've tried:
Cleaning the directory and building again
Deleting the build directory and building again
Not selecting shadow build option
Forcing Qmake (Build -> Run Qmake)
Creating a new .pro.user file
Deleting the whole repo, cloning it again, rebuilding the dependencies (we have a library which it relies on) and rebuilding QT
Adding the .qrc file to the includes (I know this was silly, but I was at my wits end)
Checking for deleted files (None that I can see)
Checking file names for inconsistencies(They seem ok)
Here is my qrc file
<RCC>
<qresource prefix="/">
<file>images/cnctbtn_connected.png</file>
<file>images/cnctbtn_connecting.png</file>
<file>images/cnctbtn_disconnected.png</file>
<file>images/configbtn.png</file>
<file>images/flash.png</file>
<file>images/logbtn.png</file>
<file>images/streambtn_start.png</file>
<file>images/streambtn_stop.png</file>
<file>images/d_logo_outlined.ico</file>
<file>images/d_logo_small.png</file>
<file>images/d_logo_small_outlined.png</file>
</qresource>
</RCC>
The list of resources which are located in the images folder
cnctbtn_connected.png
cnctbtn_connecting.png
cnctbtn_disconnected.png
configbtn.png
d_logo_small.png
d_logo_small_outlined.png
flash.png
logbtn.png
streambtn_start.png
streambtn_stop.png
d_logo_outlined.ico
The qrc_resource_File.cpp also looks ok. I see the bytes of the images in it, their names and assorted namespace declarations and functions in that name space.
The one thing I'm unsure of is why the images folder has it's on name in the resource name list.
Note: I've removed the bytes in this array, for my eyes and yours.
static const unsigned char qt_resource_name[] = {
// images
// cnctbtn_disconnected.png
// cnctbtn_connected.png
// cnctbtn_connecting.png
// streambtn_start.png
// d_logo_outlined.ico
// d_logo_small.png
// streambtn_stop.png
// d_logo_small_outlined.png
};
Ideally there would be no build error, which I don't really understand since I can see and use the executable produced. If you need any other information, don't hesitate to ask!

Resources