Skip to content

Latest commit

 

History

History

README.md

Software Architecture with C++, Second Edition

Software Architecture with C++: Designing Robust C++ Systems with Modern Architectural Practices, Second Edition, published by Packt

Chapter 8: Package Management

Prerequisites

Install the following software:

  • CMake 3.28
  • Conan 2
  • GCC 15, Clang 20, MSVC 19.50

For optional packaging with CPack:

The C++ compiler in your IDE and the Conan profile must be compatible to compile examples from the IDE.

Assuming you're on Linux or using WSL. The examples are developed on Linux, but their compilation and functionality are also tested on macOS and Windows.

Configure a local Conan profile and remotes by running:

rm -rf ./build/
conan profile detect --name ./build/conan_profile

Make sure that the profile section [settings] contains:

arch=x86_64
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=15
os=Linux

Building

To build the project, configure the Conan profile as described above, cd to its directory, and then run:

conan install . --build=missing -s build_type=Release -pr:a=./build/conan_profile
cmake --preset conan-release
cmake --build --preset conan-release

If GCC 15 is not your default compiler, you can tell CMake to use it with the CMAKE_CXX_COMPILER flag:

conan install . --build=missing -s build_type=Release -pr:a=./build/conan_profile
cmake --preset conan-release -DCMAKE_CXX_COMPILER=`which g++-15`
cmake --build --preset conan-release

To pass the settings directly without a Conan profile, use the command line option --settings:all or -s:a, and the keys arch, build_type, compiler, compiler.cppstd, compiler.libcxx, compiler.version, os:

rm -rf ./build/
conan install . --build=missing -s:a build_type=Release -s:a compiler=gcc
cmake --preset conan-release
cmake --build --preset conan-release

To apply Conan dependency as a CMake Dependency Provider, clone this Git repository and then run the next command:

rm -rf ./build/cmake-conan
git clone https://github.com/conan-io/cmake-conan.git build/cmake-conan
cmake -S . -B build -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./build/cmake-conan/conan_provider.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build build

Testing

To run tests from each of the projects, cd into their respective build directory, and then simply run ctest.

Installing

In the build directory, run cmake --install . to install the software into ${CMAKE_PREFIX_PATH}. If no prefix is given, it will install system-wide. To change this, add -DCMAKE_INSTALL_PREFIX=/path/to/install/to to your cmake invocation.

Packaging

In the build directory, run cpack. Simple as that. Assuming you're running on a system supporting DEB and RPM packages, you'll get a .tar.gz file, a .zip file, a .deb and .rpm packages.

Troubleshooting

Windows Firewall can block connections to the IP address 0.0.0.0 therefore set 127.0.0.1 in customer/src/customer/main.cpp as a workaround or allow connections to that address on the host.

Building the Conan package

In the directory containing conanfile.py, run:

rm -rf ./build
conan install . --build=missing
conan build .
conan export-pkg .

The command conan export-pkg . also runs this test:

conan test test_package customer/0.0.1

Or run this command that includes the other stages to create the package:

conan create . --build=missing

Uploading the Conan package

Run Artifactory CE using Docker Compose and wait because the server takes a while to start:

cd docker
docker compose up -d

Open the URL http://localhost:8081 in a browser. The default user and password are admin:password. Navigate to Administration -> Repositories, then click on the Create a Repository button, select Local and the Package Type Conan. For example, type conan-local in the Repository key and click on Create Local Repository.

Connect the Conan remote repository:

conan remote add hinrg-tapps http://localhost:8081/artifactory/api/conan/conan-local

Configure the credentials for the remote. By default, they are admin:password:

conan remote login hinrg-tapps admin -p password

Upload the built customer package:

conan upload customer -r=hinrg-tapps

Search for the customer package:

conan search "*" -r=hinrg-tapps

Navigate to either Application -> Artifacts or Application -> Packages (wait for package processing).