Add QML files to Qt Creator project tree with CMake

I have a library called qml_components containing basic QML graphical elements. I'd like to add these files to the project tree, without building them. I've been able to regroup them in a variable, by doing the following:

CMAKE_MINIMUM_REQUIRED(VERSION 3.4)
CMAKE_POLICY(SET CMP0003 NEW)

PROJECT(myApp)

FILE(GLOB QML_SRC "*.qml")

I then tried to add them to my library target :

# Add QML files to project tree without building/compiling them
ADD_CUSTOM_TARGET(myApp ${QML_SRC})

While researching I read that ADD_CUSTOM_TARGET could add the files to the sources without building them:

The SOURCES option specifies additional source files to be included in the custom target. Specified source files will be added to IDE project files for convenience in editing even if they have not build rules.

It doesn't seem to work. I think the probable cause is that I do not generate any binaries from this library, hence the failure when trying to link the sources to the TARGET .


I had forgotten to add the SOURCES keyword in the command...

ADD_CUSTOM_TARGET(myApp SOURCES ${QML_SRC})

I'm leaving this thread open as it could be of useful information to others.

链接地址: http://www.djcxy.com/p/79000.html

上一篇: 如何构建一个自定义的eglfs光标图集?

下一篇: 使用CMake将QML文件添加到Qt Creator项目树中