
上QQ阅读APP看书,第一时间看更新
There is more
The official documentation at https://cmake.org/runningcmake/ gives a concise overview on running CMake. The build system generated by CMake, the Makefile in the example given above, will contain targets and rules to build object files, executables, and libraries for the given project. The hello-world executable was our only target in the current example, but running the command:
$ cmake --build . --target help
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... rebuild_cache
... hello-world
... edit_cache
... hello-world.o
... hello-world.i
... hello-world.s
reveals that CMake generates more targets than those strictly needed for building the executable itself. These targets can be chosen with the cmake --build . --target <target-name> syntax and achieve the following:
- all (or ALL_BUILD with the Visual Studio generator) is the default target and will build all other targets in the project.
- clean, is the target to choose if one wants to remove all generated files.
- depend, will invoke CMake to generate the dependecies, if any, for the source files.
- rebuild_cache, will once again invoke CMake to rebuild the CMakeCache.txt. This is needed in case new entries from the source need to be added.
- edit_cache, this target will let you edit cache entries directly.
For more complex projects, with a test stage and installation rules, CMake will generate additional convenience targets:
- test (or RUN_TESTS with the Visual Studio generator) will run the test suite with the help of CTest. We will discuss testing and CTest extensively in Chapter 4, Creating and Running Tests.
- install, will execute the installation rules for the project. We will discuss installation rules in Chapter 10, Writing an Installer.
- package, this target will invoke CPack to generate a redistributable package for the project. Packaging and CPack will be discussed in Chapter 11, Packaging Projects.