To use our C library in a CMake project, you only need to include this file and to reference our library with the yoctolib name. This file contains all the compilation rules for our library. Moreover, CMake is open source and is available on almost all platforms.įor these reasons, since version 0 of our C library, we added a CMakeLists.txt file in the Sources subdirectory. As we are going to see below, the CMake syntax is much simpler, making the life of the developer easier as well. cpp file into an executable, but its syntax is very complex and becomes almost incomprehensible for large projects. Indeed, GNU make already enables us to describe the commands to be run to transform a. We could wonder why not using GNU make directly. Options -log-context, Enable the message() command outputting context attached to each message -debug-trycompile, Do not delete the trycompile() build tree. Usually under Linux, one uses CMake to generate a GNU make file which then uses gcc or g to compile the source file and to create the executable.ĬMake generates makefiles which enable you to compile the application with gccĪ CMake project is composed of source files and of one or several CMakeLists.txt files containing the required information to compile the application, such as the location of the source files, the name of the executable, the libraries to be used, and so on. In other words, the role of CMake is not to actually build the executable, but to prepare a list of commands to be performed to generate the executable. CMake is neither a compiler nor an IDE, but it is a "tool for managing the build process of software". If it is not the case, we recommend that you start by reading our post " How to start in C with Yoctopuce modules" which explains how our library works.įirst of all, a few words on CMake. Note: we assume that you already have a minimal knowledge of the C language and of our programming libraries. However, we hadn't yet documented how to use CMake to compile the library and use it in a program. This process is documented in the README file and there is a post explaining how to compile the library with the Code::Blocks IDE. Open the generated solution with C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe ROOT.Recently, we have had several customers who decided to compile our C library under Linux. Generate the Microsoft Visual Studio solution with cmake -G "Visual Studio 10" /path/to/source/dir. Open the generated file with the Xcode application. Generate the Xcode project with cmake -G Xcode /path/to/source/dir. Generate a Ninja project with cmake -G Ninja /path/to/source/dir. To see the list of available generators do cmake -help. The available generators depend on the platform for which cmake have been build. CMake generatorsĬMake can generate, in addition to standard makefiles, specific projects for various integrated development environments (IDEs) such as Xcode, Eclipse, Visual Studio, etc. CMake lists are essentially just semicolon-separated strings, but if you pass such a variable to a command, it does get expanded into multiple arguments. It is recommended to delete the file CMakeCache.txt to start from a clean configuration. Variables in the CMake cache are ‘remembered’, so you do not need to type them if you execute cmake command again. The cmake executable can be referenced by using the CMAKECOMMAND variable in your CMakeLists files, as later examples will show. $ cmake -DVARIABLE:TYPE=value path/to/source
0 Comments
Leave a Reply. |