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})
相关推荐
888CC++1 小时前
C语言与C++的区别:从面向过程到面向对象
java·c语言·c++
Darkwanderor2 小时前
Linux系统编程实战项目:模拟实现shell
linux·c++
himobrinehacken3 小时前
揭秘Windows程序启动的神秘之旅
c++·安全
库玛西3 小时前
C++ 运行时多态 :核心总结与原理图解
c语言·c++·笔记
Byron Loong4 小时前
【C++】重定向是什么
开发语言·c++
hansang_IR5 小时前
【题解】LC:Z 算法(Z Algorithm)
c++·算法·字符串
霍霍的袁7 小时前
【C++】模板从入门到进阶(函数模板 + 类模板 + 特化 + 分离编译)
开发语言·c++·visual studio
海清河晏1117 小时前
Qt 实战:信号与槽+事件系统
开发语言·c++·qt
hansang_IR7 小时前
【题解】LC:卷积(Convolution (Mod 1,000,000,007))
c++·算法·ntt·crt
计算机内卷的N天7 小时前
三维C三维配准软件(术中CT)
c++·c臂三维配准