Skip to main content

Posts

Showing posts from 2019

Bootstrapping a cmake project based on Hunter in Linux and Windows

This is the third post in my exploration of the package managers for C++ in Linux and Windows environments. This time I tested out the Hunter package manager with the same toy C++ program with header-only boost-core and boost-optional and boost-filesystem (linking necessary) dependencies. The previous blog posts in this series were about 1) a simplistic use of vcpkg from cmake and 2) a little more sophisticated use of vcpkg with cmake . The examples work for both Linux and Windows environments. Recap The following is a barebones C++ cmake project hunter_test hunter_test ├── CMakeLists.txt ├── include │   └── driver.h ├── src │   └── driver.cpp └── test └── driver_test.cpp 3 directories, 4 files The driver.cpp and driver_test.cpp files have just a main function that does nothing. driver.h is empty. The CMakeLists.txt looks as follows. cmake_minimum_required (VERSION 3.12) project (vcpkg_test CXX) set(CMAKE_CXX_STANDARD 17) add_executable(driver src/driver.cpp) target_i

Bootstrapping a vcpkg-based project in Linux and Windows with idiomatic cmake

This blog is part #2 in the series of trying out different package managers to bootstrap a cmake project. Checkout part #1 about Bootstrapping a vcpkg-based cmake project in Visual Studio . Part #3 is about bootstrapping Hunter-based cmake project in Linux and Visual Studio . The cmake code in the previous post works well on Linux too. After all, both cmake and vcpkg are designed for cross-platform build management. So what's new here? This time around we'll get the same project off the ground in both Linux and Windows with cmake proper. Last time, the cmake script CMakeLists.txt felt like a poorly written bash script. Since that blogpost, I received a lot of feedback. Feedback from Carlos ORyan (Google) forms the basis of this blog post. It would be more accurate to say that I'm downright stealing the cmake-vcpkg integration scripts he shared with me. They are open-source and available at google-cloud-cpp/super . I've copied them nearly verbatim to my vcpkg_cmake_b

Bootstrapping a vcpkg-based cmake project in Visual Studio

After the last week's 2019 Microsoft MVP Summit , I decided to give Microsoft vcpkg a shot. I've a cmake project at work and we target Linux using the Hunter package manager . So vcpkg had been on the back-burner for me. I'm targeting a 4 part 3 part blog series. Bootstrapping a cmake project based on vcpkg in Visual Studio (this post) Bootstrapping a cmake project based on vcpkg in Linux and Visual Studio with idiomatic cmake ( here ) Bootstrapping a cmake project based on Hunter in Linux and Windows ( here ) As of this writing I'm new to vcpkg. So I apologize in advance if you are annoyed by noob mistakes. Please leave a comment if you notice something. If you prefer to clone/browse a github project. All contents in this blogpost are available under cpptruths/cpp0x/vcpkg_test (branch vcpkg_cmake_blog ). To start with, I've a barebones C++ project with nearly empty driver.cpp and driver.h files. Later, I'll add Boost core and optional as third p

Review of Manning's Functional Programming in C++

Last year I reviewed the pre-print manuscript of Manning's Functional Programming in C++ written by Ivan Čukić. I really enjoyed reading the book. I enthusiastically support that the book Offers precise, easy-to-understand, and engaging explanations of functional concepts. Who is this book for This book expects a reasonable working knowledge of C++, its modern syntax, and semantics from the readers. Therefore, reading this book might require a companion book for C++ beginners. I think that’s fair because FP is an advanced topic. C++ is getting more and more powerful day by day. While there are many FP topics that could be discussed in such a book, I like the practicality of the topics selected in this book. Here's the table of contents at a glance. This is a solid coverage of functional programming concepts to get a determined programmer going from zero-to-sixty in a matter of weeks. Others have shared their thoughts on this book as well. See Rangarajan Krishnamo

Unit Testing C++ Templates and Mock Injection Using Traits

Unit testing your template code comes up from time to time. (You test your templates, right?) Some templates are easy to test. No others. Sometimes it's not clear how to about injecting mock code into the template code that's under test. I've seen several reasons why code injection becomes challenging. Here I've outlined some examples below with roughly increasing code injection difficulty. Template accepts a type argument and an object of the same type by reference in constructor Template accepts a type argument. Makes a copy of the constructor argument or simply does not take one Template accepts a type argument and instantiates multiple interrelated templates without virtual functions Lets start with the easy ones. Template accepts a type argument and an object of the same type by reference in constructor This one appears straight-forward because the unit test simply instantiates the template under test with a mock type. Some assertion might be tested in