Skip to content

Commit f6c339a

Browse files
Add documentation on how to include the project using CMake
1 parent 1c8dc59 commit f6c339a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,58 @@
55
66
```C++```'s native input/output library (```iostream```) doesn't provide the kind of high-level functions that you might like to use in your own projects, such as clearing the console, or stopping the natural control flow until a given key is pressed. This library aims to solve that in an beginner-friendly approach!
77

8+
## How to implement in your own projects, using ```CMake```
9+
10+
> [!TIP]
11+
> The simplest way to implement this library in your projects would be by fetching the library as a subfolder of a given project's build system, and ultimately, make use of ```include_directory()``` to execute this folder's ```CMakeLists.txt```, which makes it possible to use ```target_link_libraries()``` with your executable and the CppSafeIO library, as follows:
12+
13+
Your project's directory structure:
14+
```
15+
./project
16+
CMakeLists.txt
17+
/src
18+
/CppSafeIO
19+
```
20+
21+
Your project's main ```CMakeLists.txt```:
22+
```
23+
...
24+
25+
add_subdirectory(CppSafeIO)
26+
target_link_libraries(YourExecutable CppSafeIO)
27+
28+
...
29+
```
30+
31+
> [!NOTE]
32+
> This approach is used by this project's ```tests``` directory.
33+
34+
Nonetheless, I highly recommend making use of a second, cleaner approach where you don't have to directly include the library as one of your project's subdirectories:
35+
36+
> [!IMPORTANT]
37+
> For this approach, your ```CMake``` build system should use at least ```CMake v3.14.```.
38+
39+
You can just fetch it using ```FetchContent```, and then link the library as follows:
40+
41+
Your project's main ```CMakeLists.txt```:
42+
```
43+
...
44+
45+
include(FetchContent)
46+
47+
FetchContent_Declare( cpp-safe-io
48+
GIT_REPOSITORY https://github.com/DanielRamirez404/Cpp-Safe-IO.git
49+
GIT_TAG v1.1.0
50+
GIT_SHALLOW TRUE
51+
)
52+
53+
FetchContent_MakeAvailable(cpp-safe-io)
54+
55+
target_link_libraries(YourExecutable CppSafeIO)
56+
57+
...
58+
```
59+
860
## How to use
961

1062
You only need to include the ```cpp-safe-io.h``` header file. Henceforth, all of the library's functions will be available inside of the ```CppSafeIO``` namespace, similarly to the ```std``` namespace of ```C++```'s standard library. Here's a simple example showcasing a program that won't exit until the enter key is pressed.

0 commit comments

Comments
 (0)