More info from lesson work
This commit is contained in:
parent
56a6387308
commit
2763eb48a0
@ -36,6 +36,9 @@ Any *one* of these commands will install:
|
||||
|
||||
So 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. You should try to get used to using `--build`, as that will free you from using only `make` to build. 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.
|
||||
|
||||
Just to clarify, you can point CMake at either the source directory *from the build directory*, or at an *existing* build directory from anywhere.
|
||||
|
||||
|
||||
## Picking a compiler
|
||||
|
||||
Selecting a compiler must be done on the first run in an empty directory. It's not CMake syntax per se, but you might not be familiar with it. To pick Clang:
|
||||
@ -56,6 +59,7 @@ You can build with a variety of tools; `make` is usually the default. To see all
|
||||
|
||||
And you can pick a tool with `-G"My Tool"` (quotes only needed if spaces are in the tool name). You should pick a tool on your first CMake call in a directory, just like the compiler. Feel free to have several build directories, like `build/` and `buildXcode`.
|
||||
You can set the environment variable `CMAKE_GENERATOR` to control the default generator (CMake 3.15+).
|
||||
Note that makefiles will only run in parallel if you explicilty pass a number of threads, such as `make -j2`, while Ninja will automatically run in parallel. You can directly pass a parallelization option such as `-j2` to the `cmake --build .` command in recent versions of CMake.
|
||||
|
||||
## Setting options
|
||||
|
||||
@ -73,13 +77,18 @@ You can actually write `make VERBOSE=1`, and make will also do the right thing,
|
||||
|
||||
You can also build just a part of a build by specifying a target, such as the name of a library or executable you've defined in CMake, and make will just build that target.
|
||||
|
||||
## Standard options
|
||||
## Options
|
||||
|
||||
CMake has support for cached options. A Variable in CMake can be marked as "cached", which means it will be written to the cache (a file called `CMakeCache.txt` in the build directory) when it is incountered. You can preset (or change) the value of a cached option on the command line with `-D`. When CMake looks for a cached variable, it will use the existing value and will not overwrite it.
|
||||
|
||||
### Standard options
|
||||
|
||||
These are common CMake options to most packages:
|
||||
|
||||
* `-DCMAKE_BUILD_TYPE=` Pick from Release, RelWithDebInfo, Debug, or sometimes more.
|
||||
* `-DCMAKE_INSTALL_PREFIX=` The location to install to. System install on UNIX would often be `/usr/local` (the default), user directories are often `~/.local`, or you can pick a folder.
|
||||
* `-DBUILD_SHARED_LIBS=` You can set this `ON` or `OFF` to control the default for shared libraries (the author can pick one vs. the other explicitly instead of using the default, though)
|
||||
* `-DBUILD_TESTING=` This is a common name for enabling tests, not all packages use it, though, sometimes with good reason.
|
||||
|
||||
## Debugging your CMake files
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user