QMake install header files (copy to system's include directory) - c++

What variables and qmake-commands can I use to install (copy) header files of my qt-project to system's include directory (for example - /usr/include)?
I have tried an approach:
header_files.files = $$HEADERS
header_files.path = project/
INSTALLS += header_files
but it installs files not to include dir (of course because we have not set it). I've searched a variable in QMake Variables but did not found any useful.

You should make header_files.path the directory you want them to install into.
header_files.path = /usr/include
And the files you want to install should be in the header_files.files variable
header_files.files = directory_for_headers/*
Edit: If you need a cross-platform solution, you need to know the default include directories of your target system, and use it like this:
win32: header_files.path = win32_include_directory
linux: header_files.path = linux_include_directory
Edit: But I think if the user compiles with mingw, it should automatically put them in mingw's include directory, so you may need to use either /include or /usr/include. I'm not sure of that though. You need to test it on a Win machine.

Related

How to use hdfk library into qt?

How can I use HKDF library in my qt project? I found this library seems appropriate in qt (I checked with my source), but I couldn't include this header to project.
Adding a library to a Qt project is actually quite simple. In your qmake .pro file you need the following:
# This is the search location for the compiler to look for headers that accompany your library.
# For system libraries that typically resides under **/usr/include** or **/usr/local/include** if you used `make install`.
INCLUDEPATH+="/path/of/headers/for/library"
# This is the search location for the compiler/linker to look for the library itself.
# For system libraries this is usually somewhere under **/usr/lib** or **/usr/local/lib**
LIBS+= -L/path/of/library/itself
# This is the name of the library to include at link time
# without the **lib** prefix and the **.so** / **.a** / **.lib** / **.dll** extension.
LIBS+= -lMyLibraryName
# This is the full path of the library file itself
# *including* the aforementioned **lib** prefix and the **.so** / **.a** / **.lib** / **.dll** extension.
# This is used by qmake to look for changes to the library at build time,
# to make sure it is re-linked on change and other dependency related stuff
PRE_TARGETDEPS += /path/and/filename/of/library/itself/libMyLibraryName.lib
TIP: All the paths, unless they are specified as absolute paths (starting with '/') will be relative to the build directory. This might be the project directory, but in the case of shadow builds, it will be the shadow build directory. As a tip, simply prepend the following to your relative paths to make them relative to project directory: $$_PRO_FILE_PWD_/ so if for example your lib resides in /my/qt/project/libs/mylib you could make your project resilient to moving by using $$_PRO_FILE_PWD_/libs/mylib instead. Please note that the "project dir" is the location of the qmake .pro file.
I use CryptoPP HKDF implementation by https://www.cryptopp.com
Firstly, build static lib for valid architecture and for your platform (MacOS, Android, iOS, etc). CryptoPP Wiki has working manuals and scripts.
Then, just add 2 lines to your qmake *.pro file:
INCLUDEPATH += $$DEV_LIBS_PATH/cryptopp/$$ANDROID_ARCH/include
LIBS += -L$$DEV_LIBS_PATH/cryptopp/$$ANDROID_ARCH/lib -lcryptopp
as you can understand, I used qmake variables DEV_LIBS_PATH and ANDROID_ARCH which are just compose right path to relevant headers and static library libcryptopp.a.

How can I force cmake to use C++ header files in /usr/include in Linux?

I have a cmake project that uses a header installed in /usr/include, let's call it freeglut.h. When I use find_package(GLUT) I get ${GLUT_INCLUDE_DIR} pointing to /usr/include. All's well.
Now, I'm adding CUDA, which keeps its own copies of these and other headers in one of the paths included with find_package(CUDA). Normally I would resolve this by placing ${GLUT_INCLUDE_DIR} before ${CUDA_INCLUDE_DIRS} in include_directories(). However, on Unix systems cmake, in UnixPaths.cmake, maintains a list called CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES, which contains /usr/include and apparently keeps cmake from emitting -I<dir> arguments for the compiler for the directory /usr/include, meaning that the compiler searches the CUDA path first, and uses the freeglut.h header found there.
I have tried using list(REMOVE_ITEM ... to remove /usr/include from the CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES list, but that didn't change the compiler commands that cmake made.
I could of course start hacking around with the CUDA installation, delete the headers I don't want, or modify the CUDA_INCLUDE_DIRS variable, but is there a clean way to tell cmake to use the system header files first, if they exist?
I suppose the -idirafter flag should help you:
-idirafter dir
Search dir for header files, but do it after all directories specified with -I and the standard system directories have
been exhausted. dir is treated as a system include directory.
https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html
You can use it like this to lower CUDA include dirs priority:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -idirafter /usr/include/<CUDA_includes>")

Scons boost libraries in two different places

Our system has boost installed in two different places - one in /usr/... and the other is a custom install in another directory. I want to only include the headers/libs from the custom install but scons keeps picking up the standard path in /usr/...
Is there a way to force scons to only see the headers/libs in the custom directory. I have added this path to my CPPPATH variable, but the /usr/include path is also there which I do need for other c++ headers?
The include directories ("-I") are searched in left-to-right order and before standard paths (http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html)
Try prepending your CPPPATH using Prepend:
env = Environment()
env.Prepend(CPPPATH = ['/opt/boost'])
Here's the reference for Prepend:
http://www.scons.org/doc/HTML/scons-user/x1444.html#AEN1719

QAction: No such file or directory

I'm getting the error
QAction: No such file or directory
when I try to compile a project for plugin (C++ Library template). Weird, because I have a project for my app which also includes this header and there is no error. What might cause this?
For me I had some stale moc_ and ui_ files left over from compiling under a different version and configuration of Qt, so removing them solved the problem for me.
rm moc_* ui_* *.o
Make sure that you have the right include paths set up.
If you use QMake the *.pro should contain these settings if you want to include files from QtGui. They should be set by default but some templates may not set them.
CONFIG += qt
QT += gui
If you use another build system then make sure that you either use
#include <QtGui/QAction>
or you add $QTDIR/include/QtGui and not just $QTDIR/include to your include path

How do a specify a library file dependency for qmake in Qt?

Have a SomeLib.pro file that contains:
CONFIG += debug
TEMPLATE = lib
TARGET = SomeLib
..
Then in a dependent SomeApp.pro:
..
debug:LIBS += -lSomeLib_debug
..
How can I force SomeApp to build if I touched SomeLib in qmake?
It's ugly because you need to give the exact library file name, but this should work:
TARGETDEPS += libfoo.a
QT Creator will do the work if you click "Add library..." in the context menu of the project that should include the library.
These variables are configured automatically for you:
LIBS
INCLUDEPATH
DEPENDPATH
PRE_TARGETDEPS
See also http://doc.qt.digia.com/qtcreator-2.1/creator-project-qmake-libraries.html
In reply to Zahir's comment, it's perhaps worth pointing out that stating this dependency in qmake files is unnecessary if using DLLs, but is essential if your exe depends on a static library.
qmake does not provide this ability.
Instead, put your app and lib in subdirectories, then create a Makefile in their parent directory that looks something like this:
all: FRC
cd Somelib && qmake && $(MAKE)
cd SomeApp && qmake && $(MAKE)
FRC:
Then always run make from this directory.
I used:
POST_TARGETDEPS += c:/open-en/lib/win32mingw/libosal_based.a
It works, but is clumsy since it is necessary specify full path to library, which is different for every operating system/compiler.
surely that can't be possible, you are talking about using qmake to do a reverse dependency lookup? so what u want is for it to build app B (and any other app dependent on library A) after you've made a change to library A?
that's a bit like saying recompile all visual basic apps if vbrun300.dll is updated?