Afficher la pageAnciennes révisionsHaut de page Cette page est en lecture seule. Vous pouvez afficher le texte source, mais ne pourrez pas le modifier. Contactez votre administrateur si vous pensez qu'il s'agit d'une erreur. ====== Introduction to CMake ====== CMake is an extensible, open-source system that manages the build process in an operating system and in a compiler-independent manner. ===== Using CMake with executables ===== Lets assume we have a simple application with a single ''main.c'' file. We create a ''CMakeLists.txt'' file in the root of our project: <code cmake> cmake_minimum_required(VERSION 2.8) project(app_project) add_executable(myapp main.c) install(TARGETS myapp DESTINATION bin) </code> Thats all we need to be able to build our application. * ''cmake_minimum_required'' build requires version 2.8 or greater of cmake * ''project'' defines unique project name * ''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 ==== 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 ===== cmake.txt Dernière modification : 2017/05/19 13:43de admin