Producer.cpp int main(int argc, char** argv)) In the main() function of our executable, we just process the input parameter and exit the program if no one value (or a value that can't be processed) is provided. Our sample program is a simple command-line tool: It takes an integer as an argument and outputs numbers randomly shuffled in the range from one to the provided input value. In addition, the configuration described in the CMakeLists.txt can be read by many editors like QtCreator, VSCodium/VSCode, or Visual Studio. When CMake processes this file, it automatically detects the installed compilers on your systems and creates a working Makefile. This information gets made available to CMake in the file CMakeLists.txt using a special description language. At a high altitude, you define the individual parts of your project (executables, libraries), compiling options (C/C++ standard, optimizations, architecture), the dependencies (header, libraries), and the project structure on file level. What sounds simple at first glance can be pretty complex at second glance. Why CMake?ĬMake is a build system generator that creates the Makefile for your project. I've tested the steps described in this article. As usual, the related example code is available on GitHub. In this article, I will prepare a C/C++ build system based on CMake and VSCodium. Aside from that, it will be easier for you to get others involved in your project. If you build up your project from the beginning on a powerful toolchain, you will benefit from a faster and safer development. The contents of the file will be made available to the calling script of find_package().This article is part of a series about open source DevOps tools for C/C++ development. We just need to provide the my_library-config.cmake file. Set(MY_LIBRARY_VERSION $ - matches this expression. Set(MY_LIBRARY_VERSION_MINOR 0 CACHE STRING "minor version" FORCE) Set(MY_LIBRARY_VERSION_MAJOR 1 CACHE STRING "major version" FORCE) # define library version (update: apparently you can also do it in project()!) The root CMakeLists.txt can look as follows: cmake_minimum_required(VERSION 3.0) This allows a seperation of CMake’s config files and other, unrelated configuration macros etc. The configurations will be set in the file which will be preprocessed to config_impl.hpp and included by config.hpp. The root CMakeLists.txt defines configuration options and adds the subdirectories. The library, the examples and the tool each has their own CMakeLists.txt defining the target and related code in their subdirectory. It also comes with some examples, a tool and unit tests. So we have a library consisting of various header and source files. The setupįor the scope of the tutorial, let’s say we have a library that has the following CMake structure: - include/ Throughout this post, I’ll be assuming a 3.x CMake version and an already existing CMake project. In particular, the system will be able to handle multiple installed versions and multiple configurations. In this post, I will show you how to install your library so that it can be used easily by other projects. As of version 0.5 my memory library now provides support for system-wide installation and CMake’s find_package().īecause I’ve spent hours of trial and error to come up with it, I’ll document it here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |