- #CMAKE LIST DIRECTORY CONTENTS HOW TO#
- #CMAKE LIST DIRECTORY CONTENTS INSTALL#
- #CMAKE LIST DIRECTORY CONTENTS GENERATOR#
- #CMAKE LIST DIRECTORY CONTENTS FREE#
Verbose and partial buildsĪgain, not really CMake, but if you are using a command line build tool like make, you can get verbose builds: If you don't list the source/build directory, the listing will not rerun CMake ( cmake -L instead of cmake -L. You can see a list of options with -L, or a list with human-readable help with -LH. You can directly pass a parallelization option such as -j2 to the cmake -build. Note that makefiles will only run in parallel if you explicitly pass a number of threads, such as make -j2, while Ninja will automatically run in parallel.
#CMAKE LIST DIRECTORY CONTENTS GENERATOR#
You can set the environment variable CMAKE_GENERATOR to control the default generator (CMake 3.15+).
#CMAKE LIST DIRECTORY CONTENTS FREE#
Feel free to have several build directories, like build/ and buildXcode. You should pick a tool on your first CMake call in a directory, just like the compiler. To see all the tools CMake knows about on your system, runĪnd you can pick a tool with -G"My Tool" (quotes only needed if spaces are in the tool name). You can build with a variety of tools make is usually the default. This sets it just for that one line, but that's the only time you'll need those afterwards CMake continues to use the paths it deduces from those values. That sets the environment variables in bash for CC and CXX, and CMake will respect those variables. ~/package/build $ CC=clang CXX=clang++ cmake. It's not CMake syntax per se, but you might not be familiar with it. Selecting a compiler must be done on the first run in an empty directory. You can instead use the environment variables for these, as well, such as CMAKE_BUILD_PARALLEL_LEVEL (CMake 3.12+) and VERBOSE (CMake 3.14+). Otherwise, these commands vary between build systems, such as VERBOSE=1 make and ninja -v. If you use cmake -build instead of directly calling the underlying build system, you can use -v for verbose builds (CMake 3.14+), -j N for parallel builds on N cores (CMake 3.12+), and -target (any version of CMake) or -t (CMake 3.15+) to pick a target. Just to clarify, you can point CMake at either the source directory from the build directory, or at an existing build directory from anywhere. Note that working from the build directory is historically much more common, and some tools and commands (including CTest) still require running from the build directory. You should try to get used to using -build, as that will free you from using only make to build.
So which set of methods should you use? As long as you do not forget to type the build directory as the argument, staying out of the build directory is shorter, and making source changes is easier from the source directory.
#CMAKE LIST DIRECTORY CONTENTS INSTALL#
# CMake 3.15+ only # From the source directory (pick one) ~/package $ make -C build install ~/package $ cmake -build build -target install ~/package $ cmake -install build # CMake 3.15+ only target install ~/package/build $ cmake -install. # From the build directory (pick one) ~/package/build $ make install ~/package/build $ cmake -build. If you are using a newer version of CMake (which you usually should be, except for checking compatibility with older CMake), you can instead do this: if you'd like, and it will call make or whatever build tool you are using. You can replace the make line with cmake -build. ~/package $ mkdir build ~/package $ cd build ~/package/build $ cmake. Here's the Classic CMake Build Procedure (TM):
You can technically do an in-source build, but you'll have to be careful not to overwrite files or add them to git, so just don't. Unless otherwise noted, you should always make a build directory and build from there. This is true for almost all CMake projects, which is almost everything.
#CMAKE LIST DIRECTORY CONTENTS HOW TO#
Before writing CMake, let's make sure you know how to run it to make things.