安装CMake工具后,可以直接生成复杂可用的makefile。
我使用过的例子:(成功安装Cmake之后)
在目录下新建src目录(里面存放源代码),在src目录下有inc等头文件目录。
新建CMakeLists.txt文件。里面有Makefile的生成规则。
CMakeLists.txt的内容如下:
PROJECT(TUZI)
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_C_COMPILER "armv6z-mediatek451_001_soft-linux-gnueabi-gcc")
SET(CMAKE_CXX_COMPILER "armv6z-mediatek451_001_soft-linux-gnueabi-g++")
INCLUDE_DIRECTORIES(/workspace/tanyp/MT8655/airplay-mtk/jsoncpp/include/
../../release/BDP_Generic/build/sysroot/usr/include/ /workspace/tanyp/MT8655/airplay-mtk/libpcre/src/ src src/sites src/jni)
AUX_SOURCE_DIRECTORY(src TUZI_SRCS)
ADD_LIBRARY(tuzi_static STATIC ${TUZI_SRCS})
ADD_LIBRARY(tuzi SHARED ${TUZI_SRCS})
#ADD_EXECUTABLE(a.bin ${TUZI_SRCS})
编辑好CMakeLists.txt后,在同一目录运行cmake ./
这时,在当前目录下会生成Makefile,cmake_install.cmake,CMakeCache.txt文件,和CMakeFiles文件夹。
然后,运行make,就会调用Makefile,开始编译了。