Initial simple version of project using conan, dev container and cmake.

This commit is contained in:
Bart Beumer 2025-07-27 06:46:57 +00:00
commit f843ea2c13
9 changed files with 132 additions and 0 deletions

20
.devcontainer/Dockerfile Normal file
View File

@ -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

View File

@ -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"
]
}
}
}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/

8
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,8 @@
{
"conan-extension.installArgs": [
"-of build",
"--build=*",
"--settings=build_type=Debug"
]
}

6
CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.20)
project(all)
enable_testing()
add_subdirectory(src)

8
conanfile.txt Normal file
View File

@ -0,0 +1,8 @@
[requires]
boost/1.88.0
gtest/1.14.0
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout

3
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.20)
add_subdirectory(example_boost)

View File

@ -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
)

View File

@ -0,0 +1,48 @@
#include <sstream>
#include <iostream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
struct position
{
double x;
double y;
template<class Archive>
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;
}
}