Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

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:23] – [Using CMake with executables] admincmake [2017/05/19 13:43] (Version actuelle) – [Building] admin
Ligne 27: Ligne 27:
  
   * ''cmake_minimum_required'' build requires version 2.8 or greater of cmake   * ''cmake_minimum_required'' build requires version 2.8 or greater of cmake
-  * ''project'' define unique project name +  * ''project'' defines unique project name 
   * ''add_executable'' defines our binary with all linked source files    * ''add_executable'' defines our binary with all linked source files 
   * ''install'' tells cmake to install our binary into the ''bin'' directory of the install directory   * ''install'' tells cmake to install our binary into the ''bin'' directory of the install directory
  
 +==== 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
 +</code>
 +
 +And call cmake with the path to the project’s root
 +
 +<code bash>
 +$ cmake ..
 +</code>
 +
 +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=../install
 +</code>
 +
 +
 +To run the build script we can simply use the Makefile:
 +
 +<code bash>
 +$ make
 +$ make install
 +</code>
 +
 +
 +We can now run our binary from the install directory:
 +
 +<code bash>
 +$ ../install/myapp
 +</code>
 ===== Using CMake with libraries ===== ===== Using CMake with libraries =====
  
  
  • cmake.1495200198.txt.gz
  • Dernière modification : 2017/05/19 13:23
  • de admin