mirror of
https://gitee.com/apaki/cmake_demo.git
synced 2025-05-18 04:11:37 +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)
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
|
||||||
# 项目信息
|
# 0. 项目信息
|
||||||
project(demo)
|
project(demo)
|
||||||
|
|
||||||
# 查找当前目录下的所有文件
|
# 2. 添加当前路径
|
||||||
# 并将名称保存在DIR_SRC中
|
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)
|
aux_source_directory(. DIR_SRC)
|
||||||
|
|
||||||
# 添加子目录
|
# 1. 添加子目录
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
# 添加头文件路径
|
# 1. 添加头文件路径
|
||||||
include_directories(src)
|
include_directories(src)
|
||||||
|
|
||||||
# 指定生成目标
|
# 0. 指定生成目标
|
||||||
add_executable(demo ${DIR_SRC})
|
add_executable(demo ${DIR_SRC})
|
||||||
|
|
||||||
|
# 1. 添加链接库
|
||||||
target_link_libraries(demo list)
|
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 <stdlib.h>
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
void list_demo(void)
|
void list_demo(void)
|
||||||
{
|
{
|
||||||
@ -19,7 +20,8 @@ void list_demo(void)
|
|||||||
|
|
||||||
void main(int arg, char *argv[])
|
void main(int arg, char *argv[])
|
||||||
{
|
{
|
||||||
#if 0
|
#ifndef USE_DEMO
|
||||||
|
printf("list test!\n");
|
||||||
struct list_t list;
|
struct list_t list;
|
||||||
list_init(&list);
|
list_init(&list);
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ void main(int arg, char *argv[])
|
|||||||
|
|
||||||
list_print(&list);
|
list_print(&list);
|
||||||
#else
|
#else
|
||||||
|
printf("list demo!\n");
|
||||||
list_demo();
|
list_demo();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ void list_print(struct list_t *list)
|
|||||||
p = list;
|
p = list;
|
||||||
while (p->next != NULL)
|
while (p->next != NULL)
|
||||||
{
|
{
|
||||||
printf("%02d\n", p->data);
|
printf("%02d ", p->data);
|
||||||
p = p->next;
|
p = p->next;
|
||||||
if (p->next == NULL)
|
if (p->next == NULL)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user