2010/05/18

CMake - my first experience

Reference:
0.  Jserv's 貓也會的 CMake http://blog.linux.org.tw/~jserv/archives/001987.html   and http://jserv.sayya.org/cmake/cmake-overview.pdf
1. Drake's 把玩 CMake 的第一步 http://drakeguan.org/my_first_trial_of_cmake

This is my first time with CMake. Before it starts, I have to install cmake in my Ubuntu.
$ sudo apt-get install cmake
Then prepare some files and directories per Drake's suggestions.

*note:
myLL.c - a linked list library in 2009-07
myTcpSocket.c - a multi-thread tcp socket library in 2009-08


$ tree
.
├── build
├── CMakeLists.txt
├── lib
│   ├── CMakeLists.txt
│   ├── myLL.c
│   ├── myLL.h
│   ├── myTcpSocket.c
│   └── myTcpSocket.h
└── src
      ├── CMakeLists.txt
      ├── tcpCliDemo.c
      └── tcpSrvDemo.c

3 directories, 10 files


$ cat CMakeLists.txt 
cmake_minimum_required(VERSION 2.8)

PROJECT(MYSOCKET)
ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(src)

$ cat src/CMakeLists.txt 
INCLUDE_DIRECTORIES(${MYSOCKET_SOURCE_DIR}/lib)
LINK_DIRECTORIES(${MYSOCKET_BINARY_DIR}/lib)
ADD_EXECUTABLE(mySrv tcpSrvDemo.c)
ADD_EXECUTABLE(myCli tcpCliDemo.c)
TARGET_LINK_LIBRARIES(mySrv myTcpSocket)
TARGET_LINK_LIBRARIES(myCli myTcpSocket)

$ cat lib/CMakeLists.txt
FIND_LIBRARY(PTHREAD pthread)
ADD_LIBRARY(myLL myLL.c)
ADD_LIBRARY(myTcpSocket myTcpSocket.c)
TARGET_LINK_LIBRARIES(myTcpSocket myLL ${PTHREAD})

$ cd build
$ cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- 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
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yenping/workspace/test333/build

$ ls -al
總計 44
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:20 .
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:15 ..
-rw-r--r-- 1 yenping yenping 10833 2010-05-18 17:20 CMakeCache.txt
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:20 CMakeFiles
-rw-r--r-- 1 yenping yenping  1890 2010-05-18 17:20 cmake_install.cmake
drwxr-xr-x 3 yenping yenping  4096 2010-05-18 17:20 lib
-rw-r--r-- 1 yenping yenping  5292 2010-05-18 17:20 Makefile
drwxr-xr-x 3 yenping yenping  4096 2010-05-18 17:20 src

$ make
Scanning dependencies of target myLL
[ 25%] Building C object lib/CMakeFiles/myLL.dir/myLL.c.o
Linking C static library libmyLL.a
[ 25%] Built target myLL
Scanning dependencies of target myTcpSocket
[ 50%] Building C object lib/CMakeFiles/myTcpSocket.dir/myTcpSocket.c.o
Linking C static library libmyTcpSocket.a
[ 50%] Built target myTcpSocket
Scanning dependencies of target myCli
[ 75%] Building C object src/CMakeFiles/myCli.dir/tcpCliDemo.c.o
Linking C executable myCli
[ 75%] Built target myCli
Scanning dependencies of target mySrv
[100%] Building C object src/CMakeFiles/mySrv.dir/tcpSrvDemo.c.o
Linking C executable mySrv
[100%] Built target mySrv

$ ls -al lib/ src/
lib/:
總計 48
drwxr-xr-x 3 yenping yenping  4096 2010-05-18 17:22 .
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:20 ..
drwxr-xr-x 4 yenping yenping  4096 2010-05-18 17:20 CMakeFiles
-rw-r--r-- 1 yenping yenping  1159 2010-05-18 17:20 cmake_install.cmake
-rw-r--r-- 1 yenping yenping  4638 2010-05-18 17:22 libmyLL.a
-rw-r--r-- 1 yenping yenping 12496 2010-05-18 17:22 libmyTcpSocket.a
-rw-r--r-- 1 yenping yenping  6711 2010-05-18 17:20 Makefile

