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.

I don’t think compilers generally support callable macro definitions on the command line.

Do you have the error message available?

You are right. Yesterday I solved it as I removed the macro. That is a bad workaround of using function like definition, because it is added to CXX_FLAGS, not to CXX_DEFINES. If I try to use add_compile_definition that adds it to CXX_DEFINES instead of add_definition I get a message that function like definitions are not tolerated. So, do not use macros that way :slight_smile: