Skip to content

Commit

Permalink
chore: add precompiled headers
Browse files Browse the repository at this point in the history
Add precompiled headers, switch to debug build mode.

Signed-off-by: Melg Eight <public.melg8@gmail.com>
  • Loading branch information
melg8 committed Jun 10, 2024
1 parent d38fc45 commit c19afdd
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 15 deletions.
32 changes: 32 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
"CMAKE_CXX_COMPILER": "clang++"
}
},
{
"name": "cit_default_linux_debug",
"description": "Configure default linux release mode preset",
"hidden": true,
"inherits": [
"generator_ninja",
"linker_mold",
"mode_debug"
]
},
{
"name": "cit_default_linux_release",
"description": "Configure default linux release mode preset",
Expand All @@ -81,6 +91,17 @@
"mode_release"
]
},
{
"name": "cit_gcc_debug",
"description": "Configure gcc debug mode for CMake integration tests",
"displayName": "Configure gcc debug mode for CMake integration tests",
"hidden": false,
"inherits": [
"cit_default_linux_debug",
"toolchain_conan_gcc",
"compiler_gcc"
]
},
{
"name": "cit_gcc_release",
"description": "Configure gcc release mode for CMake integration tests",
Expand All @@ -92,6 +113,17 @@
"compiler_gcc"
]
},
{
"name": "cit_clang_debug",
"description": "Configure clang debug mode for CMake integration tests",
"displayName": "Configure clang debug mode for CMake integration tests",
"hidden": false,
"inherits": [
"cit_default_linux_debug",
"toolchain_conan_clang",
"compiler_clang"
]
},
{
"name": "cit_clang_release",
"description": "Configure clang release mode for CMake integration tests",
Expand Down
2 changes: 1 addition & 1 deletion ci/builders/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CONAN_CPPSTD=$4
DIRECTORY=build_"${CONAN_COMPILER}"
cd "${DIRECTORY}"

cmake .. --preset "cit_"${CONAN_COMPILER}"_release"
cmake .. --preset "cit_"${CONAN_COMPILER}"_debug"

echo "Building..."
cmake --build . -j "$(nproc)" | camomilla -c"../.camomilla.json"
Expand Down
2 changes: 1 addition & 1 deletion ci/builders/common/cmake_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ conan create ../ci/conan_recipes/range_v3/conanfile.py
conan install .. \
--build missing \
-of "${PWD}" \
-s compiler=gcc -s compiler.version=13 -s compiler.cppstd=20 -s compiler.libcxx=libstdc++11
-s compiler=gcc -s compiler.version=13 -s compiler.cppstd=20 -s compiler.libcxx=libstdc++11 -s build_type=Debug
8 changes: 7 additions & 1 deletion cmake/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
endif()
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_BUILD_TYPE MATCHES "Release")
# In debug mode OUTCOME_TRY(a, b); is reported to have extra semi statement.
# So this check is enabled only in Release mode.
add_compiler_flags(-Wextra-semi-stmt)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compiler_flags(-Weverything)
add_compiler_flags(-Wextra-semi-stmt)
add_compiler_flags(-Wmissing-noreturn)
add_compiler_flags(-Wno-extra-semi-stmt)
add_compiler_flags(-Wcovered-switch-default)
add_compiler_flags(-Wunreachable-code)
add_compiler_flags(-Wcomma)
Expand Down
2 changes: 1 addition & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ glaze/2.6.1
gsl-lite/0.40.0
libassert/2.0.2
openssl/3.1.2
outcome/2.2.3
outcome/2.2.8
range-v3/0.12.0
spdlog/1.14.0
magic_enum/0.9.5
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ clean-all:
@rm -rf report
@echo "all cleaned"

# Remove ccache cache.
clean-ccache:
@ccache -C

# Build and load docker image.
docker-update-locally:
@just docker-build
Expand Down
4 changes: 3 additions & 1 deletion sources/coal/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ file(GLOB_RECURSE ALL_COALA_APPLICATION_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")

add_executable(coala "${ALL_COALA_APPLICATION_HEADERS}"
"${ALL_COALA_APPLICATION_SOURCES}")
"${ALL_COALA_APPLICATION_SOURCES}")

target_precompile_headers(coala PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/sources/precompiled_headers.h)

header_directories(ALL_COALA_INCLUDE_DIRECTORIES)

