How tell qmake NOT to create a folder? - qmake

I want to configurate my qmake so it will make my executables go under ./build/debug (or release). I've done that sucessfully with the following code:
CONFIG(debug, debug|release) {
DESTDIR = ./build/debug
TARGET = mShareLibd
}
CONFIG(release, debug|release) {
DESTDIR = ./build/release
TARGET = mShareLib
}
Everything works fine apart from the fact that qmake still creates two folders, namely "debug" and "release" in the project's root directory - so I end up with a "build", a "debug" (always empty) and a "release" (always empty) folder.
How can I tell qmake NOT to create this two folders? I did this question in the QtCentre forum (here is the link), but the way provided didn't seem to me to be a reasonable one. Isn't there a more reasonable approach - such as just write a command which tells "qmake, don't create this folders"?
Thanks,
Momergil
EDIT
Bill asked me to copy and paste my .pro file here. Here are the resumed version (most of the header and source files not included)
#qmake defines
MSHARE_REPO = $${PWD}/..
MSHARE_COMMON = $${MSHARE_REPO}/Common
MSHARE_LIB = $${MSHARE_REPO}/mShareLib
MLOGGER = $${MSHARE_REPO}/../Classes/mLogger
#inclusion
QT += core gui network multimedia sql
qtHaveModule(printsupport): QT += printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += qwt
#CONFIG *= precompile_header
#PRECOMPILED_HEADER = stdafx.h
#HEADERS += stdafx.h
TARGET = mShare
TEMPLATE = app
VER_MAJ = 0
VER_MIN = 0
VER_PAT = 7
VERSION = $${VER_MAJ}.$${VER_MIN}.$${VER_PAT}
INCLUDEPATH += MSHARE_REPO \
MSHARE_COMMON \
C:\Qt\Qwt-6.1.0\include
LIBS += $${PWD}/SMTPEmail.dll
DEFINES += MGENERALDEFINES_GUI \
MGENERALDEFINES_DEBUG \
MGENERALDEFINES_GENERAL \
QWT_INCLUDED \
APP_VERSION=\\\"$$VERSION\\\"
win32 {
LIBS += -lpsapi
CONFIG(debug, debug|release) { #debug {
LIBS += C:/Qt/Qwt-6.1.0/lib/qwtd.dll \
$${MLOGGER}/build/debug/mLogger.dll \ #$${MLOGGER}/debug/mLoggerd.dll \
$${MSHARE_LIB}/build/debug/mShareLibd.dll
DEFINES += DEBUG
DESTDIR = ./build/debug
}
CONFIG(release, debug|release) { #release {
LIBS += C:/Qt/Qwt-6.1.0/lib/qwt.dll \
$${MLOGGER}/build/release/mLogger.dll \
$${MSHARE_LIB}/build/release/mShareLib.dll
DEFINES += RELEASE \
QT_NO_DEBUG \
QT_NO_DEBUG_OUTPUT
DESTDIR = ./build/release
}
} # win32
#others
MOC_DIR = $${DESTDIR}/.moc
OBJECTS_DIR = $${DESTDIR}/.obj
UI_DIR = $${DESTDIR}/.ui
RCC_DIR = $${DESTDIR}/.rcc
########################################################################
HEADERS += AppDefines.hpp \
mreadwrite.hpp \
system/appbrain.hpp \
...
SOURCES += main.cpp \
mreadwrite.cpp \
system/appbrain.cpp \
...
FORMS += \
interface/entracedialog.ui \
interface/validationdialog.ui \
...
OTHER_FILES += Files/CandlePatternProbabilities.txt \
Project_Files/Readme.txt \
...
RESOURCES += \
Icons.qrc \
Setups.qrc \
GeneralFiles.qrc
RC_FILE = icone.rc
#TRANSLATIONS += DEFAULT_THEME_PATH/translations/app_pt.ts \
# DEFAULT_THEME_PATH/translations/app_de.ts

I think I've found the solution by looking at the QMake's source code : set the "PRECOMPILED_DIR" variable.
It works with Qt 5. Since the QMake source code doesn't change a lot, I think it also works with Qt 4.
CONFIG(debug, debug|release) {
DESTDIR = ./build/debug
PRECOMPILED_DIR = ./build/debug
TARGET = mShareLibd
}
CONFIG(release, debug|release) {
DESTDIR = ./build/release
PRECOMPILED_DIR = ./build/release
TARGET = mShareLib
}

Related

How to create a py_library from a generated source tree

