您的位置:首页 > 运维架构 > 网站架构

项目代码架构

2015-06-15 15:41 519 查看
在project目录下的树结构如下:

root@u18:~/cp/project# tree
.
├── 3rd_lib      //存放 第三方库 的目录
│   ├── libvirt-lxc.so
│   ├── libvirt-qemu.so
│   └── libvirt.so
├── build       //执行Cmake ..的目录
├── CMakeLists.txt
├── include     //头文件目录
│   └── libvirt
│       ├── libvirt-domain.h
│       ├── libvirt-domain-snapshot.h
│       ├── libvirt-event.h
│       ├── libvirt.h
│       ├── libvirt-host.h
│       ├── libvirt-interface.h
│       ├── libvirt-lxc.h
│       ├── libvirt-network.h
│       ├── libvirt-nodedev.h
│       ├── libvirt-nwfilter.h
│       ├── libvirt-qemu.h
│       ├── libvirt-secret.h
│       ├── libvirt-storage.h
│       ├── libvirt-stream.h
│       └── virterror.h
└── src      //代码目录
├── LibvirtConfig.h
├── LibvirtConfig.h.in
├── libvirt.cpp
└── Libvirt.h.in

5 directories, 23 files


  CMakeList文件内容如下:

cmake_minimum_required (VERSION 2.6)

#PROJECT(projectname [CXX] [C] [Java])  编译语言
project (Libvirt CXX)

#The version number
set (Libvirt_VERSION_MAJOR 1)
set (Libvirt_VERSION_MINOR 0)

#configure a header file to pass some of  the source code
configure_file (
"${PROJECT_SOURCE_DIR}/src/LibvirtConfig.h.in"
"${PROJECT_BINARY_DIR}/src/LibvirtConfig.h"
)

# equal to echo in shell
MESSAGE(STATUS "This is source dir: " ${PROJECT_SOURCE_DIR})
MESSAGE(STATUS "This is binary dir: " ${PROJECT_BINARY_DIR})

#add sub dir  and find CMakeList.txt in the sub dir, done it
#ADD_SUBDIRECTORY(subdir)

#将一个文件下的编译用的源文件添加到一个宏列表中
#AUX_SOURCE_DIRECTORY(. SRC_LIST)
#只将.cc .cpp .c 的文件添加到SRC_LIST中,.h除外

#将.h文件也添加进来,使用
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}/src")
FILE(GLOB_RECURSE SOURCE_FILE ./src/*.cpp  ./src/*.c)
FILE(GLOB_RECURSE HEADER_FILE *.h  *.hpp)

MESSAGE(STATUS "This is source dir: " ${SOURCE_FILE})
#MESSAGE(STATUS "This is header dir: " ${HEADER_FILE})
#add the binary tree to the search path for include files so that we will find LibvirtConfig.h
#include_directories ("${PROJECT_BINARY_DIR}/src", "${PROJECT_BINARY_DIR}/INCLUDE/libvirt")

#add the 3rd_lib
#link_directories("${PROJECT_BINARY_DIR}/3rd_Lib")
FILE(GLOB_RECURSE LIB_FILE libvirt.so*)

MESSAGE(STATUS "This is 3rd_lib file : " ${LIB_FILE})

#add the executable
add_executable(Libvirt ${SOURCE_FILE})

#link
TARGET_LINK_LIBRARIES(Libvirt ${LIB_FILE})


操作步骤:

  1、进入build目录,执行cmake .. (因为CMakelist文件在上一级目录中),生成Makefile文件

  2、执行make即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: