# This is a single line comment Targets The different types of targetsĪ target usually is an executable or a library, but can also be a custom target if your project needs to run some custom tools. 0 LANGUAGES C CXX) CommentsĬomments start with the character # and can be multiline ( bracket comments) if following the bracket_open syntax. This can be done easily with the project command: project(YOUR_PROJECT_NAME VERSION 0.1. Then, you'll want to specify the name, languages and version (needed for packaging purposes). Please do not use something older than 3.1, which dates back to 2014! cmake_minimum_required(VERSION 3.14) Project description In our case we choose CMake 3.14 as it is not too old and supports most recent features. This is important because CMake can have different behaviours based on its versions, which are named policies.ĭepending on the features you will be using, you might need to ask for more recent versions of CMake. The first thing you will need in it, is to specify the minimum version of CMake you will be using. CMake uses a file named CMakeLists.txt, and it is written in its own scripting language. The CMakeLists.txt fileĪll build systems require some kind of entrypoint for the definition of the project. This is the first article of a mini series related to build systems and continuous integration. We hope to answer this question so that the C++ community can thrive, and make it easier for everyone to integrate any library in a project. So while CMake is far from perfect, for now, it does the job.īut how does one write a good CMake project? It also requires no additional dependency such as Python which usually makes it a tiny bit easier to install for Continuous Integration on platforms such as Windows. We based this choice on the fact that most of the ecosystem is using CMake, so IDEs now have decent support for it, so do most libraries and major package managers. There are many (relatively) new (meta) buildsystems around lately such as build2 or meson. Old ways of doing this were quite cumbersome.Cmake,tutorial,C++,buildsystem Why CMake?Īt siliceum, we decided to use CMake for our C++ based projects. I hope this helps everybody as much as it has helped me. If it has been installed in a non-standard path, it is also easy, just tell CMake where to find MyLibConfig.cmake using: cmake -DMyLib_DIR=/non/standard/install/path. That's it, if it has been installed in a standard directory it will be found and there is no need to do anything else. #No need to perform include_directories(.) Set VERSION property (optional but it is a good practice): set_target_properties(mylib PROPERTIES VERSION $ FILE MyLibConfig.cmake)Īfter running CMake and installing the library, there is no need to use Find***.cmake files, it can be used like this: find_package(MyLib REQUIRED) If you are lazy, copy-paste output of ls -1 sources/*.cpp : add_library(mylib SHARED This feature does not provide attended mastery of the compilation process. cmake says it is mandatory and it will define convenient variables PROJECT_NAME, PROJECT_VERSION and PROJECT_DESCRIPTION (this latter variable necessitate cmake 3.9): project(mylib VERSION 1.0.1 DESCRIPTION "mylib description")ĭeclare a new library target. Always specify the minimum required version of cmake cmake_minimum_required(VERSION 3.9)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |