xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

CMake 快速入门教程 All In One

CMake 快速入门教程 All In One

CMake

CMake is an open-source, cross-platform family of tools designed to build, test and package software.
CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice.
The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK.

CMake 是一个开源的跨平台工具系列,旨在构建、测试和打包软件。
CMake 用于使用简单的平台和编译器独立配置文件来控制软件编译过程,并生成可在您选择的编译器环境中使用的本机 makefile工作区
CMake 工具套件是由 Kitware 创建的,旨在响应 ITK 和 VTK 等开源项目对强大的跨平台构建环境的需求。

https://cmake.org/

docs

include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 ...])

https://cmake.org/cmake/help/latest/command/include_directories.html

target_include_directories(<target> [SYSTEM] [AFTER|BEFORE]
  <INTERFACE|PUBLIC|PRIVATE> [items1...]
  [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])

https://cmake.org/cmake/help/latest/command/target_include_directories.html#command:target_include_directories

shit docs 完全看不懂呀

https://cmake.org/examples/

target_include_directories (Hello PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

image

CMakeLists.txt

# ???
# add_library (MATH_FUNCTIONS math_functions.c)
# add_library (math_functions math_functions.c)
# add_library (math_functions ./mf/math_functions.c)
// add_library (add ./mf/math_functions.c)

# ❌ 不好使呀
include_directories(mf)
include_directories(BEFORE mf ${CMAKE_CURRENT_SOURCE_DIR})

vscode

搭建 C 语言开发环境 errors

# tree

// math_test.c
#include <stdio.h>

// 使用 自定义的头文件
#include "math_functions.h"

int main(){
  int a = 2;
  int b = 3;
  int sum = add(a, b); 
  printf("a=%d, b=%d, a+b=%d\n", a, b, sum);
}


/* 

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/xgqfrms-mm/Desktop/c-demos/math_test.c).C/C++(1696)

cannot open source file "math_functions.h"C/C++(1696)


 */

image

https://stackoverflow.com/questions/45583473/include-errors-detected-in-vscode

https://code.visualstudio.com/docs/cpp/faq-cpp#_what-is-the-difference-between-includepath-and-browsepath

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

cmake

https://www.cnblogs.com/xgqfrms/tag/cmake/

https://zzk.cnblogs.com/my/s/blogpost-p?Keywords=cmake

demo

https://vcpkg.io/en/getting-started.html



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-01-18 14:18  xgqfrms  阅读(129)  评论(5编辑  收藏  举报