Skip to content

Commit a380099

Browse files
committed
Switch to CMake and harden TRANSFER size validation
1 parent 0e3970d commit a380099

13 files changed

Lines changed: 146 additions & 417 deletions

.github/workflows/release.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,38 @@ jobs:
3535
uses: msys2/setup-msys2@v2
3636
with:
3737
msystem: MINGW64
38-
install: mingw-w64-x86_64-gcc make
38+
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
3939

40-
- name: Build (release)
40+
- name: Configure
4141
env:
4242
VERSION: ${{ github.ref_name }}
4343
run: |
4444
if [ "$RUNNER_OS" == "Windows" ]; then
45-
make program \
46-
CXXFLAGS="-std=c++17 -O2 -Wall -Wextra -pthread -DFILEBROADCASTER_VERSION=\\\"${VERSION}\\\"" \
47-
LDLIBS_WIN="-lws2_32 -static -static-libgcc -static-libstdc++"
48-
mv FileBroadcaster FileBroadcaster.exe
45+
cmake -S . -B build -G Ninja \
46+
-DCMAKE_BUILD_TYPE=Release \
47+
-DBUILD_TESTING=OFF \
48+
-DFILEBROADCASTER_VERSION="${VERSION}" \
49+
-DCMAKE_EXE_LINKER_FLAGS="-static -static-libgcc -static-libstdc++"
4950
else
50-
make program \
51-
CXXFLAGS="-std=c++17 -O2 -Wall -Wextra -pthread -DFILEBROADCASTER_VERSION=\"\\\"${VERSION}\\\"\""
51+
cmake -S . -B build \
52+
-DCMAKE_BUILD_TYPE=Release \
53+
-DBUILD_TESTING=OFF \
54+
-DFILEBROADCASTER_VERSION="${VERSION}"
5255
fi
5356
54-
- name: Rename artifact
55-
run: mv ${{ matrix.artifact_name }} ${{ matrix.asset_name }}
57+
- name: Build
58+
run: cmake --build build --config Release
59+
60+
- name: Stage artifact
61+
run: |
62+
mkdir -p out
63+
cp build/${{ matrix.artifact_name }} out/${{ matrix.asset_name }}
5664
5765
- name: Upload artifact
5866
uses: actions/upload-artifact@v4
5967
with:
6068
name: ${{ matrix.asset_name }}
61-
path: ${{ matrix.asset_name }}
69+
path: out/${{ matrix.asset_name }}
6270
if-no-files-found: error
6371

6472
release:

.github/workflows/tests.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,37 @@ jobs:
2828
uses: msys2/setup-msys2@v2
2929
with:
3030
msystem: MINGW64
31-
install: mingw-w64-x86_64-gcc make mingw-w64-x86_64-gtest
31+
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-gtest
3232

3333
- name: Install dependencies (Linux)
3434
if: runner.os == 'Linux'
3535
run: |
3636
sudo apt-get update
37-
sudo apt-get install -y libgtest-dev
37+
sudo apt-get install -y libgtest-dev cmake
3838
3939
- name: Install dependencies (macOS)
4040
if: runner.os == 'macOS'
4141
run: brew install googletest
4242

43-
- name: Build program
43+
- name: Configure
4444
run: |
4545
if [ "$RUNNER_OS" == "Windows" ]; then
46-
make program LDLIBS_WIN="-lws2_32"
46+
cmake -S . -B build -G Ninja
4747
else
48-
make program
48+
cmake -S . -B build
4949
fi
5050
51-
- name: Build tests
51+
- name: Build
52+
run: cmake --build build --config Release
53+
54+
- name: Run tests
55+
# Skip e2e on Windows: SO_REUSEADDR semantics on Winsock cause one
56+
# socket to silently capture all loopback traffic, which breaks
57+
# two-process localhost tests. The protocol works fine across
58+
# separate hosts.
5259
run: |
53-
if [ "$RUNNER_OS" == "macOS" ]; then
54-
GTEST_PREFIX=$(brew --prefix googletest)
55-
make gtests GTEST_CFLAGS="-I${GTEST_PREFIX}/include" GTEST_LDFLAGS="-L${GTEST_PREFIX}/lib"
60+
if [ "$RUNNER_OS" == "Windows" ]; then
61+
ctest --test-dir build --output-on-failure -E e2e
5662
else
57-
make gtests
63+
ctest --test-dir build --output-on-failure
5864
fi
59-
60-
- name: Run tests
61-
run: ./GTests --gtest_filter=*
62-
63-
- name: Run E2E loopback tests
64-
# Skip on Windows: SO_REUSEADDR semantics on Winsock cause one socket
65-
# to silently capture all loopback traffic, which breaks two-process
66-
# localhost tests. The protocol works fine across separate hosts.
67-
if: runner.os != 'Windows'
68-
run: make e2e

CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(FileBroadcaster CXX)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_EXTENSIONS OFF)
7+
8+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
9+
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
10+
endif()
11+
12+
# Version string baked into the binary; the release workflow overrides this
13+
# from the git tag (e.g. -DFILEBROADCASTER_VERSION=v1.0.0).
14+
set(FILEBROADCASTER_VERSION "1.0.0" CACHE STRING "Version string for --version output")
15+
16+
# --- main executable ---------------------------------------------------------
17+
18+
add_executable(FileBroadcaster
19+
src/Main.cpp
20+
src/Sender.cpp
21+
src/Receiver.cpp
22+
src/Config.cpp
23+
)
24+
25+
target_include_directories(FileBroadcaster PRIVATE
26+
${CMAKE_CURRENT_SOURCE_DIR}/lib/cxxopts/include
27+
)
28+
29+
target_compile_definitions(FileBroadcaster PRIVATE
30+
FILEBROADCASTER_VERSION="${FILEBROADCASTER_VERSION}"
31+
)
32+
33+
if(MSVC)
34+
target_compile_options(FileBroadcaster PRIVATE /W4 /permissive-)
35+
else()
36+
target_compile_options(FileBroadcaster PRIVATE -Wall -Wextra)
37+
endif()
38+
39+
if(WIN32)
40+
target_link_libraries(FileBroadcaster PRIVATE ws2_32)
41+
else()
42+
find_package(Threads REQUIRED)
43+
target_link_libraries(FileBroadcaster PRIVATE Threads::Threads)
44+
endif()
45+
46+
# --- tests -------------------------------------------------------------------
47+
48+
option(BUILD_TESTING "Build the unit-test target" ON)
49+
50+
if(BUILD_TESTING)
51+
enable_testing()
52+
find_package(GTest QUIET)
53+
if(GTest_FOUND)
54+
add_executable(GTests tests/Tests.cpp)
55+
target_link_libraries(GTests PRIVATE GTest::gtest)
56+
if(NOT WIN32)
57+
find_package(Threads REQUIRED)
58+
target_link_libraries(GTests PRIVATE Threads::Threads)
59+
endif()
60+
add_test(NAME unit COMMAND GTests)
61+
else()
62+
message(STATUS "GTest not found — skipping GTests target")
63+
endif()
64+
65+
# E2E loopback test (Linux/macOS only — Winsock SO_REUSEADDR semantics
66+
# break two-process loopback, see tests/e2e.sh comment).
67+
if(NOT WIN32)
68+
add_test(
69+
NAME e2e
70+
COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/tests/e2e.sh
71+
)
72+
set_tests_properties(e2e PROPERTIES
73+
ENVIRONMENT "BINARY=$<TARGET_FILE:FileBroadcaster>"
74+
)
75+
endif()
76+
endif()

FileBroadcaster.sln

Lines changed: 0 additions & 41 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 34 deletions
This file was deleted.

README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,39 +150,37 @@ development):
150150

151151
### Requirements
152152

153-
- **Linux / macOS:** GCC 7+ or Clang 5+ with C++17 support, GNU Make, pthreads.
154-
- **Windows (MinGW64):** [MSYS2](https://www.msys2.org/) with
155-
`mingw-w64-x86_64-gcc` and `make`.
156-
- **Windows (Visual Studio):** Visual Studio 2017 or later with the v141
157-
platform toolset.
153+
- CMake 3.15+
154+
- A C++17 compiler:
155+
- GCC 7+ or Clang 5+ on Linux/macOS,
156+
- MinGW64 GCC via [MSYS2](https://www.msys2.org/) on Windows,
157+
- or MSVC 2019+ through the Visual Studio CMake generator.
158+
- pthreads (Linux/macOS).
158159

159-
### Linux / macOS / MSYS2
160+
### Build
160161

161162
```sh
162163
git clone https://github.com/gistrec/File-Broadcaster.git
163164
cd File-Broadcaster
164165
git submodule update --init --recursive
165-
make program
166+
cmake -S . -B build
167+
cmake --build build --config Release
166168
```
167169

168-
The binary is written to `./FileBroadcaster`.
169-
170-
### Windows (Visual Studio)
171-
172-
1. Clone the repository.
173-
2. Run `git submodule update --init --recursive`.
174-
3. Open `FileBroadcaster.sln` in Visual Studio.
175-
4. Build the solution.
170+
The binary lands at `build/FileBroadcaster` (or
171+
`build\Release\FileBroadcaster.exe` with the multi-config Visual Studio
172+
generator).
176173

177174
### Tests
178175

179176
```sh
180-
make gtests # unit tests (requires Google Test)
181-
./GTests
182-
183-
make e2e # loopback end-to-end test (small + large file)
177+
ctest --test-dir build --output-on-failure
184178
```
185179

180+
Runs the unit tests (requires Google Test installed) and the loopback
181+
end-to-end test. Pass `-E e2e` to skip the e2e case on Windows, where
182+
Winsock semantics break two-process loopback.
183+
186184
## License
187185

188186
[MIT](LICENSE).

0 commit comments

Comments
 (0)