cmake鍏ラ棬
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cmake鍏ラ棬相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e8%a7%a3%e9%87%8a' title='瑙i噴'>瑙i噴
required 3.5 浣跨敤 other 鏌ョ湅 tab als1 浠€涔堟槸CMake?
Cmake鏄竴涓紪璇戙€佹瀯寤哄伐鍏枫€備娇鐢–MakeLists.txt鏉ユ弿杩版瀯寤鸿繃绋嬶紝鍙互鐢熸垚鏍囧噯鐨勬瀯寤烘枃浠讹紝濡侻akefile銆備竴鑸厛缂栧啓CMakeLists.txt锛岀劧鍚庨€氳繃cmake鏉ョ敓鎴怣akefile锛屾渶鍚庢墽琛宮ake杩涜缂栬瘧銆?/p>
1.1 cmake瀹夎
? 鍦╱buntu涓婂畨瑁卌make闈炲父绠€鍗曪紝鎵цsudo apt-get install cmake鍗冲彲銆傚鏋滄兂瀹夎鏈€鏂扮殑cmake鐗堟湰锛屽氨闇€瑕佽嚜宸辫繘琛屾簮鐮佺紪璇戝畨瑁呫€傛簮鐮佷笅杞借矾寰?https://cmake.org/download銆傛簮鐮佺紪璇戝畨瑁呴潪甯哥畝鍗曪紝杩欓噷灏变笉鍐嶈缁嗘弿杩颁簡銆?/p>
1.2 鏌ョ湅cmake鐗堟湰
cmake瀹夎瀹屾垚鍚庯紝鎵цcmake --version锛屽嵆鍙煡鐪媍make鐨勭増鏈彿銆傛垜鐨勬槸3.5.1
3 CMake绠€鍗曠ず渚?/h1>
杩欓噷缁欏嚭涓€涓畝鍗曠殑浣跨敤cmake杩涜鏋勫缓鐨勫伐绋嬬ず渚嬶紝鐩綍缁撴瀯濡備笅:
test01
? 鈹溾攢鈹€ build
? 鈹溾攢鈹€ CMakeLists.txt
? 鈹斺攢鈹€ main.c
main.c鏂囦欢濡備笅:
#include <stdio.h>
int main(int argc, char** argv)
{
printf("hello cmake
");
return 0;
}
CMakeLists.txt鍐呭濡備笅:
#璁剧疆cmake鐨勬渶灏忕増鏈?CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
#璁剧疆椤圭洰鍚嶇О
project(test01)
#璁剧疆婧愭枃浠?aux_source_directory(. dir_srcs)
#璁剧疆鍙墽琛岀▼搴?add_executable(test01 ${dir_srcs})
鎴戣繖閲宮kdir 浜哹uild 鐩綍锛?/p>
cd build
cmake ..
make
鏈€鍚庡氨浼氬湪褰撳墠鐩綍涓嬬湅鍒扮敓鎴愮殑test01鍙墽琛岀▼搴忋€?/p>
鎺ヤ笅鏉ワ紝瀵逛笂渚嬩腑鐨凜MakeLists.txt鐨勮娉曡繘琛岃В閲娿€?/p>
CMakeLists.txt 鐨勮娉曟瘮杈冪畝鍗?鐢卞懡浠ゃ€佹敞閲婂拰绌烘牸缁勬垚,鍏朵腑鍛戒护鏄笉鍖哄垎澶у皬鍐?/strong>鐨?绗﹀彿"#"鍚庨潰鐨勫唴瀹硅璁や负鏄敞閲?/strong>銆?/p>
Call the
cmake_minimum_required()
command at the beginning of the top-levelCMakeLists.txt
file even before calling theproject()
command. It is important to establish version and policy settings before invoking other commands whose behavior they may affect. See also policyCMP0000
.cmake_minimun_required
鏍煎紡:cmake_minimum_required(VERSION <min>[...<max>][FATAL_ERROR])
璁剧疆璇ュ伐绋嬬殑cmake鏈€浣庢敮鎸佺増鏈紝娉ㄦ剰"VERSION"涓嶈兘鍐欐垚灏忓啓锛屽惁鍒欎細鎶make_minimum_required called with unknown argument "version".
project
project(<PROJECT-NAME> [LANGUAGES] [<language-name>...]) project(<PROJECT-NAME> [VERSION <major>[.<minor>[.<patch>[.<tweak>]]]] [DESCRIPTION <project-description-string>] [HOMEPAGE_URL <url-string>] [LANGUAGES <language-name>...])
aux_source_directory
aux_source_directory(<dir> <variable>)
Find all source files in a directory.Collects the names of all the source files in the specified directory and stores the list in the
add_executable
add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [source1] [source2 ...])
灏嗘簮鏂囦欢缂栬瘧鎴愬彲鎵ц绋嬪簭锛屽彲鎵ц绋嬪簭鐨勫悕绉扮敱
琛ュ厖:
cmake鐨?a href="https://cmake.org/cmake/help/v3.13/manual/cmake-commands.7.html">鍛戒护鍖呭惈 scripting commands,project commands,ctest commands,deprecated commands銆?/p>
以上是关于cmake鍏ラ棬的主要内容,如果未能解决你的问题,请参考以下文章