File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed
Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ #cmake_minimum_required (VERSION 2.8)
2+ project (helloworld)
3+ #include_directories(include)
4+ AUX_SOURCE_DIRECTORY (src DIR_SRCS)
5+ set (SRCS ${DIR_SRCS} )
6+ message (${DIR_SRCS} )
7+ add_executable (helloworld ${SRCS} )
8+
Original file line number Diff line number Diff line change 1+ #cmake最小版本需求
2+ cmake_minimum_required(VERSION xxx)
3+
4+ #设置此项目的名称
5+ project(xxx)
6+
7+ #生成可执行文件target ,后面填写的是生成此可执行文件所依赖的源文件列表。
8+ add_executable(target target_source_codes)
9+
10+ # 设置一个名字var_name 的变量,同时给此变量赋值为var_value
11+ SET(var_name var_value)
12+
13+ # 指定编译器
14+ # CMAKE_C_FLAGS_DEBUG ---- C 编译器
15+ # CMAKE_CXX_FLAGS_DEBUG ---- C++ 编译器
16+ # -std=c++11 使用 C++11
17+ # -g:只是编译器,在编译的时候,产生调试信息。
18+ # -Wall:生成所有警告信息。一下是具体的选项,可以单独使用
19+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -wall ")
20+
21+ #指定编译类型,debug 或者为 release
22+ # debug 会生成相关调试信息,可以使用 GDB 进行
23+ # release 不会生成调试信息。当无法进行调试时查看此处是否设置为 debug.
24+ set(CMAKE_BUILD_TYPE Debug)
25+
26+ # 打印消息
27+ MESSAGE("MSG")
28+
29+ #给变量var_name赋值为var_value,comment是此变量的注释,和SET 有类似的功效,用于给某变量设置默认值
30+ option(var_name "comment" var_value)
31+
32+ # 添加include路径,也就是头文件路径
33+ include_directories(xxx)
34+
35+ # 调用xxx子目录的CMakeLists.txt执行
36+ add_subdirectory(xxx)
37+
38+ # 给编译器添加xxx参数
39+ add_compile_options(xxx)
40+
41+ # 给编译器添加库目录,
42+ link_directories(xxx)
43+
44+ # 生成库文件,SHARED代表动态库,STATIC代表静态库, 最后一个参数代表此库的源文件列表
45+ add_library(lib_name SHARED or STATIC lib_source_code)
46+
47+ # 给目标添加依赖库
48+ target_link_libraries(target_name lib_name ...)
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ int main ()
3+ {
4+ printf ("Hello World !\n" );
5+ }
You can’t perform that action at this time.
0 commit comments