Skip to content

Commit 2e0d023

Browse files
committed
Fix Windows Release build; improve README
1 parent 3b6c5d7 commit 2e0d023

File tree

2 files changed

+145
-30
lines changed

2 files changed

+145
-30
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
8989
if (WIN32)
9090
add_custom_target(dist_slick_socket ALL
9191
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/dist/include
92-
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}/slick_socket.lib ${CMAKE_BINARY_DIR}/dist/lib/slick_socket.lib
93-
COMMENT "Copying slick_socket headers to dist/include"
92+
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/dist/lib
93+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/Release/slick_socket.lib ${CMAKE_BINARY_DIR}/dist/lib/
94+
COMMENT "Copying slick_socket headers and lib to dist"
9495
VERBATIM
9596
)
9697
else()

README.md

Lines changed: 142 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,142 @@ A header-only C++20 networking library providing cross-platform TCP and UDP mult
1717
- **UDP Multicast**: One-to-many communication support
1818
- **Logging**: Template-based logger interface with console output
1919

20-
## Quick Start
20+
## Installation
2121

22-
### Prerequisites
22+
### Using FetchContent (Recommended)
2323

24-
- C++20 compatible compiler
25-
- CMake 3.20 or higher
24+
The easiest way to use slick_socket is to fetch it directly in your CMakeLists.txt:
2625

27-
### Building
26+
```cmake
27+
include(FetchContent)
2828
29-
```bash
30-
# Configure build
31-
cmake -S . -B build
29+
FetchContent_Declare(
30+
slick_socket
31+
GIT_REPOSITORY https://github.com/SlickQuant/slick_socket.git
32+
GIT_TAG v1.0.0.1 # Use the desired version
33+
)
3234
33-
# Build project
34-
cmake --build build --config Debug
35+
FetchContent_MakeAvailable(slick_socket)
3536
36-
# Run tests
37-
cd build && ctest --output-on-failure -C Debug
37+
# Link against slick_socket
38+
target_link_libraries(your_target PRIVATE slick_socket)
39+
```
40+
41+
On Windows, you also need to link against `ws2_32`:
42+
```cmake
43+
target_link_libraries(your_target PRIVATE slick_socket ws2_32)
3844
```
3945

40-
### Windows (Visual Studio)
46+
### From Source
4147

42-
```bash
43-
# Configure with Visual Studio generator
44-
cmake -S . -B build -G "Visual Studio 17 2022"
48+
#### Prerequisites
4549

46-
# Build
47-
cmake --build build --config Debug
48-
```
50+
- C++20 compatible compiler (GCC 11+, Clang 12+, MSVC 2022+)
51+
- CMake 3.25 or higher
52+
53+
#### Unix/Linux/macOS
54+
55+
1. **Configure the build**:
56+
```bash
57+
cmake -S . -B build
58+
```
59+
60+
2. **Build the library**:
61+
```bash
62+
cmake --build build --config Release
63+
```
64+
65+
3. **Copy to your project**:
66+
```bash
67+
cp -r build/dist/include/slick /path/to/your/project/include/
68+
```
69+
70+
The library is header-only on Unix/Linux/macOS platforms, so only headers are needed.
71+
72+
#### Windows (Visual Studio)
73+
74+
1. **Configure the build**:
75+
```bash
76+
cmake -S . -B build -G "Visual Studio 17 2022"
77+
```
78+
79+
2. **Build the library**:
80+
```bash
81+
cmake --build build --config Release
82+
```
83+
84+
3. **Copy headers and library**:
85+
```bash
86+
xcopy build\dist\include\slick <your-project>\include\slick /E
87+
xcopy build\dist\lib\slick_socket.lib <your-project>\lib\
88+
```
89+
90+
4. **Link in your CMakeLists.txt**:
91+
```cmake
92+
# Add the slick_socket include and lib directories
93+
target_include_directories(your_target PRIVATE path/to/slick/include)
94+
target_link_directories(your_target PRIVATE path/to/slick/lib)
95+
96+
# Link the libraries
97+
target_link_libraries(your_target PRIVATE slick_socket ws2_32)
98+
```
99+
100+
**Or manually** in Visual Studio:
101+
- Add include path: `path/to/slick/include`
102+
- Add library path: `path/to/slick/lib`
103+
- Link with: `slick_socket.lib` and `ws2_32.lib`
49104

50105
## Usage
51106

52-
Since this is a header-only library, simply include the headers you need:
107+
### Basic Example
108+
109+
Include the headers you need in your project:
53110

54111
```cpp
55-
#include "tcp_server.h"
56-
#include "tcp_client.h"
57-
#include "multicast_sender.h"
58-
#include "multicast_receiver.h"
112+
#include <slick/socket/tcp_server.h>
113+
#include <slick/socket/tcp_client.h>
114+
#include <slick/socket/multicast_sender.h>
115+
#include <slick/socket/multicast_receiver.h>
59116
```
60117

118+
### Creating a TCP Server
119+
120+
```cpp
121+
#include <slick/socket/tcp_server.h>
122+
123+
class MyServer : public slick::socket::TCPServerBase<MyServer>
124+
{
125+
public:
126+
MyServer() : TCPServerBase("MyServer", {/*.port = 5000*/}) {}
127+
128+
void onClientConnected(int client_id, const std::string& address)
129+
{
130+
std::cout << "Client " << client_id << " connected from " << address << std::endl;
131+
}
132+
133+
void onClientData(int client_id, const uint8_t* data, size_t size)
134+
{
135+
// Echo back to client
136+
send_data(client_id, std::vector<uint8_t>(data, data + size));
137+
}
138+
139+
void onClientDisconnected(int client_id)
140+
{
141+
std::cout << "Client " << client_id << " disconnected" << std::endl;
142+
}
143+
};
144+
145+
int main()
146+
{
147+
MyServer server;
148+
server.start();
149+
// ... server runs in background thread
150+
return 0;
151+
}
152+
```
153+
154+
For more examples, see the [examples/](examples/) directory.
155+
61156
## Testing
62157
63158
Run the complete test suite:
@@ -78,23 +173,42 @@ Enable verbose test output:
78173
cd build && ctest -V -C Debug
79174
```
80175

81-
## Build Options
176+
## Development
82177

83-
### AddressSanitizer
178+
### Build Options
84179

85-
Enable AddressSanitizer for debugging:
180+
#### AddressSanitizer
181+
182+
Enable AddressSanitizer for debugging memory issues:
86183

87184
```bash
88185
cmake -S . -B build -DENABLE_ASAN=ON
89186
cmake --build build --config Debug
90187
```
91188

92-
### Release Build
189+
#### Release Build with Optimization
93190

94191
```bash
192+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
95193
cmake --build build --config Release
96194
```
97195

196+
### Project Structure
197+
198+
```
199+
slick_socket/
200+
├── include/slick/socket/ # Public headers
201+
│ ├── tcp_server.h # TCP server base class
202+
│ ├── tcp_client.h # TCP client base class
203+
│ ├── multicast_sender.h # UDP multicast sender
204+
│ ├── multicast_receiver.h # UDP multicast receiver
205+
│ └── logger.h # Logger interface
206+
├── src/ # Implementation files (Windows-specific)
207+
├── examples/ # Usage examples
208+
├── tests/ # Unit and integration tests
209+
└── CMakeLists.txt
210+
```
211+
98212
## Architecture
99213

100214
The library uses a three-file pattern for cross-platform support:

0 commit comments

Comments
 (0)