I am trying to consume some Python code + C extensions that are produced by CMake.
I'm using rules_foreign_cc to build the code, and it puts the code into an output directory, but I'm stumped as to how I can turn that into a py_library. I tried the below:
Depend on the cmake rule as srcs
Set imports to try to point to the directory containing the Python packages
But it doesn't work. When I run the py_test, the constructed PYTHONPATH doesn't point to the directory containing the python package from the cmake rule.
Thanks for any help!
Here's what I've got in my third_party/BUILD.bazel:
load("#rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
load("#rules_python//python:defs.bzl", "py_library", "py_test")
filegroup(
name = "torch_mlir_src",
srcs = glob(["torch-mlir/**"]),
)
make(
name = "torch_mlir",
...
install = False,
lib_source = ":torch_mlir_src",
out_data_dirs = ["python_packages"],
postfix_script = " && ".join([
"cp -r --dereference tools/torch-mlir/python_packages/torch_mlir $$INSTALLDIR$$/python_packages",
]),
targets = ["tools/torch-mlir/all"],
working_directory = "external/llvm-project/llvm",
)
# This doesn't seem to work.
py_library(
name = "torch_mlir_py",
srcs = [":torch_mlir"],
imports = ["$(BINDIR)/third_party/torch_mlir/python_packages"],
srcs_version = "PY3",
)
py_test(
name = "torch_mlir_annotations_sugar_test",
srcs = ["torch-mlir/python/test/annotations-sugar.py"],
main = "torch-mlir/python/test/annotations-sugar.py",
srcs_version = "PY3",
deps = [":torch_mlir_py"],
)

How do I get the files in the build directory in another bazel rule

when use the python tool to generate the .cpp/.hpp code like the protobuf tool, but I don't know how many files will be generated, so it's a little not the same as protbuf tool.
In one genrule:
def __generate_core_ifce_impl(ctx):
...
output_file = ctx.actions.declare_directory(out)
cmd = """
mkdir -p {path};
""".format(path = output_file.path)
cmd += """
{tools} -i {src} -o {output_dir}
""".format(tools = tools, src = ctx.files.srcs, output_dir = output_file.path)
ctx.actions.run_shell(
command = cmd,
inputs = ctx.files.srcs,
outputs = [output_file]
)
return [DefaultInfo(files = depset([output_file])),]
_generate_core_ifce = rule (
implementation = __generate_core_ifce_impl,
attrs = {
"srcs": attr.label_list(mandatory = False, allow_files = True),
"tools": attr.label_list(mandatory = True, allow_files = True),
"out": attr.sting(mandatory = True),
},
)
In output_file directory , there will generate some *.cpp && *.hpp, but i can't know their names
then in another rule , cc_library will use *.cpp && *.hpp which are in output_file directory
the questions is: how to write this rule?
I can't get the files in the output_file diectory,
so I can't write the cc_library?
You should be able to use the name of the target, and the cc_library will use the files that are given in the DefaultInfo, e.g.:
_generate_core_ifce(
name = "my_generate_core_ifce_target",
...
)
cc_library(
name = "my_cc_library_target",
srcs = [":my_generate_core_ifce_target"],
...
)
edit: adding an example:
BUILD:
load(":defs.bzl", "my_rule")
my_rule(
name = "my_target",
)
cc_binary(
name = "cc",
srcs = [":my_target"],
)
defs.bzl:
def _impl(ctx):
output_dir = ctx.actions.declare_directory("my_outputs")
command = """
mkdir -p {output_dir}
cat > {output_dir}/main.c <<EOF
#include "stdio.h"
#include "mylib.h"
int main() {
printf("hello world %d\\n", get_num());
return 0;
}
EOF
cat > {output_dir}/mylib.c <<EOF
int get_num() {
return 42;
}
EOF
cat > {output_dir}/mylib.h <<EOF
int get_num();
EOF
""".replace("{output_dir}", output_dir.path)
ctx.actions.run_shell(
command = command,
outputs = [output_dir]
)
return [DefaultInfo(files = depset([output_dir])),]
my_rule = rule(
implementation = _impl,
)
usage:
$ bazel run cc
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:cc (15 packages loaded, 57 targets configured).
INFO: Found 1 target...
Target //:cc up-to-date:
bazel-bin/cc
INFO: Elapsed time: 3.626s, Critical Path: 0.06s
INFO: 8 processes: 4 internal, 4 linux-sandbox.
INFO: Build completed successfully, 8 total actions
INFO: Build completed successfully, 8 total actions
hello world 42

Makefile, foreach eval, missing separator in define

after reading through plenty of Q/A here, i cannont identify any missing tabs in my targets.mk leading to this error:
../targets.mk:84: *** missing separator. Stop.
Here goes a code excerpt:
define CORNER_TEMPLATE
.PHONY : ${1}
${1} : ${BASEFILENAME}_${1}.lib
TARGET_FILES += ${BASEFILENAME}${1}.lib
${BASEFILENAME}${1}.lib : override TMPDIR = ${BASEFILENAME}.tmp
${BASEFILENAME}_${1}.lib : export LIBERATE_CHAR_CORNER_TXT = ${call LIBERATE_CHAR_CORNER, ${1}, ${CELLNAMES}}
${BASEFILENAME}_${1}.lib : export LIBERATE_CHAR_TCL_TXT = ${call LIBERATE_CHAR_TCL, ${TMPDIR}, ${1}}
${BASEFILENAME}_${1}.lib : ${addsuffix .spi, ${CELLNAMES}}
#mkdir -p ${TMPDIR}
#echo "$${LIBERATE_CHAR_CORNER_TXT}" > ${TMPDIR}/corner.tcl
#echo "$${LIBERATE_CHAR_TCL_TXT}" > ${TMPDIR}/char.tcl
#cat ${addsuffix .spi, ${CELLNAMES}} > ${TMPDIR}/liberate.spi
cd ${TMPDIR} && liberate char.tcl
#touch $$#
endef
Line 84:
${foreach CORNER, ${CORNERS}, ${eval ${call CORNER_TEMPLATE,${CORNER}}}}

How to make qmake to do a clean rebuild if DEFINES are changed

... which it should do but does not.
This is one of the major frustration of the qmake for me. qbs is our Qt future but for now we are stuck with qmake. So, what can be done?
I abuse QMAKE_EXTRA_COMPILERS to accompilsh this. I need to use it because I have to get DEFINES value after all features are processed.
# in this function all the work is done
defineReplace(checkDefinesForChanges) {
old_def = $$cat($$OUT_PWD/defines.txt)
curr_def = $$DEFINES
curr_def -= $$old_def
old_def -= $$DEFINES
diff = $$old_def $$curr_def
# delete all files in OUT_PWD if macros were changed
!isEmpty(diff) {
A = $$system(del /F /Q /S $$system_path($${OUT_PWD}/*.*))
message(DEFINES WERE CHANGED)
}
write_file($$OUT_PWD/defines.txt, DEFINES);
return(???)
}
# use QMAKE_EXTRA_COMPILERS to launch function
# checkDefinesForChanges after all features processing
_defines_check_ = ???
defines_check.name = check on defines being changed
defines_check.input = _defines_check_
defines_check.CONFIG += no_link ignore_no_exist
defines_check.depends = ???
defines_check.commands = ???
defines_check.output_function = checkDefinesForChanges
defines_check.clean = 333
QMAKE_EXTRA_COMPILERS += defines_check
# make sure qmake is run if deines.txt is deleted
recompile_on_defines_txt_not_existsing.target = $(MAKEFILE)
recompile_on_defines_txt_not_existsing.depends = $$OUT_PWD/defines.txt
recompile_on_defines_txt_not_existsing2.target = $$OUT_PWD/defines.txt
recompile_on_defines_txt_not_existsing2.depends = qmake
QMAKE_EXTRA_TARGETS += recompile_on_defines_txt_not_existsing recompile_on_defines_txt_not_existsing2
Source in Russian

How can I use qmake to copy files recursively

In my source tree I have a bunch of resources, I want to copy them with make install to my defined target path. Since the resource tree has many, many subdirectories, I want qmake to find all files recursively.
I tried:
resources.path = /target/path
resources.files += `find /path/to/resources`
INSTALLS += resources
and:
resources.path = /target/path
resources.files += /path/to/resources/*
resources.files += /path/to/resources/*/*
resources.files += /path/to/resources/*/*/*
resources.files += /path/to/resources/*/*/*/*
INSTALLS += resources
Both don't have the result I was hoping for.
I have done it like this:
res.path = $$OUT_PWD/targetfolder
res.files = sourcefolder
INSTALLS += res
this would copy "wherever this qmake script is"/sourcefolder into buildfolder/"same sub folder on build dir"/targetfolder
so you would have targetfolder/sourcefolder/"all other subfolders and files..."
Example:
#(My .pro file's dir) $$PWD = /mysources/
#(My Build dir) $$OUT_PWD = /project_build/
extras.path = $$OUT_PWD
extras.files += extras
src.path = $$OUT_PWD
src.files += src
INSTALLS += extras src
Would copy /mysources/extras to /project_build/extras and /mysources/src to /project_build/src
It appears that directories are installed with 'cp -r -f', so this does the trick:
resources.path = /target/path
resources.files += /path/to/resources/dir1
resources.files += /path/to/resources/dir2
resources.files += /path/to/resources/dir3
resources.files += /path/to/resources/dirn # and so on...
resources.files += /path/to/resources/* # don't forget the files in the root
INSTALLS += resources

Resources