'C++ library public interface as single header file
This is an example of a tuigraphics library I'm working on, what would be the best approach into creating it's public interface accessible via a single header file?
├── CMakeLists.txt
├── include
│ ├── Cell.hpp
│ ├── Grid.hpp
│ ├── math.hpp
│ ├── Node.hpp
│ ├── Renderer.hpp
│ ├── shape
│ │ ├── CircleShape.hpp
│ │ ├── RectangleShape.hpp
│ │ └── Shape.hpp
│ └── types.hpp
└── src
└── Node.cpp
I would like to access the library like so:
#include <tuigraphics.hpp>
int main(void)
{
Node node(CircleShape(10), Vector2(10, 10));
return EXIT_SUCCESS;
}
I have thought about putting a header file tuigraphics.hpp
including all header files, but I'm not quite sure about it. I have never built a static library, and i would like some advice on how to proceed. Also here the CMake configuration:
project(libex)
cmake_minimum_required(VERSION 3.16)
add_library(tuigraphics STATIC)
target_include_directories(tuigraphics PRIVATE ./include)
target_sources(tuigraphics PRIVATE src/Node.cpp
include/Node.hpp
include/types.hpp
include/math.hpp
include/Cell.hpp
include/shape/CircleShape.hpp
include/shape/Shape.hpp
include/shape/RectangleShape.hpp
include/Renderer.hpp)
target_include_directories(tuigraphics PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|