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. Ubuntu下添加定时任务执行php文件

    //添加自动下载定时任务1. vim /etc/crontab2. 添加 #每5分钟执行一次*/5 * * * * root /usr/bin/php /home/wwwroot/123.php3. ...

  2. iOS - 反射机制: objc_property_t的使用

    iOS属性反射:说白了,就是将两个对象的所有属性,用动态的方式取出来,并根据属性名,自动绑值.(注意:对象的类,如果是派生类,就得靠其他方式来实现了,因为得到不该基类的属性.) 常用的反射方式,有如下 ...

  3. 哈夫曼树详解——PHP代码实现

    在介绍哈夫曼树之前需要先了解一些专业术语 路径和路径长度 在一棵树中,从一个结点往下可以达到的孩子或孙子结点之间的通路,称为路径.通路中分支的数目称为路径长度.若规定根结点的层数为1,则从根结点到第L ...

  4. EWA不能及时通过邮件接收

    1. 确保EWA已经配置成功.可以通过SW_workcenter查看 2.确保EWA的邮箱设置成功 3. 检查EWAreport产生的时间 卫星系统:SDCCN 在tab"done" ...

  5. Java并发 行级锁/字段锁/表级锁 乐观锁/悲观锁 共享锁/排他锁 死锁

    原文地址:https://my.oschina.net/oosc/blog/1620279 前言 锁是防止在两个事务操作同一个数据源(表或行)时交互破坏数据的一种机制. 数据库采用封锁技术保证并发操作 ...

  6. stm32和cortex M3学习内核简单总结

    1.stm32综述 2.寄存器组 3.操作模式和特权级别 4.存储器映射 5.中断和异常 6.其他 Stm32综述 这可以说是我第一款认真学习的单片机了,学完这个就要开启我通往arm9的大门了,接下来 ...

  7. 小程序npm构建

    npm initnpm install --productionnpm i  第三方组件名称  -S --production //重要

  8. MySQL binlog反解析

    反解析delete语句 背景:delete table忘了加条件导致整张表被删除 恢复方式:直接从binlog里反解析delete语句为insert进行恢复 导出删指定表的DELETE语句: # my ...

  9. 详解介绍Selenium常用API的使用--Java语言(完整版)

    参考:http://www.testclass.net/selenium_java/ 一共分为二十个部分:环境安装之Java.环境安装之IntelliJ IDEA.环境安装之selenium.sele ...

  10. 【转载】内联函数 —— C 中关键字 inline 用法解析

    转载地址:https://blog.csdn.net/zqixiao_09/article/details/50877383 一.什么是内联函数 在C语言中,如果一些函数被频繁调用,不断地有函数入栈, ...