Archive:Development/CMake FAQ (zh CN): Difference between revisions

From KDE TechBase
m (Text replace - "<code>" to "<syntaxhighlight lang="text">")
m (Text replace - "</code>" to "</syntaxhighlight>")
Line 28: Line 28:
   DEPENDS genembed ${keramikPics}
   DEPENDS genembed ${keramikPics}
)
)
</code>
</syntaxhighlight>


如你所见 genembed 也做为相赖关系列出。这表示 CMake 知道它应该在执行这些规则之前建构 genembed 执行档。
如你所见 genembed 也做为相赖关系列出。这表示 CMake 知道它应该在执行这些规则之前建构 genembed 执行档。
Line 43: Line 43:
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
% make VERBOSE=1
% make VERBOSE=1
</code>
</syntaxhighlight>
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
% VERBOSE=1 make
% VERBOSE=1 make
</code>
</syntaxhighlight>


更多细节请查看 CMake wiki:[http://www.cmake.org/Wiki/CMake_FAQ#Is_there_an_option_to_produce_more_.27verbose.27_compiling.3F 有没有选项可以产生更多的'verbose'编译?]
更多细节请查看 CMake wiki:[http://www.cmake.org/Wiki/CMake_FAQ#Is_there_an_option_to_produce_more_.27verbose.27_compiling.3F 有没有选项可以产生更多的'verbose'编译?]
Line 64: Line 64:
optimized;C:/kde4/lib/QtNetwork4.lib;debug;C:/kde4/lib/QtNetworkd4.lib
optimized;C:/kde4/lib/QtNetwork4.lib;debug;C:/kde4/lib/QtNetworkd4.lib
^^^^^^^^^
^^^^^^^^^
</code>
</syntaxhighlight>


The first <tt>optimized</tt> part is translated by cmake to optimized.lib so we have got the ''cannot open file 'optimized.lib' error.''
The first <tt>optimized</tt> part is translated by cmake to optimized.lib so we have got the ''cannot open file 'optimized.lib' error.''

Revision as of 20:49, 29 June 2011


Development/CMake FAQ

常见问题

These are KDE's FAQ for CMake, there is also a CMake FAQ in the main CMake wiki.

如何让我最喜欢的编辑器支持 CMake 语法和缩排?

请阅读CMake Wiki 的 CMake 编辑器支持章节。这里说明如何设定 Emacs(XEmacs works too)、VIM、Kate、KWrite 和 KDevelop。

我需要在建构过程中产生一些档案,我该怎么做?

使用 ADD_CUSTOM_COMMAND()。在 CMake wiki 的如何在建构过程中生成原始码档案有解释

我想在建构过程中建立一个稍后使用的可执行文件。我该怎么做?

假设可执行文件叫 genembed。那么使用 KDE4_ADD_EXECUTABLE(foo RUN_UNINSTALLED ${fooSources})来建立可执行文件。RUN_UNINSTALLED 选项非常重要,因为可执行文件必须从建构目录执行,并会链接到建构目录中的一些函式库。为了达成这个目的,可执行文件透过 RPATH 设定和 shell 脚本包装编译,和执行档的名称一样只是多了个「.sh」。这个 shell 脚本建立 LD_LIBRARY_PATH 并呼叫实际的执行档。

依照上面说明的在 ADD_CUSTOM_COMMAND() 中使用这个 shell 脚本包装。 您可以通过查询 WRAPPER_SCRIPT 来找到名称和确切的路径。这里有一个来自 kdelibs/kstyles/keramik/ 的完整例子:

# build the executable
kde4_add_executable(genembed RUN_UNINSTALLED ${genembed_SRCS})

# get the name of the generated wrapper script (which sets up LD_LIBRARY_PATH)
get_target_property(GENEMBED_EXECUTABLE genembed WRAPPER_SCRIPT)

# and the custom command
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/keramikrc.h
  COMMAND ${GENEMBED_EXECUTABLE} --file ${CMAKE_CURRENT_BINARY_DIR}/keramikPics.txt > \
  ${CMAKE_CURRENT_BINARY_DIR}/pixmaps.keramik
  DEPENDS genembed ${keramikPics}
)

如你所见 genembed 也做为相赖关系列出。这表示 CMake 知道它应该在执行这些规则之前建构 genembed 执行档。

我不想设定 -DCMAKE_INSTALL_PREFIX 命令行参数。CMake 是否支持 KDEDIR 环境变量?

不。KDE 4 反对使用 $KDEDIR。

为什么我会得到/usr/lib/qt4/include/QtCore/qstring.h:536: undefined reference to `QString::fromLatin1_helper(char const*, int)'之类的编译错误?

如果你有旧版的 Qt 4 在 qt/lib 目录,你必须删除这些旧版(4.0.1)档案。

我要怎么让 CMake 创建 noisy makefiles?我希望看到 make 过程执行的指令。

传递 VERBOSE 变数给 make,例如:

% make VERBOSE=1

% VERBOSE=1 make

更多细节请查看 CMake wiki:有没有选项可以产生更多的'verbose'编译?

产生的 Makefiles 中没有 'make distclean' 标签。我该如何才能清理包括 cache 档案在内的所有档案?

只需删除建构目录,或建构目录里的内容。

I've got fatal error LNK1104: cannot open file 'optimized.lib' under Windows/msvc (release with debug info build)

This is a problem with KDE's CMakeLists.txt and CMake 2.6.0 and 2.6.1, it will be fixed soon.

QT_*_LIBRARIES must not be used in your target_link_libraries() line of CMakeLists.txt. Use QT_*_LIBRARY instead. Otherwise the variable will look like this (example for QT_QTNETWORK_LIBRARY):

optimized;C:/kde4/lib/QtNetwork4.lib;debug;C:/kde4/lib/QtNetworkd4.lib
^^^^^^^^^

The first optimized part is translated by cmake to optimized.lib so we have got the cannot open file 'optimized.lib' error.