子目录包含CMakeLists.txt文件,主目录的CMakeLists.txt通过add_subdirectory添加子目录,子目录编译规则体现在子目录下的CMakeLists.txt中; 子目录未包含CMakeLists.txt文件,子目录编译规则体现在主目录的CMakeLists.txt中; 3.1 编译流程 在linux 平台下使用 CMake 构建C/C++工程的流程: 推荐使用外部构建(创建build...
这里指定src目录下存放了源文件,当执行cmake时,就会进入src目录下去找src目录下的CMakeLists.txt,所以在src目录下也建立一个CMakeLists.txt,内容如下, 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 aux_source_directory(.SRC_LIST)include_directories(../include)add_executable(main ${SRC_LIS...
include_directories:向工程添加多个特定的头文件搜索路径,相当于指定g++编译器的-I参数 语法:include_directories([AFTER|BEFORE][SYSTEM] dir1 dir2 ...) // 将/usr/include/myincludefolder 和 ./include 添加到头文件搜索路径 include_directories(/usr/include/myincludefolder ./include) link_directories:向...
cmake_minimum_required(VERSION3.0)# 最低版本3.0project(main)# 项目名称# 配置编译器set(CMAKE_CXX_FLAGS${CMAKE_CXX_FLAGS}-g)# 配置头文件搜索路径# include_directories()# 配置库文件搜索路径# link_directories()# 设置需要编译的源文件列表set(SRC_LIST main.cpp)# 把.指定路径下的所有源文件名字放...
首先让我们从最简单的代码入手,先来体验下cmake是如何操作的。 2.1 项目结构 2.2 示例源码 打开终端,输入: touch main.c CMakeLists.txt 编写main.c,如下: #include int main(void) { printf("Hello World\n"); return 0; } 然后在main.c同级目录下编写CMakeLists.txt,内容如下: ...
这里指定src目录下存放了源文件,当执行cmake时,就会进入src目录下去找src目录下的CMakeLists.txt,所以在src目录下也建立一个CMakeLists.txt,内容如下, 1aux_source_directory (. SRC_LIST)23include_directories (../include)45add_executable (main ${SRC_LIST})67set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE...
在cmake目录中新建hello_cmake.c与CMakeLists.txt文件,内容如下: hello_cmake.c: #include <stdio.h> int main() { printf("Hello CMake\n"); return 0; } CMakeLists.txt: make_minimum_required (VERSION 2.8) project (HelloCMake) add_executable(HelloCMake hello_cmake.c) ...
其中sum.h和sub.h放到include这个文件夹中,main.c、sum.c和sub.c放到src这个文件夹中。 在整个工程中,只有一个CMakeLists.txt: 1.2 CMakeLists.txt cmake_minimum_required(VERSION2.8)project(sum_sub_test)include_directories(include)aux_source_directory(srcSRC_LIST)add_executable(sum_sub...
首先让我们从最简单的代码入手,先来体验下cmake是如何操作的。 2.1 项目结构 2.2 示例源码 打开终端,输入: touch main.c CMakeLists.txt 编写main.c,如下: #include int main(void) { printf("Hello Worldn"); return 0; } 然后在main.c同级目录下编写CMakeLists.txt,内容如下: ...
15. CMAKE_INCLUDE_CURRENT_DIR:自动添加CMAKE_CURRENT_BINARY_DIR和CMAKE_CURRENT_SOURCE_DIR到当前处理的CMakeLists.txt; 16. CMAKE_INCLUDE_DIRECTORIES_PROJECT_EFORE:将工程提供的头文件目录始终至于系统头文件目录的前面,当你定义的头文件确定跟系统发生冲突时可以提供一些帮助; ...