一个CMakeLists例子:
project(CMAKETEST)
cmake_minimum_required(VERSION 2.8)
include_directories(${PROJECT_SOURCE_DIR}/Include/)
set(CMakeTest ${PROJECT_SOURCE_DIR}/Src/CMakeTestMain.c
${PROJECT_SOURCE_DIR}/Src/CTest.c)
add_executable(CMakeTest ${CMakeTest})
这个工程的目录结构:
$Project_Directory/CMakeLists
$Project_Directory/Src/*.c
$Project_Directory/Include/*.h
add_executable:
Add an executable to the project using the specified source files.
add_library: Add a library to the project using the specified source files.
add_library(lib_name, SHARED|STATIC, ${SRC_LIST})
SHARED: 表示动态库 STATIC: 表示静态库
SRC_LIST 是源列表
add_definitions("-D_DEBUG") 添加编译时参数
add_subdirectory(directory, build_directory)
官方wiki: http://www.cmake.org/Wiki/CMake
本文深入解析了CMakeLists.txt文件的用法,并通过一个实际例子展示了如何使用CMakeLists.txt来管理C/C++项目的构建过程。文章详细介绍了add_executable函数、include_directories、set命令等常用命令的使用方法,同时强调了正确设置工程目录的重要性。
1万+

被折叠的 条评论
为什么被折叠?



