Skip to content

Commit 797acc7

Browse files
authored
Merge pull request #79 from yusuf601/main
docs: add cmake instalation guide
2 parents cc85260 + 39a4466 commit 797acc7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ including various member functions, iterators, and algorithms such as sort, merg
3737
- **Compiler**: g++ 10+/clang++ 12+
3838
- **OS**: Linux(recomended),MacOS,Mikocok
3939
## Instalation
40+
41+
### 1.add header manual(not recomended)
4042
Clone this repo
4143
```bash
4244
git clone https://github.com/Build-X-From-Scratch/forward_list_sratch.git
@@ -46,6 +48,47 @@ git clone https://github.com/Build-X-From-Scratch/forward_list_sratch.git
4648
cp -r forward_list_sratch/header/forward_list.hpp .
4749
```
4850

51+
### 2. use CMake (Recomended)
52+
53+
If your project uses CMake, you can integrate this library using `FetchContent`. Add the following code to your `CMakeLists.txt`:
54+
```cmake
55+
include(FetchContent)
56+
57+
FetchContent_Declare(
58+
forward_lists
59+
GIT_REPOSITORY https://github.com/Build-X-From-Scratch/forward_list_sratch.git
60+
GIT_TAG v1.0.0
61+
)
62+
FetchContent_MakeAvailable(forward_lists)
63+
```
64+
65+
Then link the library to your executable:
66+
```cmake
67+
add_executable(${PROJECT_NAME} main.cpp)
68+
69+
target_link_libraries(${PROJECT_NAME} PRIVATE forward_list)
70+
```
71+
72+
#### CMakeLists complete example
73+
```cmake
74+
cmake_minimum_required(VERSION 3.14)
75+
project(MyProject)
76+
77+
set(CMAKE_CXX_STANDARD 17)
78+
79+
include(FetchContent)
80+
81+
FetchContent_Declare(
82+
forward_lists
83+
GIT_REPOSITORY https://github.com/namamu/mystl.git
84+
GIT_TAG v1.0.0
85+
)
86+
FetchContent_MakeAvailable(forward_lists)
87+
88+
add_executable(${PROJECT_NAME} main.cpp)
89+
target_link_libraries(${PROJECT_NAME} PRIVATE forward_list)
90+
```
91+
4992
## example
5093
```cpp
5194
#include <iostream>

0 commit comments

Comments
 (0)