mkdir src inc
inc 中创建文件 test.h
src 中创建文件 test.cpp
#ifndef __TEST_H
#define __TEST_H
int test_log();
#endif
#include<iostream>
#include"test.h"
int test_log()
{
std::cout<<"This is test_log."<<std::endl;
return 0;
}
include_directories(${PROJECT_SOURCE_DIR}/inc)
set(src_dir ${PROJECT_SOURCE_DIR}/src)
file(GLOB src_codes ${src_dir}/*.cpp)
add_executable(${demo_basename} ${demo} ${src_codes})
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(hello-world-01 LANGUAGES CXX)
include_directories(${PROJECT_SOURCE_DIR}/inc)
set(src_dir ${PROJECT_SOURCE_DIR}/src)
file(GLOB src_codes ${src_dir}/*.cpp)
set(demo_dir ${PROJECT_SOURCE_DIR}/demo)
file(GLOB demo_codes ${demo_dir}/*.cpp)
foreach(demo ${demo_codes})
string(REGEX MATCH "[^/]+$" demo_file ${demo})
string(REPLACE ".cpp" "" demo_basename ${demo_file})
add_executable(${demo_basename} ${demo} ${src_codes})
endforeach()
#include<iostream>
#include<string>
#include "test.h"
int main()
{
std::cout<<"This is cmd_dir."<<std::endl;
test_log();
return 0;
}
因篇幅问题不能全部显示,请点此查看更多更全内容