Search code examples
c++qtcmakeqt5definition

Qt5 CMake can't find C++ STD library if a definition is added in CMakeLists.txt


Here is the problem I am struggling with.

I am using CMake to build my Qt5 GUI project. I am using a custom module QML-material project from GitHub. The problem is that as it is said in the project documentation - in order to setup the module for your project, you should add a definition:

add_definitions("-DQPM_INIT\(E\)=E.addImportPath\(QStringLiteral\(\"qrc:/\"\)\)\;")

But if this definition is added in CMakeLists.txt the project can't find C++ STD library. If I comment it out the STD features can be used again.

About the definition meaning.

This macro basically calls addImportPath("qec:/") to the argument it is called with. In my case it is in main():

// Working example
QQmlApplicationEngine engine;
QPM_INIT(engine);

But if I just change it and call addImportPath straight forward and remove the definition it doesn't find the custom QML modules.

// Not working example
QQmlApplicationEngine engine;
engine.addImportPath(QStringLiteral("qrc:/"));

My questions:

  • Why a definition in CMake can block the project linking with the STD lib?
  • Why if I replace the macro with its representation in the main() function it doesn't work?
  • Does anyone have a proposal how to use both the custom module and the STD library together?

NB! The Qt libraries are still visible. The problem is only with the STD.


Solution

  • Most of the compilers does not tolerate function like definitions. Adding such a macro with add_definition is a workaround as it adds the macro to CXX_FLAGS, not to CXX_DEFINES, but apparently it doesn't work properly too.