From 1fd972ee078611946fe3d38d8dd4a624736a50cf Mon Sep 17 00:00:00 2001 From: James Yab Date: Wed, 10 Dec 2025 21:12:32 -0500 Subject: [PATCH 1/2] Remove the Debug mode in CMakeLists.txt The reasoning for removing the Debug mode is to simplify the GitHub Actions workflow --- CMakeLists.txt | 42 +++++++++++++++++++++--------------------- README.md | 25 +++++-------------------- 2 files changed, 26 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22d662d..db322ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.31) +cmake_minimum_required(VERSION 3.15) project(http_server VERSION 1.0 LANGUAGES CXX) set(LIBRARY "server_library") @@ -6,6 +6,10 @@ 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 @@ -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() diff --git a/README.md b/README.md index db81062..fd27e2c 100644 --- a/README.md +++ b/README.md @@ -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 \ From 8a1cff0c0f88ada2c1fc872e0151f7b1f11477ce Mon Sep 17 00:00:00 2001 From: James Yab Date: Wed, 10 Dec 2025 21:17:31 -0500 Subject: [PATCH 2/2] Add a workflow to run GTest --- .github/workflows/server_workflows.yml | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/server_workflows.yml diff --git a/.github/workflows/server_workflows.yml b/.github/workflows/server_workflows.yml new file mode 100644 index 0000000..db9b674 --- /dev/null +++ b/.github/workflows/server_workflows.yml @@ -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 \ No newline at end of file