Let's CMake an ASIO Socket Wrapper project!

by Jan Gabriel | 09 Dec 2020

last edited: 17 Jan 2021

CMake C++11 Project-Structure Asio-Wrapper


There is a very good reason why I chose the CMake topic for my Hello World post. If you want to create a C/C++ software solution that needs to build cross-platform and support multiple compilers, then CMake is for you. There really is a myriad of other reasons too, but for the purposes of this post, I'll stick to those two.

I like programming in a platform-independent way. This is not always possible, but build tools like CMake do Make it easier. I also decided to start my Cpp::Engineer blog journey with a nice network communication project and write about my lessons learned as I go along.

Thus, without further ado, I'll be writing a wrapper for socket communication using the well-known ASIO C++ Library. ASIO provides cross-platform networking capabilities. Our aim will be to write an ASIO wrapper library with clear-to-use classes, which will enable our future software to communicate with the outside world.

VCS - Version Control System

I'll be using GIT for version control and the repository will be hosted on Github at asio-wrapper.

Project Structure

We also need to decide on our initial project structure. We'll keep it simple as follows:

.
+-- lib
|   +-- asio-include
+-- include
|   +-- our-library-public-includes
+-- src
|   +-- our-source-files.cc
|   +-- our-private-header-files.h
+-- readme.md
+-- CMakeLists.txt

Build System

The CMakeLists.txt will enable us to structure our build process. There is a very good tutorial on CMake.org, which we will use to set up our top-level CMakeLists.txt file.

We will also use the ExternalProject_Add(), as shown in the documentation, to automatically clone the ASIO version we want.

C++ Version

For this project, I'll be using C++11. This will ensure the best adoption into legacy systems.

Style Convention

I'm also going to adopt the Google C++ Style style convention for this project.

Okay, you might ask why do I start my project mentioning:

  • Version Control System;
  • Project structure;
  • Build System;
  • C++ Version; and
  • Style Convention?

Well, from past experience, I've learned that there are certain things that really just makes your life so much easier when you do it from the get-go. In this case, these five points are a good place to start.

For now, this will suffice in getting us up and running on our first Cpp::Engineer open-source project.

Happy coding.