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

 

posted @ 2020-02-18 09:45  happyyoung  阅读(468)  评论(0编辑  收藏  举报