C/C++ CMake

CMake是一个跨平台的自动化构建工具,使用CMakeLists.txt文件来描述构建过程,生成标准的构建文件,如UNIX下Makefile。

1、使用流程

1)编写CMakeLists.txt。

2)执行"cmake path"命令,其中path是CMakeLists.txt所在的目录。

3)在生成的Makefile文件所在的目录,执行"make"命令。

2、命令不区分大小写,参数和变量区分大小写。

3、设置项目名称。

project(xworkbench) # Set the name of the project.

4、设置项目所需的CMake最小版本。 

cmake_minimum_required(VERSION 3.11) # Require a minimum version of cmake.

5、

add_subdirectory(src) # Add a subdirectory to the build.

 

6、利用源文件生成可执行文件。

add_executable(main ${SRC_DIR})

  

7、

aux_source_directory()

8、

option

add_library 则告诉生成一个库文件。

set赋值

 

9、

include_directories() # Add include directories to the build.

10、

link_directories() # Add directories in which the linker will look for libraries.

11、  

file(GLOB TEST_SRC ./*.cpp) # File manipulation command.

 

target_link_libraries(workbench ) # Specify libraries or flags to use when linking a given target and/or its dependents.

  

 

 

 

参考链接:

https://cmake.org/cmake-tutorial/

https://www.ibm.com/developerworks/cn/linux/l-cn-cmake/index.html

 

原文链接: https://www.cnblogs.com/yangwenhuan/p/10573753.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    C/C++ CMake

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/330202

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月1日 下午5:28
下一篇 2023年3月1日 下午5:28

相关推荐