Walid-Shouman
6/26/2017 - 7:08 PM

some tips using cmake.

some tips using cmake.

CMake syntax

Common variables

CMake Useful Variables: is a list with the common variables with a brief for each, following are the ones that will be used through this guide.

  • PROJECT_NAME: the name of the project set by PROJECT() command.
  • CMAKE_PROJECT_NAME: the name of the first project set by the PROJECT() command, i.e. the top level project.
  • CMAKE_INSTALL_PREFIX: location of final build output.

Common commands

CMake commands: is a list of the common commands that one uses while working with CMakeLists.txt, following are the commands that will be used through this guide

  • message: useful for debugging, prints a message of certain importance mode.
  • get_directory_property: use to capture a list of directories into a variable.

CMake usage

  • Create a CMakeLists.txt
  • Include some commands to:
    • act based on the environment.
    • search for libraries we depend on.

Variable assignment

Passing command lines

  • Prefix every variable name with -D, if only variable is to be added
cmake -DCMAKE_INSTALL_PREFIX=/usr .
cmake -DCMAKE_PREFIX_PATH="C:\Qt\5.5\msvc2013\lib\cmake;C:\protobuf\src;C:\protobuf\c‌​make\build\Release"

Setting in CMakeLists.txt

Add the following BEFORE PROJECT(< project_name>).

SET(CMAKE_INSTALL_PREFIX < install_path >)

Extras