{"id":1346,"date":"2011-12-21T03:40:57","date_gmt":"2011-12-20T19:40:57","guid":{"rendered":"https:\/\/www.csslayer.tk\/wordpress\/?p=1346"},"modified":"2011-12-21T03:40:57","modified_gmt":"2011-12-20T19:40:57","slug":"my-cmake-tutorial-1","status":"publish","type":"post","link":"https:\/\/www.csslayer.info\/wordpress\/cmake\/my-cmake-tutorial-1\/","title":{"rendered":"My CMake Tutorial 1"},"content":{"rendered":"<p>CMake \u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u5f00\u6e90\u6784\u5efa\u7cfb\u7edf\u3002<\/p>\n<p>1\u3001CMake\u7684\u8bde\u751f<\/p>\n<p>\u65e2\u7136\u7ef4\u57fa\u767e\u79d1\u6709\u6211\u5c31\u4e0d\u591a\u8bf4\u4e86\u3002<\/p>\n<p><a href=\"http:\/\/zh.wikipedia.org\/wiki\/CMake\">http:\/\/zh.wikipedia.org\/wiki\/CMake<\/a><\/p>\n<p>2\u3001\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528CMake<\/p>\n<p><a href=\"http:\/\/lwn.net\/Articles\/188693\/\">http:\/\/lwn.net\/Articles\/188693\/<\/a>\u00a0 Why the KDE project switched to CMake &#8212; and how<\/p>\n<p>\u539f\u56e0\u4e4b\u4e00\u662f\u8de8\u5e73\u53f0\uff0c\u672c\u6765\u4ed6\u4eec\u60f3\u91c7\u7528 SCons \u4f5c\u4e3a\u6784\u5efa\u7cfb\u7edf\uff0c \u4f46\u5728\u8de8\u5e73\u53f0\u4e0a\u9047\u89c1\u4e86\u8bb8\u591a\u95ee\u9898\u3002CMake\u7684\u4f18\u52bf\u5728\u4e8e\u5b83\u53ea\u4f9d\u8d56\u4e8eC++\u7f16\u8bd1\u5668\uff0c\u8de8\u5e73\u53f0\uff0c\u53ef\u4ee5\u751f\u6210\u5404\u4e2a\u5e73\u53f0\u7279\u5b9a\u7684Makefile\u548c\u5de5\u7a0b\u6587\u4ef6\uff0c\u5e76\u4e14\u652f\u6301\u5355\u5143\u6d4b\u8bd5\u3002<\/p>\n<p>\u53e6\u5916\u4e00\u70b9\u5c31\u662f\u6027\u80fd\uff0c\u4f46\u6211\u4e00\u65f6\u95f4\u627e\u4e0d\u5230\u5177\u4f53\u7684\u5f15\u7528\u4e86\u3002<\/p>\n<p>3\u3001\u4f7f\u7528CMake\u7684\u57fa\u672c\u65b9\u6cd5<\/p>\n<pre>mkdir build\r\ncd build\r\ncmake ..\r\nmake\r\nmake install<\/pre>\n<p>\u9488\u5bf9\u4e00\u822c\u7528\u6237\u6765\u8bf4\u5c31\u662f\u4ee5\u4e0a\u5185\u5bb9\uff0c\u548c\u5f53\u5e74\u7684\u4f20\u7edf configure make \u5f88\u50cf\u5427\uff1f<\/p>\n<p>4\u3001\u7b2c\u4e00\u4e2a\u9879\u76ee<\/p>\n<pre>cmake_minimum_required (VERSION 2.6)\r\nproject(test)\r\n\r\nadd_executable(test test.cpp)<\/pre>\n<p>cmake\u9879\u76ee\u4e00\u5f00\u59cb\u90fd\u9700\u8981\u6307\u5b9acmake\u7684\u6700\u4f4e\u7248\u672c\uff0c\u4e00\u822c\u6765\u8bf42.6\u5373\u53ef\uff0c\u6700\u65b0\u7248\u662f2.8.6\u3002\u7b2c\u4e8c\u884c\u5236\u5b9a\u9879\u76ee\u540d\u79f0\uff0c\u5176\u6b21\u5c31\u662f\u6dfb\u52a0\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u6e90\u4ee3\u7801\u662f test.cpp \u3002\u8fd9\u6837cmake\u5c31\u4f1a\u7f16\u8bd1\u751f\u6210\u4e00\u4e2atest\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p>\u5f53\u7136\u4e00\u4e2a\u597d\u4e60\u60ef\u662f\u4e3a\u4e00\u5806\u6587\u4ef6\u8bbe\u7f6e\u4e00\u4e2a\u53d8\u91cf\u540d\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<a href=\"http:\/\/code.google.com\/p\/fcitx\/source\/browse\/src\/core\/CMakeLists.txt\">http:\/\/code.google.com\/p\/fcitx\/source\/browse\/src\/core\/CMakeLists.txt<\/a><\/p>\n<pre>\u00a0set(FCITX_SOURCES\r\n\u00a0\u00a0\u00a0\u00a0 fcitx.c\r\n\u00a0\u00a0\u00a0\u00a0 errorhandler.c\r\n\u00a0)<\/pre>\n<p>\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u540d\u4e3aFCITX_SOURCES\u7684\u53d8\u91cf\uff0c\u5f15\u7528<\/p>\n<p>\u4e0a\u9762\u7684\u94fe\u63a5\u4e2d\u8fd8\u51fa\u73b0\u4e86\u4e00\u4e9b\u65b0\u547d\u4ee4\uff0c\u90a3\u4e48\u6211\u4eec\u4e5f\u6765\u4e00\u4e00\u89e3\u91ca\uff1a<\/p>\n<pre>install(TARGETS fcitx RUNTIME DESTINATION ${bindir})<\/pre>\n<p>\u5c06 target fcitx\u5b89\u88c5\u5230 ${bindir} \u76ee\u5f55\u4e0b\u3002<\/p>\n<pre>target_link_libraries(fcitx fcitx-core ${LIBEXECINFO_LIBRARIES})<\/pre>\n<p>fcitx\u8fd9\u4e2atarget\u548cfcitx-core\uff0c\u4ee5\u53ca\u00a0${LIBEXECINFO_LIBRARIES} \u8fdb\u884clink\u3002<\/p>\n<p>\u7528\u8fc7makefile\u7684\u4eba\u5bf9target\u4e00\u5b9a\u4e0d\u964c\u751f\u3002fcitx\u8fd9\u4e2atarget\u5728\u90a3\u91cc\u5b9a\u4e49\u7684\u5462\uff1f\u5c31\u662f\u5728\u4e0a\u9762\u7684add_executable\u90a3\u91cc\u5b9a\u4e49\u7684\u3002\u7c7b\u4f3cadd_executable\u7684\u8fd8\u6709add_library\uff0c\u7528\u4e8e\u6784\u5efa\u5e93\u800c\u4e0d\u662f\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p>\u81f3\u6b64\u9488\u5bf9\u4e00\u4e2a\u7b80\u5355\u7684C\/C++\u7684\u5de5\u7a0b\u6765\u8bf4\uff0c\u8fd9\u4e9b\u5c31\u5df2\u7ecf\u8db3\u591f\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CMake \u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u5f00\u6e90\u6784\u5efa\u7cfb\u7edf\u3002 1\u3001CMake\u7684\u8bde\u751f \u65e2\u7136\u7ef4\u57fa\u767e\u79d1\u6709\u6211\u5c31\u4e0d\u591a\u8bf4\u4e86\u3002 http:\/\/zh.wikipedia.org\/wiki\/CMake 2\u3001\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528CMake http:\/\/lwn.net\/Articles\/188693\/\u00a0 Why the KDE project switched to CMake &#8212; and how \u539f\u56e0\u4e4b\u4e00\u662f\u8de8\u5e73\u53f0\uff0c\u672c\u6765\u4ed6\u4eec\u60f3\u91c7\u7528 SCons \u4f5c\u4e3a\u6784\u5efa\u7cfb\u7edf\uff0c \u4f46\u5728\u8de8\u5e73\u53f0\u4e0a\u9047\u89c1\u4e86\u8bb8\u591a\u95ee\u9898\u3002CMake\u7684\u4f18\u52bf\u5728\u4e8e\u5b83\u53ea\u4f9d\u8d56\u4e8eC++\u7f16\u8bd1\u5668\uff0c\u8de8\u5e73\u53f0\uff0c\u53ef\u4ee5\u751f\u6210\u5404\u4e2a\u5e73\u53f0\u7279\u5b9a\u7684Makefile\u548c\u5de5\u7a0b\u6587\u4ef6\uff0c\u5e76\u4e14\u652f\u6301\u5355\u5143\u6d4b\u8bd5\u3002 \u53e6\u5916\u4e00\u70b9\u5c31\u662f\u6027\u80fd\uff0c\u4f46\u6211\u4e00\u65f6\u95f4\u627e\u4e0d\u5230\u5177\u4f53\u7684\u5f15\u7528\u4e86\u3002 3\u3001\u4f7f\u7528CMake\u7684\u57fa\u672c\u65b9\u6cd5 mkdir build cd build cmake .. make make install \u9488\u5bf9\u4e00\u822c\u7528\u6237\u6765\u8bf4\u5c31\u662f\u4ee5\u4e0a\u5185\u5bb9\uff0c\u548c\u5f53\u5e74\u7684\u4f20\u7edf configure make \u5f88\u50cf\u5427\uff1f 4\u3001\u7b2c\u4e00\u4e2a\u9879\u76ee cmake_minimum_required (VERSION 2.6) &hellip; <a href=\"https:\/\/www.csslayer.info\/wordpress\/cmake\/my-cmake-tutorial-1\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[173],"tags":[217],"class_list":["post-1346","post","type-post","status-publish","format-standard","hentry","category-cmake","tag-cmake"],"_links":{"self":[{"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/posts\/1346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1346"}],"version-history":[{"count":2,"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/posts\/1346\/revisions"}],"predecessor-version":[{"id":1357,"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/posts\/1346\/revisions\/1357"}],"wp:attachment":[{"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.csslayer.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}