Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| cmake [2017/05/19 13:22] – créée admin | cmake [2017/05/19 13:43] (Version actuelle) – [Building] admin | ||
|---|---|---|---|
| Ligne 5: | Ligne 5: | ||
| ===== Using CMake with executables ===== | ===== Using CMake with executables ===== | ||
| - | |||
| - | |||
| - | ===== Using CMake with libraries ===== | ||
| Ligne 30: | Ligne 27: | ||
| * '' | * '' | ||
| - | * '' | + | * '' |
| * '' | * '' | ||
| * '' | * '' | ||
| + | |||
| + | ==== Building ==== | ||
| + | |||
| + | |||
| + | CMake supports out-of-source builds, so all our compiled code goes into a directory separate to the sources. | ||
| + | |||
| + | To start a build we create a new folder: | ||
| + | |||
| + | <code bash> | ||
| + | $ mkdir build | ||
| + | $ cd build | ||
| + | </ | ||
| + | |||
| + | And call cmake with the path to the project’s root | ||
| + | |||
| + | <code bash> | ||
| + | $ cmake .. | ||
| + | </ | ||
| + | |||
| + | This will generate build scripts this should be Makefiles On Linux. | ||
| + | |||
| + | By default cmake will install the build into the system directories. | ||
| + | To define a custom install directory we simply pass it to cmake: | ||
| + | <code bash> | ||
| + | $ cmake .. -DCMAKE_INSTALL_PREFIX=../ | ||
| + | </ | ||
| + | |||
| + | |||
| + | To run the build script we can simply use the Makefile: | ||
| + | |||
| + | <code bash> | ||
| + | $ make | ||
| + | $ make install | ||
| + | </ | ||
| + | |||
| + | |||
| + | We can now run our binary from the install directory: | ||
| + | |||
| + | <code bash> | ||
| + | $ ../ | ||
| + | </ | ||
| + | ===== Using CMake with libraries ===== | ||