cmake自动载入项目源码文件

include/xlog.h

复制代码
#ifndef XLOG_H
#define XLOG_H
void xlog();

#endif

include/xthread.hpp

复制代码
#ifndef XTHREAD_H
#define XTHREAD_H
void xthread();
#endif

src/xlog.cpp

复制代码
#include <iostream>
#include "xlog.h"
using namespace std;
void xlog()
{
	cout<<" In xlog"<<endl;
}

src/xtest.c

复制代码
void test()
{
}

xthread.cc

复制代码
#include <iostream>
using namespace std;
void xthread()
{
	cout<<"In xthread"<<endl;
}

根目录下的main.cpp

复制代码
#include <iostream>
#include "xlog.h"
#include "xthread.hpp"
using namespace std;
int main()
{
    xlog();
    xthread();
	cout<<"test auto source head"<<endl;
	return 0;
}

根目录下的CMakeList.txt

复制代码
#[[
108auto_src_h
    CMakeLists.txt
    main.cpp
    src
        xlog.cpp
        xthread.cc
        xtest.c
    include
        xlog.h
        xthread.hpp
]]

cmake_minimum_required(VERSION 3.20)
project("auto_src_h")

#头文件加载路径
set(INCLUDE_PATH  "./include")
include_directories(${INCLUDE_PATH})

# 找到当前目录(.)下源码写入M_SRC变量中
aux_source_directory("." M_SRC)
aux_source_directory("./src" SRC)

#读取所有的头文件
file(GLOB H_FILE "${INCLUDE_PATH}/*.h*")

add_executable(${PROJECT_NAME} ${M_SRC} ${SRC} ${H_FILE})
相关推荐
Stanford_11063 小时前
如何利用Python进行数据分析与可视化的具体操作指南
开发语言·c++·python·微信小程序·微信公众平台·twitter·微信开放平台
千里马-horse4 小时前
Async++ 源码分析8--partitioner.h
开发语言·c++·async++·partitioner
Lucis__5 小时前
再探类&对象——C++入门进阶
开发语言·c++
北京不会遇到西雅图6 小时前
【SLAM】【后端优化】不同优化方法对比
c++·机器人
jndingxin6 小时前
c++多线程(6)------ 条件变量
开发语言·c++
程序员莫小特6 小时前
老题新解|大整数加法
数据结构·c++·算法
洲覆8 小时前
C++ 模板、泛型与 auto 关键字
开发语言·数据结构·c++
千里马-horse9 小时前
Async++ 源码分析7--parallel_reduce.h
开发语言·c++·async++·parallel_reduce
江公望9 小时前
Qt QThread使用方法入门浅解
c++·qt
叫我龙翔9 小时前
【MySQL】从零开始了解数据库开发 --- 数据表的约束
android·c++·mysql·数据库开发