commit f843ea2c13f63cbb9632c785dd0c9ea754939c6d Author: Bart Beumer Date: Sun Jul 27 06:46:57 2025 +0000 Initial simple version of project using conan, dev container and cmake. diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..e615f0c --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,20 @@ +FROM alpine:3.21.3 + +# Install tools required for building. +RUN apk update && \ + apk add --no-cache \ + autoconf \ + bash \ + build-base \ + cmake \ + gdb \ + git \ + libstdc++ \ + libtool \ + linux-headers \ + m4 \ + perl \ + python3 \ + py3-pip && \ + pip install --break-system-packages conan && \ + conan profile detect diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..1e64a64 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "C++", + "build": { + "dockerfile": "Dockerfile" + }, + // Configure tool-specific properties. + "customizations": { + "vscode": { + "settings": {}, + "extensions": [ + "ms-vscode.cpptools", + "twxs.cmake", + "ms-vscode.cmake-tools", + "konicy.conan-extension" + ] + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2f67a5c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "conan-extension.installArgs": [ + + "-of build", + "--build=*", + "--settings=build_type=Debug" + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..652d490 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.20) + +project(all) +enable_testing() + +add_subdirectory(src) \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..20a457e --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,8 @@ +[requires] +boost/1.88.0 +gtest/1.14.0 +[generators] +CMakeDeps +CMakeToolchain +[layout] +cmake_layout diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..4c95bae --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.20) + +add_subdirectory(example_boost) diff --git a/src/example_boost/CMakeLists.txt b/src/example_boost/CMakeLists.txt new file mode 100644 index 0000000..f8133ed --- /dev/null +++ b/src/example_boost/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.20) + +find_package(Boost 1.88.0 REQUIRED COMPONENTS serialization) + +project(hello_world_boost) + +add_executable( + ${PROJECT_NAME} + ./src/main.cpp +) + +set_property( + TARGET ${PROJECT_NAME} + PROPERTY CXX_STANDARD 20 +) + +target_link_libraries( + ${PROJECT_NAME} + Boost::serialization +) diff --git a/src/example_boost/src/main.cpp b/src/example_boost/src/main.cpp new file mode 100644 index 0000000..d17a699 --- /dev/null +++ b/src/example_boost/src/main.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +struct position +{ + double x; + double y; + + template + void serialize(Archive & ar, const unsigned int /*version*/) + { + ar & x; + ar & y; + } + + bool operator==(const position& rhs) const + { + return x == rhs.x + && y == rhs.y; + } +}; + + +int main(int argc, char* argv[]) +{ + position myposition{.x=123.0, .y=456.0}; + + std::stringstream ss; + { + boost::archive::text_oarchive oa(ss); + oa << myposition; + } + + position anotherposition; + std::cout << "serialized: " << ss.str() << std::endl; + { + boost::archive::text_iarchive ia(ss); + ia >> anotherposition; + } + + if (myposition == anotherposition) + { + std::cout << "positions are the same" << std::endl; + } + +} \ No newline at end of file