Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/server_workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: server_workflows.yml
on:
pull_request:
push:
branches:
- main

jobs:
build-and-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Apt update
run: |
sudo apt update
sudo apt install -y cmake

- name: Install Conan
run: pip3 install conan

- name: Configure Conan Packages
run: |
conan profile detect --force
conan install . --build=missing

- name: CMake Configure
run: cmake -S . -B build/Release -DCMAKE_TOOLCHAIN_FILE=build/Release/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release

- name: CMake Build
run: cmake --build build/Release

- name: Run tests
run: ./build/Release/server_tests_bin
42 changes: 21 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
cmake_minimum_required(VERSION 3.31)
cmake_minimum_required(VERSION 3.15)
project(http_server VERSION 1.0 LANGUAGES CXX)

set(LIBRARY "server_library")
set(TEST_TARGET "server_tests_bin")
set(TARGET "server_impl_bin")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(GTest REQUIRED)
find_package(Threads REQUIRED)


# server library
add_library(${LIBRARY}
src/HttpServer.cpp
Expand All @@ -15,31 +19,27 @@ add_library(${LIBRARY}
)
target_include_directories(${LIBRARY} PUBLIC include)
target_compile_features(${LIBRARY} PRIVATE cxx_std_17)
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_compile_options(${LIBRARY} PRIVATE -O0 -g --coverage)
endif()
target_compile_options(${LIBRARY} PRIVATE -O0 -g --coverage)
target_link_libraries(${LIBRARY} PRIVATE Threads::Threads)


# unit tests executable
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
enable_testing()
find_package(GTest REQUIRED)
add_executable(${TEST_TARGET} test/HttpServerTest.cpp)
target_link_libraries(${TEST_TARGET}
PRIVATE ${LIBRARY} GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(${TEST_TARGET})
target_compile_options(${TEST_TARGET} PRIVATE -g -O0 -g --coverage)
target_link_options(${TEST_TARGET} PRIVATE -O0 -g --coverage)
endif()
enable_testing()
add_executable(${TEST_TARGET} test/HttpServerTest.cpp)
target_link_libraries(${TEST_TARGET}
PRIVATE ${LIBRARY} GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(${TEST_TARGET})
target_compile_options(${TEST_TARGET} PRIVATE -g -O0 -g --coverage)
target_link_options(${TEST_TARGET} PRIVATE -O0 -g --coverage)


# server implementation executable
add_executable(${TARGET}
src/main.cpp
)
target_compile_options(${TARGET} PRIVATE -g -O0 -g --coverage)
target_link_options(${TARGET} PRIVATE -O0 -g --coverage)
target_link_libraries(${TARGET} PRIVATE ${LIBRARY})
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_compile_options(${TARGET} PRIVATE -g -O0 -g --coverage)
target_link_options(${TARGET} PRIVATE -O0 -g --coverage)
endif()
25 changes: 5 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,29 @@

### Building for Release mode
```bash
conan build .
cd build/Release/generators
cmake ../../.. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
conan build . --build=missing
cmake -S . -B build/Release -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release

# runs the underlying build system (Makefiles, VStudio solution files)
cmake --build .
```

### Building for Debug mode
```bash
conan build .
cd build/Debug/generators
cmake ../../.. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug

# runs the underlying build system (Makefiles, VStudio solution files)
cmake --build .
cmake --build build/Release
```

## Command to run the HttpServer impl example
```bash
# in release mode
./build/Release/server_impl_bin

# in debug mode
./build/Debug/server_impl_bin
```

## Command to run the Tests
```bash
# run tests
./build/Debug/server_test_bin
./build/Release/server_test_bin
```

## Generation of coverage reports

```bash
cd build/Debug/generators \
&& cmake --build . \
cmake --build build/Release \
&& ctest \
&& cd CMakeFiles/server_library.dir/src \
&& gcov HttpServer.cpp.gcno \
Expand Down