Expand Down
33 changes: 33 additions & 0 deletions sources/coal/application/sources/precompiled_headers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: © 2024 Melg Eight <public.melg8@gmail.com>
//
// SPDX-License-Identifier: MIT

#ifndef PRECOMPILED_HEADERS_H
#define PRECOMPILED_HEADERS_H

#include <fmt/color.h>
#include <fmt/core.h>
#include <fmt/format.h>
#include <spdlog/spdlog.h>
#include <ctre.hpp>
#include <glaze/glaze.hpp>
#include <libassert/assert.hpp>
#include <magic_enum/magic_enum.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/join.hpp>

#include <cctype>
#include <chrono>
#include <coroutine>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#endif // PRECOMPILED_HEADERS_H
10 changes: 5 additions & 5 deletions sources/coal/application/sources/websocket_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

namespace coal {

namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace beast = boost::beast;
namespace http = beast::http;
namespace websocket = beast::websocket;
namespace net = boost::asio;
using tcp = boost::asio::ip::tcp;

static constexpr auto nothrow_use_op =
boost::asio::as_tuple(boost::cobalt::use_op);
Expand Down
35 changes: 35 additions & 0 deletions sources/coal/tests/unit_tests/sources/span_reinterpret_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: © 2024 Melg Eight <public.melg8@gmail.com>
//
// SPDX-License-Identifier: MIT

#include <testing_framework.h>

namespace coal::test {

template <class T>
[[nodiscard]] std::span<T> ReinterpretAsSpanOf(
std::span<std::byte> s) noexcept {
auto data = s.data();
if (!data || s.empty()) {
return {};
}
const auto bytes = s.size_bytes();
const auto count = bytes / static_cast<int>(sizeof(T));
return std::span<T>{reinterpret_cast<T*>(data), count};
}

SCENARIO("reinterpretation of span of bytes into span of uint8_t values") {
std::vector<std::byte> data{std::byte(0), std::byte(1), std::byte(2),
std::byte(3), std::byte(4)};

const std::span<uint8_t> span = ReinterpretAsSpanOf<uint8_t>(data);

CHECK(span.size() == 5);
CHECK(span[0] == uint8_t{0});
CHECK(span[1] == uint8_t{1});
CHECK(span[2] == uint8_t{2});
CHECK(span[3] == uint8_t{3});
CHECK(span[4] == uint8_t{4});
}

} // namespace coal::test
4 changes: 3 additions & 1 deletion sources/example_glassy/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# SPDX-License-Identifier: MIT

find_package(outcome 2.2.8 REQUIRED)

file(GLOB_RECURSE ALL_GLASSY_APPLICATION_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")

Expand All @@ -13,4 +15,4 @@ add_executable(glassy_application "${ALL_GLASSY_APPLICATION_HEADERS}"

target_link_libraries(glassy_application PUBLIC glassy)

add_test(glassy_application glassy_application)
add_test(glassy_application glassy_application outcome::outcome)
2 changes: 1 addition & 1 deletion sources/example_glassy/library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT

find_package(OpenSSL 3.0.2 REQUIRED)
find_package(outcome 2.2.3 REQUIRED)
find_package(outcome 2.2.8 REQUIRED)
find_package(gsl-lite 0.40 REQUIRED)

file(GLOB_RECURSE ALL_GLASSY_LIB_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT

find_package(OpenSSL 3.0.2 REQUIRED)
find_package(outcome 2.2.3 REQUIRED)
find_package(outcome 2.2.8 REQUIRED)
find_package(gsl-lite 0.40 REQUIRED)

file(GLOB_RECURSE ALL_GLASSY_TESTS_APPLICATION_HEADERS
Expand Down
2 changes: 1 addition & 1 deletion sources/example_glassy/tests/mock_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT

find_package(OpenSSL 3.0.2 REQUIRED)
find_package(outcome 2.2.3 REQUIRED)
find_package(outcome 2.2.8 REQUIRED)

file(GLOB_RECURSE ALL_GLASSY_TESTS_APPLICATION_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")
Expand Down
2 changes: 1 addition & 1 deletion sources/example_glassy/tests/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT

find_package(OpenSSL 3.0.2 REQUIRED)
find_package(outcome 2.2.3 REQUIRED)
find_package(outcome 2.2.8 REQUIRED)
find_package(gsl-lite 0.40 REQUIRED)
find_package(range-v3 0.12.0 REQUIRED)

Expand Down

0 comments on commit c19afdd

Please sign in to comment.