Cmake

1. What is CMake

2. How to use CMake command line

3. A simple example to start (My system is Ubuntu 16.04 LTS;  g++ 5.4.0;  cmake 3.5.1)

Two files are in the same director, one is main.cpp another one is CMakeLists.txt , (big case matters). Use the commands to build and generate the executable file.

$ cmake .   

dot means current directory. 

a folder named CMakeFiles, and files like: CMakeCache.txt, cmake_insall.cmake, Makefile will be generated.

$ make

will generate a executable file.

// main.cpp

#include <iostream>

int main(){

  std::cout << "Hello World." << std::endl;

  return 0;

}

//CMakeLists.txt

cmake_minimum_required(VERSION 3.2)

set(SRC_LIST main.cpp)

project(main)

add_executable(main main.cpp)

4. More details

(1)project ( <project_name> [cxx] [c] [java])

two cmake variables are inplicitly defined here: <project_name>_BINARY_DIR    <project_name>_SOURCE_DIR

(2)SET (VAR [VALUE] [VALUE2] ...)

(3)ADD_EXECUTABLE(<ext_file_name> ${SRC_LIST})

posted @ 2020-01-13 07:58  心怀阳光  阅读(159)  评论(0编辑  收藏  举报