一:安装CMake
sudo apt-get install cmake
Do you want to continue [Y/n]? y
Get:1 http://cn.archive.ubuntu.com/ubuntu/ quantal/main libxmlrpc-core-c3 i386 1.16.33-3.1ubuntu6 [182 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu/ quantal/main emacsen-common all 2.0.3 [17.3 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu/ quantal/main cmake-data all 2.8.9-0ubuntu1 [796 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu/ quantal/main cmake i386 2.8.9-0ubuntu1 [4730 kB]
......
二:编写待测试程序
hhh@hhh-VirtualBox:~/project/test$ vi hhh.cpp
#include <iostream>
using namespace std;
int main()
{
cout<<"hello my test"<<endl;
return 0;
}
三:编写CMakefile.txt
hhh@hhh-VirtualBox:~/project/test$ vi CMakeLists.txt
PROJECT (hhh)
SET(SRC_LIST hhh.cpp)
MESSAGE(STATUS "This is BINARY dir "${HHH_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir "${HHH_SOURCE_DIR})
ADD_EXECUTABLE(hhh ${SRC_LIST})
四:执行cmake命令生成makefile文件
hhh@hhh-VirtualBox:~/project/test$ cmake .
-- The C compiler identification is GNU 4.7.2
-- The CXX compiler identification is GNU 4.7.2
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- This is BINARY dir
-- This is SOURCE dir
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hhh/project/test
五:执行make命令,生成目标文件
hhh@hhh-VirtualBox:~/project/test$ make
Scanning dependencies of target hhh
[100%] Building CXX object CMakeFiles/hhh.dir/hhh.cpp.o
Linking CXX executable hhh
[100%] Built target hhh
六:运行程序
hhh@hhh-VirtualBox:~/project/test$ ./hhh
hello my test