Archive:Development/CMake FAQ (zh CN): Difference between revisions
(Created page with '{{Template:I18n/Language Navigation Bar|Development/CMake FAQ}} == 常见问题 == These are KDE's FAQ for CMake, there is also a CMake FAQ in the [http://www.cmake.org/Wiki/CMa...') |
m (AnneW moved page Development/CMake FAQ (zh CN) to Archive:Development/CMake FAQ (zh CN) without leaving a redirect: Obsolete) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
== 常见问题 == | == 常见问题 == | ||
Line 15: | Line 15: | ||
依照上面说明的在 ADD_CUSTOM_COMMAND() 中使用这个 shell 脚本包装。 | 依照上面说明的在 ADD_CUSTOM_COMMAND() 中使用这个 shell 脚本包装。 | ||
您可以通过查询 WRAPPER_SCRIPT 来找到名称和确切的路径。这里有一个来自 kdelibs/kstyles/keramik/ 的完整例子: | 您可以通过查询 WRAPPER_SCRIPT 来找到名称和确切的路径。这里有一个来自 kdelibs/kstyles/keramik/ 的完整例子: | ||
< | <syntaxhighlight lang="text"> | ||
# build the executable | # build the executable | ||
kde4_add_executable(genembed RUN_UNINSTALLED ${genembed_SRCS}) | kde4_add_executable(genembed RUN_UNINSTALLED ${genembed_SRCS}) | ||
Line 28: | Line 28: | ||
DEPENDS genembed ${keramikPics} | DEPENDS genembed ${keramikPics} | ||
) | ) | ||
</ | </syntaxhighlight> | ||
如你所见 genembed 也做为相赖关系列出。这表示 CMake 知道它应该在执行这些规则之前建构 genembed 执行档。 | 如你所见 genembed 也做为相赖关系列出。这表示 CMake 知道它应该在执行这些规则之前建构 genembed 执行档。 | ||
Line 41: | Line 41: | ||
传递 VERBOSE 变数给 make,例如: | 传递 VERBOSE 变数给 make,例如: | ||
< | <syntaxhighlight lang="text"> | ||
% make VERBOSE=1 | % make VERBOSE=1 | ||
</ | </syntaxhighlight> | ||
或 | 或 | ||
< | <syntaxhighlight lang="text"> | ||
% VERBOSE=1 make | % VERBOSE=1 make | ||
</ | </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 61: | Line 61: | ||
'''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): | '''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): | ||
< | <syntaxhighlight lang="text"> | ||
optimized;C:/kde4/lib/QtNetwork4.lib;debug;C:/kde4/lib/QtNetworkd4.lib | optimized;C:/kde4/lib/QtNetwork4.lib;debug;C:/kde4/lib/QtNetworkd4.lib | ||
^^^^^^^^^ | ^^^^^^^^^ | ||
</ | </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.'' |
Latest revision as of 15:17, 23 June 2013
常见问题
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.