src/:
總計 80
drwxr-xr-x 3 yenping yenping  4096 2010-05-18 17:22 .
drwxr-xr-x 5 yenping yenping  4096 2010-05-18 17:20 ..
drwxr-xr-x 4 yenping yenping  4096 2010-05-18 17:20 CMakeFiles
-rw-r--r-- 1 yenping yenping  1159 2010-05-18 17:20 cmake_install.cmake
-rw-r--r-- 1 yenping yenping  6731 2010-05-18 17:20 Makefile
-rwxr-xr-x 1 yenping yenping 27179 2010-05-18 17:22 myCli
-rwxr-xr-x 1 yenping yenping 27360 2010-05-18 17:22 mySrv

$ tree
.
├── build
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   │   ├── CMakeCCompiler.cmake
│   │   ├── cmake.check_cache
│   │   ├── CMakeCXXCompiler.cmake
│   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   ├── CMakeDirectoryInformation.cmake
│   │   ├── CMakeOutput.log
│   │   ├── CMakeSystem.cmake
│   │   ├── CMakeTmp
│   │   │   └── CMakeFiles
│   │   │       └── cmTryCompileExec.dir
│   │   ├── CompilerIdC
│   │   │   ├── a.out
│   │   │   └── CMakeCCompilerId.c
│   │   ├── CompilerIdCXX
│   │   │   ├── a.out
│   │   │   └── CMakeCXXCompilerId.cpp
│   │   ├── Makefile2
│   │   ├── Makefile.cmake
│   │   ├── progress.marks
│   │   └── TargetDirectories.txt
│   ├── cmake_install.cmake
│   ├── lib
│   │   ├── CMakeFiles
│   │   │   ├── CMakeDirectoryInformation.cmake
│   │   │   ├── myLL.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── C.includecache
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── cmake_clean_target.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   ├── depend.internal
│   │   │   │   ├── depend.make
│   │   │   │   ├── flags.make
│   │   │   │   ├── link.txt
│   │   │   │   ├── myLL.c.o
│   │   │   │   └── progress.make
│   │   │   ├── myTcpSocket.dir
│   │   │   │   ├── build.make
│   │   │   │   ├── C.includecache
│   │   │   │   ├── cmake_clean.cmake
│   │   │   │   ├── cmake_clean_target.cmake
│   │   │   │   ├── DependInfo.cmake
│   │   │   │   ├── depend.internal
│   │   │   │   ├── depend.make
│   │   │   │   ├── flags.make
│   │   │   │   ├── link.txt
│   │   │   │   ├── myTcpSocket.c.o
│   │   │   │   └── progress.make
│   │   │   └── progress.marks
│   │   ├── cmake_install.cmake
│   │   ├── libmyLL.a
│   │   ├── libmyTcpSocket.a
│   │   └── Makefile
│   ├── Makefile
│   └── src
│       ├── CMakeFiles
│       │   ├── CMakeDirectoryInformation.cmake
│       │   ├── myCli.dir
│       │   │   ├── build.make
│       │   │   ├── C.includecache
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   ├── depend.internal
│       │   │   ├── depend.make
│       │   │   ├── flags.make
│       │   │   ├── link.txt
│       │   │   ├── progress.make
│       │   │   └── tcpCliDemo.c.o
│       │   ├── mySrv.dir
│       │   │   ├── build.make
│       │   │   ├── C.includecache
│       │   │   ├── cmake_clean.cmake
│       │   │   ├── DependInfo.cmake
│       │   │   ├── depend.internal
│       │   │   ├── depend.make
│       │   │   ├── flags.make
│       │   │   ├── link.txt
│       │   │   ├── progress.make
│       │   │   └── tcpSrvDemo.c.o
│       │   └── progress.marks
│       ├── cmake_install.cmake
│       ├── Makefile
│       ├── myCli
│       └── mySrv
├── CMakeLists.txt
├── lib
│   ├── CMakeLists.txt
│   ├── myLL.c
│   ├── myLL.h
│   ├── myTcpSocket.c
│   └── myTcpSocket.h
└── src
    ├── CMakeLists.txt
    ├── tcpCliDemo.c
    └── tcpSrvDemo.c

17 directories, 82 files (<--- 3 directories, 10 files)
At final, test mySrv and myCli. They seem work fine.
FINISHED.

沒有留言: