安装
cmake-3.2.2.tar.gz
解压:tar zxvf cmake-3.2.2.tar.gz 得到 cmake-3.2.2
进入cmake-3.2.2:cd cmake-3.2.2
./bootstrap --prefix=/home/zj/cmake_install
#prefix后跟安装目录
make
make install
配置
vi /etc/profile
在文件的最后一行加入
export PATH=目录/cmake-build-3.2.2/bin:$PATH
#目录意思是cmake-build-3.2.2的绝对地址
保存退出后
source /etc/profile
验证
cmake --version
出现版本号则为成功
######################################
解压cmake.tar.gz后,在其中找到README.rst,里面有安装的过程:
UNIX/Mac OSX/MinGW/MSYS/Cygwin ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You need to have a compiler and a make installed. Run the ``bootstrap`` script you find the in the source directory of CMake. You can use the ``--help`` option to see the supported options. You may use the ``--prefix=<install_prefix>`` option to specify a custom installation directory for CMake. You can run the ``bootstrap`` script from within the CMake source directory or any other build directory of your choice. Once this has finished successfully, run ``make`` and ``make install``. In summary:: $ ./bootstrap && make && make install
我在下面的网页上找到除上面外第二种方法:
http://stackoverflow.com/questions/18615451/cmake-missing-modules-directory
添加环境变量CMAKE_ROOT,格式如下:
export CMAKE_ROOT=/home/zj/cmake_install/share/cmake3.2
#########################################################3
cmake测试
参考:http://www.ibm.com/developerworks/cn/linux/l-cn-cmake/
测试一:
新建文件夹cmake_demo1
进入cmake_demo1,新建文件main.cpp:
#include <iostream> int main() { std::cout<<"Hello World!!!"<<std::endl; return 0; }
PROJECT(main) CMAKE_MINIMUM_REQUIRED(VERSION 3.2.2) AUX_SOURCE_DIRECTORY(. DIR_SRCS) ADD_EXECUTABLE(main ${DIR_SRCS})
cmake . make
参考:http://my.oschina.net/u/1757926/blog/293976
测试二:
要求已安装opencv
新建文件加cmake_demo2
进入cmake_demo2,新建文件test.cpp:
#include <cv.h> #include <highgui.h> using namespace cv; int main(int argc, char* argv[]) { Mat image; image = imread(argv[1], 1); if (argc != 2 || !image.data) { printf("No image data\n"); scanf("%d", &argc); return -1; } namedWindow("Display Image", CV_WINDOW_AUTOSIZE); imshow("Display Image", image); waitKey(0); return 0; }
project(test) find_package(OpenCV REQUIRED) add_executable(test test) target_link_libraries(test ${OpenCV_LIBS}) cmake_minimum_required(VERSION 3.2.2)
cmake . make