Compiling and running your program is as easy as pressing the “play” button in the IDE. Writing software for Windows is very easy: just download and install Microsoft Visual Studio and off you go. Unsurprisingly, these are not the only IDEs available that can build C programs and libraries, but what is the one thing that most popular IDEs have in common? CMake support. Maybe MS Visual Studio, VS Code, or CLion. If you have just started learning C , you are probably using a popular IDE to edit and build (compile) your programs. This CMake tutorial was an Hello World tutorial.We have written the simplest C program, but how do we build it? In this article, I will give a brief description of CMake, a build automation tool that allows users to build software on different platforms. Hello from Badprog and CMake! :D Conclusion The message from the code should appear on Cygwin: Here we are, the executable BadprogTutorial.exe has been added. Linking CXX executable BadprogTutorial.exe ![]() Building CXX object CMakeFiles/BadprogTutorial.dir/ Scanning dependencies of target BadprogTutorial Now let's use our Makefile by simply typing in Cygwin:Ī new message should appear in your terminal: │ │ ├── CMakeDetermineCompilerABI_CXX.binĪll those files aren't useful for us, they are used by CMake. #endif // !_BADPROG_H Generating the Makefileīut it comes with many other different files, below the complete list: Only the constructor to have a really easy example. Straightforward file, it prints a string from the code.Ĭout << "Hello from Badprog and CMake! :D" << endl It's of course possible to add more than 1 file for this second parameter, but here we have only 1 file. It takes 2 arguments, the first is the name of the executable and the second is the name of source files needed to generate this executable. The add_executable() command is to generate the project executable file. With the cmake_minimum_required command, we tell CMake to generate an error if the CMake version is lower than the one required (3.6 in our case). This file is a simple text file with the following code.Īdd_executable(BadprogTutorial Badprog.cpp) So we have these 3 files now in C:\dev\cmake\tutorial: To start our CMake tutorial, we need 3 files that we have to create ourselves: We will use the following directory as main directory for our tutorial: Indeed the cmake command (from Cygwin) calls the cmake.exe file within the following directory:Īnd not the one you've downloaded on the official website.Īnyway, if you want to know which version you are using, type the following command in your favorite CLI:įrom the Cygwin terminal, you should see something like this:ĬMake suite maintained and supported by Kitware (/cmake). So no need to download it from the official website.īe careful though if you installed CMake as an independant program because with Cygwin you won't use the one downloaded from the official website. If you don't know what to install, just follow this Cygwin tutorial (Part 1 and 2).ĬMake is already included inside the packages you downloaded if you followed this Cygwin tutorial. We will install it in the following directory: Our main CLI for this tutorial will be Cygwin: ![]() ![]() That's why CMake has been created, it works on every operating system (the first letter " C" standing for Cross-platform).įurthermore, with CMake it will be possible to generate Visual Studio project files, like. To be honest the main reason is because in the Windows world there is no native GNU tools available. So why creating a new tool as the GNU one works well? Thus it reduces our mechanism to only 2 steps. The make tool will generate the executable. ![]()
0 Comments
Leave a Reply. |