| Start |
|---|
| Generating Build Environment with CMake CMake (opens new window) generates build environments for nearly any compiler or IDE from a single project definition. The following examples will demonstrate how to add a CMake file to the cross-platform "Hello World" C++ code (opens new window). CMake files are always named "CMakeLists.txt" and should already exist in every project's root directory (and possibly in sub-directories too.) A basic CMakeLists.txt file looks like: See it live on Coliru (opens new window). This file tells CMake the project name, what file version to expect, and instructions to generate an executable called "HelloWorld" that requires Generate a build environment for your installed compiler/IDE from the command line: Build the application with: This generates the default build environment for the system, depending on the OS and installed tools. Keep source code clean from any build artifacts with use of "out-of-source" builds: CMake can also abstract the platform shell's basic commands from the previous example: CMake includes generators (opens new window) for a number of common build tools and IDEs. To generate makefiles for Visual Studio's |
Compiling with GNU make IntroductionThe GNU Make (styled GNU Make is especially notable for being attached to the GNU Project, which is attached to the popular GNU/Linux operating system. GNU Make also has compatible versions running on various flavors of Windows and Mac OS X. It is also a very stable version with historical significance that remains popular. It is for these reasons that GNU Make is often taught alongside C and C++. Basic rulesTo compile with make, create a Makefile in your project directory. Your Makefile could be as simple as: Makefile NOTE: Make absolutely sure that the indentations are with a tab, not with four spaces. Otherwise, you'll get an error of To run this from the command-line, do the following: Incremental buildsWhen you start having more files, make becomes more useful. What if you edited a.cpp but not b.cpp? Recompiling b.cpp would take more time. With the following directory structure: This would be a good Makefile: Makefile Again watch the tabs. This new Makefile ensures that you only recompile changed files, minimizing compile time. DocumentationFor more on make, see the official documentation by the Free Software Foundation (opens new window), the stackoverflow documentation (opens new window) and dmckee's elaborate answer on stackoverflow (opens new window). |
| Building with SCons You can build the cross-platform "Hello World" C++ code (opens new window), using Scons (opens new window) - A Python (opens new window)-language software construction tool. First, create a file called Now, from the terminal, run (although the details will vary depending on your operating system and installed compiler). The builds the executable |
Autotools (GNU) IntroductionThe Autotools are a group of programs that create a GNU Build System for a given software package. It is a suite of tools that work together to produce various build resources, such as a Makefile (to be used with GNU Make). Thus, Autotools can be considered a de facto build system generator. Some notable Autotools programs include:
In general, Autotools is meant to generate the Unix-compatible script and Makefile to allow the following command to build (as well as install) most packages (in the simple case): As such, Autotools also has a relationship with certain package managers, especially those that are attached to operating systems that conform to the POSIX Standard(s). |
Ninja IntroductionThe Ninja build system is described by its project website as "a small build system with a focus on speed." (opens new window) Ninja is designed to have its files generated by build system file generators, and takes a low-level approach to build systems, in contrast to higher-level build system managers like CMake or Meson. Ninja is primarily written in C++ and Python, and was created as an alternative to the SCons build system for the Chromium project. |
NMAKE (Microsoft Program Maintenance Utility) IntroductionNMAKE is a command-line utility developed by Microsoft to be used primarily in conjunction with Microsoft Visual Studio and/or the Visual C++ command line tools. NMAKE is build system that falls under the Make family of build systems, but has certain distinct features that diverge from Unix-like Make programs, such as supporting Windows-specific file path syntax (which itself differs from Unix-style file paths). RemarksCurrently, there exists no universal or dominant build system for C++ that is both popular and cross-platform. However, there do exist several major build systems that are attached to major platforms/projects, the most notable being GNU Make with the GNU/Linux operating system and NMAKE with the Visual C++/Visual Studio project system. Additionally, some Integrated Development Environments (IDEs) also include specialized build systems to be used specifically with the native IDE. Certain build system generators can generate these native IDE build system/project formats, such as CMake for Eclipse and Microsoft Visual Studio 2012. |
Read Article
https://develop.horje.com/learn/1434/reference