详细内容
#根Cmakelists.txt
cmake_minimum_required(VERSION 3.20)
project(main)
add_subdirectory(submodules)
add_executable(main main.cpp)
target_link_libraries(main hellolib)
#sub... cmake
cmake_minimum_required(VERSION 3.20)
project(submodules)
add_subdirectory(hello)
#hello cmake
cmake_minimum_required(VERSION 3.20)
project(hellolib)
add_library(hellolib STATIC src/hello.cpp)
target_include_directories(hellolib PUBLIC include)
// hello.hpp
#pragma once//少用头文件保护
#include <iostream>
namespace hello{
void say_hello();
}
// hello.cpp
#include "hello.hpp"
void hello::say_hello()
{
std::cout << "hello world" << std::endl;
}
// main.cpp
#include <iostream>
#include "hello.hpp"
int main()
{
hello::say_hello();
return 0;
}
every submodule create in directory submodules
.
├── CMakeLists.txt
├── main.cpp
├── metainfo
│ ├── .gitignore
│ └── LICENSE
├── readme.md
└── submodules
├── CMakeLists.txt
└── hello
├── CMakeLists.txt
├── include
│ └── hello.hpp
└── src
└── hello.cpp
5 directories, 9 files
可能可以完善
provide by @etcix