How to make a library with the installed layout looks like Qt's internal modules (a.k. QtCore, QtQml, ect.)?
-
Environment
CMake
Ubuntu 24.04
- Qt 6.8.1/Online Installer
Case
I have wrote a an library named
Demo
, and it has some headers (i.e.welcome.h
forclass Welcome
, etc) for the library users.What I want?
when installed by
cmake install
, all headers keep the original case(all lower case) filename.
but I want get something like theQtCore
. that is to say, theDemo
library should be installed with a file tree like the following(which is the structure for qt internal modules like core, qml, widgets, etc.):├── include │ ├── Demo │ │ ├──1.0.0 │ │ │ └── Demo │ │ │ └── private │ │ │ ├── welcome_p.h │ │ │ ├── demo-config_p.h │ │ ├──Welcome │ │ ├──welcome.h │ │ ├──DemoVersion │ │ └──demoversion.h ├── lib │ ├── cmake │ │ ├── Demo │ │ │ ├── DemoConfig.cmake │ │ │ └── ... │ ├── libWelcome.so.1.0.0 │ ├── ... │ ├── pkgconfig │ │ ├── DemoWelcome.pc │ │ └── ... │ ├── DemoWelcome.debug │ └── ... ├── metatypes │ ├── demo_debug_metatypes.json │ └── ... ├── mkspecs │ └── modules │ ├── qt_lib_welcome.pri │ └── ... ├── modules │ ├── Welcome.json │ └── ... └── sbom └── demo-1.0.0.spdx
All in a word, how to make the library users use
Demo
like the way they useQtCore
, for example:- In
.cpp
/.h
file
#include <Demo/Welcome> // or #include <Welcome> // BUT NOT LIKE THIS: #include <demo/welcome.h>
- In
CMakeLists.txt
find_package(Demo 1.0.0) target_link_library(myapp Demo::Welcome)
Tried solutions
I have tried
qt_internal_project_setup()
/qt_internal_add_module()
, but it requires the project's major version must be same to Qt's major version, and it does not generate camel case wrappers for header files!So, the question is:
- I do not want to write any camel cased header wrappers manually, it should be auto generated, and how?
- Or, is it possible to make my own library with the experiences same to the QtCore for the end users?
-
@Sauntor said in How to make a library with the installed layout looks like Qt's internal modules (a.k. QtCore, QtQml, ect.)?:
All in a word, how to make the library users use Demo like the way they use QtCore, for example:
You cannot control how the users use the headers provided but you can give then the option of "clean" header names like <QWidget> the same way that Qt does it. The deployed headers files are:
- include - QtWidgets (directory) - QtWidgets (file) - QWidget (file) - qwidget.h (file)
The file "QWidget" simply contains:
#include "qwidget.h"
The file QtWidgets similarly includes all the headers for the entire module.
The
qmake
orcmake
setup ensures that theinclude/QtWidget
folder is added to the include path when the widget module is invoked (e.g. QT += widgets). Theinclude
folder is also present. So, the user can specify:// found via the top level include path #include <QtWidgets/QWidget> #include <QtWidgets/qwidget.h> // found via the QtWidgets include path #include <QtWidgets> #include <QWidget> #include <qwidget.h>
To do this for your library you need to deploy at least the "clean" files.
I do not want to write any camel cased header wrappers manually, it should be auto generated, and how?
You only need to do this once and check it in to your source control. It's probably faster than trying to automate. As for how you could automate this; there's no magic bullet here.