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

https://cmake.org/cmake/help/v3.16/guide/tutorial/index.html#cmake-tutorial

https://www.ncnynl.com/category/ros-junior-tutorial/

https://blog.csdn.net/weixin_43455581/article/details/96306977#1_CPython_1

https://blog.csdn.net/wsc820508/article/details/81349675

最早的:https://www.ibm.com/developerworks/cn/linux/l-cn-cmake/

前言很多完全省略

1、编辑helloc.c文件:

 #include <stdio.h>

 int main(int argc, char **argv)
{
printf("Hello world from cMake pro1\n"); return ;
}

  代码非常简单,不多罗嗦。

2、编辑CMakeList.txt文件,这个是cmake的指导性文件:

 cmake_minimum_required(VERSION 3.15)
PROJECT(Pro1)
SET(SRC_LIST helloc.c)
MESSAGE(STATUS "This is BINARY_dir " ${PROJECT_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE_dir " ${PROJECT_SOURCE_DIR})
ADD_EXECUTABLE(helloc ${SRC_LIST})

  文件说明:对新手有用,老手请忽略

  第1行:主要是不让camke时,工具出现警告,可以不加,建议加上

  第2行:PROJECT指令指定项目名称为Rpo1,并暗含两个变量PROJECT_BINARY_DIR和PROJECT_SOURCE_DIR,前者是项目中可执行文件的目录名称,后者是项目的源代码目录名称;

  第3行:SET指令相当与定义并设置变量SRC_LIST的值为helloc.c,如果有更多的源文件,以空格或分号分割即可

  第4行:MESSAGE指令打印消息,STATUS表明正常消息,用${PROJECT_BINARY_DIR}获得PROJECT_BINARY_DIR的值,打印项目中可执行文件夹名称

  第5行:打印项目中源代码文件夹名称

  第6行:ADD_EXECUTABLE指令主要制定生成的可执行文件helloc和依赖列表,请务必使用 ${SRC_LIST},以获取依赖列表中的所有文件,而不是依赖文件SRC_LIST

3、第一次构建,生成Makefile文件,返回信息如下:

 -- The C compiler identification is GNU 9.2.
-- The CXX compiler identification is GNU 9.2.
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- This is BINARY_dir /home/nication/WORKM/studyCode/toolCode/cMake/pro1
-- This is SOURCE_dir /home/nication/WORKM/studyCode/toolCode/cMake/pro1
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nication/WORKM/studyCode/toolCode/cMake/pro1

  Makefile文件:

 # CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.15 # Default target executed when no arguments are given to make.
default_target: all .PHONY : default_target # Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL: #=============================================================================
# Special targets provided by cmake. # Disable implicit rules so canonical targets will work.
.SUFFIXES: # Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES = .SUFFIXES: .hpux_make_needs_suffix_list # Suppress display of executed commands.
$(VERBOSE).SILENT: # A target that is always out of date.
cmake_force: .PHONY : cmake_force #=============================================================================
# Set environment variables for the build. # The shell in which to execute make rules.
SHELL = /bin/sh # The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake # The command to remove a file.
RM = /usr/bin/cmake -E remove -f # Escaping for special characters.
EQUALS = = # The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/nication/WORKM/studyCode/toolCode/cMake/pro1 # The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/nication/WORKM/studyCode/toolCode/cMake/pro1 #=============================================================================
# Targets provided globally by CMake. # Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache # Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache .PHONY : rebuild_cache/fast # Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache # Special rule for the target edit_cache
edit_cache/fast: edit_cache .PHONY : edit_cache/fast # The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/nication/WORKM/studyCode/toolCode/cMake/pro1/CMakeFiles /home/nication/WORKM/studyCode/toolCode/cMake/pro1/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/nication/WORKM/studyCode/toolCode/cMake/pro1/CMakeFiles
.PHONY : all # The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean # The main clean target
clean/fast: clean .PHONY : clean/fast # Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall # Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast # clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake
.PHONY : depend #=============================================================================
# Target rules for targets named helloc # Build rule for target.
helloc: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 helloc
.PHONY : helloc # fast build rule for target.
helloc/fast:
$(MAKE) -f CMakeFiles/helloc.dir/build.make CMakeFiles/helloc.dir/build
.PHONY : helloc/fast helloc.o: helloc.c.o .PHONY : helloc.o # target to build an object file
helloc.c.o:
$(MAKE) -f CMakeFiles/helloc.dir/build.make CMakeFiles/helloc.dir/helloc.c.o
.PHONY : helloc.c.o helloc.i: helloc.c.i .PHONY : helloc.i # target to preprocess a source file
helloc.c.i:
$(MAKE) -f CMakeFiles/helloc.dir/build.make CMakeFiles/helloc.dir/helloc.c.i
.PHONY : helloc.c.i helloc.s: helloc.c.s .PHONY : helloc.s # target to generate assembly for a file
helloc.c.s:
$(MAKE) -f CMakeFiles/helloc.dir/build.make CMakeFiles/helloc.dir/helloc.c.s
.PHONY : helloc.c.s # Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... rebuild_cache"
@echo "... helloc"
@echo "... edit_cache"
@echo "... helloc.o"
@echo "... helloc.i"
@echo "... helloc.s"
.PHONY : help #=============================================================================
# Special targets to cleanup operation of make. # Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake
.PHONY : cmake_check_build_system

4、二次构建并编译:

 make

  返回信息:

 Scanning dependencies of target helloc
[ %] Building C object CMakeFiles/helloc.dir/helloc.c.o
[%] Linking C executable helloc
[%] Built target helloc

  自动生成可执行文件,helloc,文件列表:

 -rw-r--r--  nication nication  10月  : CMakeCache.txt
drwxr-xr-x nication nication 10月 : CMakeFiles
-rw-r--r-- nication nication 10月 : cmake_install.cmake
-rw-r--r-- nication nication 10月 : CMakeLists.txt
-rwxr-xr-x nication nication 10月 : helloc
-rw-r--r-- nication nication 10月 : helloc.c
-rw-r--r-- nication nication 10月 : Makefile

5、执行程序:

  ./helloc

  执行结果:

  Hello world from cMake pro1

到此为止,算是成功了。但是由于cmake过程中会产生很多中间文件,使用make clean只能清除可执行文件。清除临时文件不方便,因此,尽量使用cmake的外部构建。

cmake入门之内部构建的更多相关文章

  1. cmake入门:01 构建一个简单的可执行程序

    一.目录结构 CMakeLists.txt:cmake 工程入口文件,包含当前目录下的工程组织信息.cmake 指令根据此文件生成相应的 MakeFile 文件. Hello.c: 源代码文件 bui ...

  2. CMake入门教程(转帖)

    本文转自:https://www.cnblogs.com/never--more/p/6921837.html CMake入门教程 参考文献:http://www.ibm.com/developerw ...

  3. C++ CMake 入门实战[转载]

    C++ CMake 入门实战 2016-11-05 CMake用于跨平台的编译系统,对于通常的c/c++工程,都是通过make来进行编译的,CMake可以通过指令生成Makefile文件来指导整个项目 ...

  4. pytorch入门2.2构建回归模型初体验(开始训练)

    pytorch入门2.x构建回归模型系列: pytorch入门2.0构建回归模型初体验(数据生成) pytorch入门2.1构建回归模型初体验(模型构建) pytorch入门2.2构建回归模型初体验( ...

  5. VScode 使用 CMake 入门

    参考 CMake 入门实战 在 linux 平台下使用 CMake 生成 Makefile 并编译的流程如下: 编写 CMake 配置文件 CMakeLists.txt . 执行命令 cmake PA ...

  6. CMake 入门实战 | HaHack

    CMake 入门实战 | HaHack undefined

  7. CMake入门(二)

    CMake入门(二) 最后更新日期:2014-04-25 by kagula 阅读前提:<CMake入门(一)>.Linux的基本操作 环境: Windows 8.1 64bit英文版.V ...

  8. CMake入门

    CMake入门 CMake是一个跨平台的安装编译工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似 ...

  9. C#游戏开发高速入门 2.1 构建游戏场景

    C#游戏开发高速入门 2.1  构建游戏场景 假设已经计划好了要编写什么样的游戏,在打开Unity以后.要做的第一件事情就是构建游戏场景(Scene).游戏场景就是玩家游戏时,在游戏视图中看到的一切. ...

随机推荐

  1. vue的jsonp百度下拉菜单

    通过vue的jsonp实现百度下拉菜单的请求,vue的版本是2.9.2 <!DOCTYPE html> <html lang="en"> <head& ...

  2. 【转载】C#使用Except方法求取两个List集合的差集数据

    在C#语言的编程开发中,针对List集合的运算有时候需要计算两个List集合的差集数据,集合的差集是取在该集合中而不在另一集合中的所有的项.A集合针对B集合的差集数据指的是所有在A集合但不在B集合的元 ...

  3. 【转】Java最常见的200+面试题

    今天看到一份面试题总结,感觉很到位,主要包括以下模块:Java基础.容器.多线程.反射.对象拷贝.Java Web模块,异常.网络.设计模式.Spring/Spring MVC .Spring Boo ...

  4. 前端编译原理 parser.js源码解读

    前面已经介绍了一个jison的使用,在正常开发中其实已经够用下,下面主要是看了下parser.js代码解读下,作为一些了解. 下面以最简单的文法产生的parser做一些代码注释 下面是一些注释,标示了 ...

  5. stm32 引脚映射 和 ADC

    老是弄不明白ADC的输入到底在哪,看了stm32F103Ve的datasheet,将引脚和通道的映射关系贴在下面: 好了,写到这,我已经看了中文手册一上午了,可是啥都没看懂,下午接着看,写代码不重要, ...

  6. Linux 之 压缩解压缩

    Linux中常见的压缩格式 .zip            .gz             .bz2           .tar.gz      tar.bz2 zip zip格式的压缩文件和win ...

  7. 【视频】谷歌大佬30分钟让你入门机器学习(2019谷歌I/O资源分享)

    如果你是个谷粉,就一定会知道: 谷歌向来都很大胆.当所有的科技公司都在讲产品.讲利润的时候,2019年的谷歌开发者大会的主题却是:人文关怀.要知道,这是政府操心的事,而不是一家公司的任务. 谷歌敢这样 ...

  8. 15 Windows编程——系统内置窗口子类型之button

    button子类型BS_3STATE.BS_AUTO3STATE.BS_AUTOCHECKBOX 源码 #include<Windows.h> #include<Windowsx.h ...

  9. charles overvoew

    本文参考:charles overvoew 这里是请求文件的概览 对HTTP/s分析非常重要 基本上常见的HTTP相关字段都有: Charles is a web proxy (HTTP Proxy ...

  10. redis高可用之sentinel哨兵

    一,单实例模式 当系统中只有一台redis运行时,一旦该redis挂了,会导致整个系统无法运行. 二,主从模式 由于单台redis出现单点故障,就会导致整个系统不可用,所以想到的办法自然就是备份.当一 ...