mirror of
https://gitee.com/apaki/cmake_demo.git
synced 2025-05-17 20:01:36 +08:00
cmake自定义编译选项测试通过
This commit is contained in:
parent
31a8e9cacc
commit
08c9442df5
@ -1,21 +1,40 @@
|
||||
|
||||
# cmake 最低版本号要求
|
||||
# 0. cmake 最低版本号要求
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
# 项目信息
|
||||
# 0. 项目信息
|
||||
project(demo)
|
||||
|
||||
# 查找当前目录下的所有文件
|
||||
# 并将名称保存在DIR_SRC中
|
||||
# 2. 添加当前路径
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
# 2. 配置项目
|
||||
option(USE_DEMO "use demo application interface" ON)
|
||||
|
||||
# 2. 配置文件
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/config.h.in"
|
||||
"${PROJECT_BINARY_DIR}/config.h"
|
||||
)
|
||||
|
||||
# 2. 配置条件
|
||||
if(USE_DEMO)
|
||||
# include_directories(.)
|
||||
# else()
|
||||
# pass
|
||||
endif(USE_DEMO)
|
||||
|
||||
# 0. 查找当前目录下的所有文件,并将名称保存在DIR_SRC中
|
||||
aux_source_directory(. DIR_SRC)
|
||||
|
||||
# 添加子目录
|
||||
# 1. 添加子目录
|
||||
add_subdirectory(src)
|
||||
|
||||
# 添加头文件路径
|
||||
# 1. 添加头文件路径
|
||||
include_directories(src)
|
||||
|
||||
# 指定生成目标
|
||||
# 0. 指定生成目标
|
||||
add_executable(demo ${DIR_SRC})
|
||||
|
||||
# 1. 添加链接库
|
||||
target_link_libraries(demo list)
|
||||
|
1
config.h.in
Normal file
1
config.h.in
Normal file
@ -0,0 +1 @@
|
||||
#cmakedefine USE_DEMO
|
5
main.c
5
main.c
@ -4,6 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "list.h"
|
||||
#include "config.h"
|
||||
|
||||
void list_demo(void)
|
||||
{
|
||||
@ -19,7 +20,8 @@ void list_demo(void)
|
||||
|
||||
void main(int arg, char *argv[])
|
||||
{
|
||||
#if 0
|
||||
#ifndef USE_DEMO
|
||||
printf("list test!\n");
|
||||
struct list_t list;
|
||||
list_init(&list);
|
||||
|
||||
@ -30,6 +32,7 @@ void main(int arg, char *argv[])
|
||||
|
||||
list_print(&list);
|
||||
#else
|
||||
printf("list demo!\n");
|
||||
list_demo();
|
||||
#endif
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ void list_print(struct list_t *list)
|
||||
p = list;
|
||||
while (p->next != NULL)
|
||||
{
|
||||
printf("%02d\n", p->data);
|
||||
printf("%02d ", p->data);
|
||||
p = p->next;
|
||||
if (p->next == NULL)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user