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})
相关推荐
青瓦梦滋1 分钟前
C++特殊类设计(设计模式)和类型转换
c++·设计模式
(Charon)4 分钟前
【C++/Qt】Qt 网络工具中的输入校验设计:IP、端口、URL 和空内容判断
服务器·c++·tcp/ip
liu****14 分钟前
第16届国赛蓝桥杯大赛C/C++大学B组
c语言·数据结构·c++·算法·蓝桥杯
nazisami38 分钟前
红黑树详解
数据结构·c++·面向对象·红黑树
kyle~1 小时前
RTPS(Real-Time Publish-Subscribe)---DDS的传输协议
c++·机器人·ros2
TIEM_691 小时前
C++ vector容器全面解析:从入门到精通
开发语言·c++
Irissgwe1 小时前
c++多态
开发语言·c++·多态
lingran__1 小时前
C++_类和对象(上)
开发语言·c++
lzh200409191 小时前
手搓一个简易 Linux 进程池:巩固进程知识
linux·c++
basketball6161 小时前
C++ 的 const 相关知识点总结
开发语言·c++