add_executable(fibonacci fib.c) - This does the magic.add_definitions(-std=c99) - This command sends arguments to the compiler, which CMake will choose for you unless otherwise told so.project(fibonacci) - This allows you to name your project and you can later on refer to the project as a whole using this string.cmake_minimum_required(VERSION 2.6) - This signifies the version of CMake that you're using and allows you to pass the language into documentation.so here is the breakdown of the CMakeLists.txt I prefer all lowercase because it is faster to type. #This tells CMake to fib.c and name it fibonacciĬMake is case insensitive, thus it does not distinguish between command() and COMMAND(). #Sends the -std=c99 flag to the gcc compiler So back to the CMakeLists.txt file to build our example #Specify the version being used as well as the language () Saves a matched expression and uses it in a later replacementįor a more detailed description of CMake syntax go here.? Matches preceding pattern zero or once only. Matches preceding pattern one or more times.* Matches preceding pattern zero or more times.Matches any character in range on either side of a dash.Matches any character(s) not inside the brackets.Matches any character(s) inside the brackets.Matches any single character other than a newline ^ Matches at beginning of a line or string.Lastly CMake also supports all of your common Regular Expressions # call the macro with the string "hello world" Simple function and macro constructions are also supported. They also provide looping commands, foreach and while. # empty, 0, N, NO, OFF, FALSE, NOTFOUND, or -NOTFOUND. # some_command will be called if the variable's value is not: CMake syntax also provides some useful flow control options. Printf("Fibonacci takes one postitive integer greater\įor( int i = 0 i a <= atof( argv ) b = i ) " not "a b c". That value is passed to the main function when it is called. Here is a very simple program I wrote in C called fib.c which lists the Fibonacci Sequence up to a given value. No more messy Makefiles.ĬMake basically requires one thing, a CMakeLists.txt file. When you use CMake it will locate include files, libraries, executables, other optional build directives, then link everything for you. More elaborately however, CMake is wonderful for it’s design to support complex directory hierarchies. You tell it where all your files are at, what you want it to do with them, and it does it. At the risk of over simplifying things, CMake looks at your project and sees a ‘file system’. It is targeted towards C and C and is usable with various compiler/OS support. CPack – A packaging tool that finalizes your project for distribution.ĬMake simplifies the potentially monstrous build system into a few easy to write files.CTest, CDash – These are used to test and debug your projects.CMake – An intelligent build system used to build simple, to very elaborate projects. ![]() CMake is the name used to refer to the entire family of tools: CMake, CTest, CDash, and CPack. CMake is a sophisticated, cross-platform, open-source build system developed by Kitware in 2001.
0 Comments
Leave a Reply. |