1

我有这个树结构:

repository/modules/module1
repository/modules/module2
repository/modules/module..
repository/apps/application1
repository/apps/application2
repository/apps/application..

应用程序使用某些模块的地方。

现在,我想将一些资源放在一个模块中(就像一个非常丰富多彩的图标在一个被多个应用程序使用的小部件中)但是.. 出了点问题。

如果我只使用模块 CMakeLists.txt 内部:

set(${MODULE_NAME}_RCS
    colors.qrc
)

...
qt4_add_resources   (${MODULE_NAME}_RHEADERS ${${MODULE_NAME}_RCS})

没有qrc_colors.cxx在任何地方创建。所以我尝试添加:

ADD_EXECUTABLE (${MODULE_NAME}
    ${${MODULE_NAME}_RHEADERS}
)

但是..我收到这个奇怪的错误:

CMake Error at repo/modules/ColorModule/CMakeLists.txt:51 (ADD_EXECUTABLE):
  add_executable cannot create target "ColorModule" because another
  target with the same name already exists.  The existing target is a static
  library created in source directory
  "repo/modules/ColorModule".  See documentation for
  policy CMP0002 for more details.

(我当然改变了错误的路径)

所以..不知道该怎么想,因为我对cmake和qt都是新手..

我可以尝试什么?

编辑:

如果我在 add_library 命令中添加${MODULE_NAME}_RHEADERSand ,则会创建qrc_colors.cxx但它在 repository/modules/module1/built 中,而不是在应用程序构建目录中复制...${MODULE_NAME}_RCS

4

1 回答 1

1

There is at least two errors in your code.

1) It is usually not necessary to use ${MODULE_NAME} everywhere like that, just "MODULE_NAME". You can see that the difference is the raw string vs. variable. It is usually recommended to avoid double variable value dereference if possible.

2) More importantly, you seem to be setting ${MODULE_NAME} in more than one executable place, which is "ColorModule" according to the error output. You should have individual executable names for different binaries.

Also, the resource file focus is a bit of red herring in here. There are several other issues with your project.

  • You can cmake files as CmakeLists.txt instead of CMakeLists.txt which inherently causes issues on case sensitive systes as my Linux box.

  • You use Findfoo.cmake, and find_package(foo) for that matter, rather than the usual FindFoo.cmake convention alongside find_package(Foo).

  • Your FindFoo.cmake is quite odd, and you should probably be rewritten.

  • Most importantly, you should use config files rather than find modules.

Documentation and examples can be found at these places:

http://www.cmake.org/Wiki/CMake/Tutorials#CMake_Packages

https://projects.kde.org/projects/kde/kdeexamples/repository/revisions/master/show/buildsystem

When you would like use a find module, you need to have that at hand already. That will tell you what to look for, where things are, or if they are not anywhere where necessary. It is not something that you should write. You should just reuse existing ones for those projects that are not using cmake, and hence the find modules are added separately.

It is a bit like putting the treasure map just next to the treasure. Do you understand the irony? :) Once you find the map, you would automatically have the treasure as well. i.e. you would not look for it anymore.

于 2013-09-25T19:36:34.507 回答