3

我想为 ubuntu 构建包 uci。

我下载了源码包,发现里面有C文件,header文件和CMakeLists.txt

如何用cmake构建uci项目?

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(uci C)

SET(CMAKE_INSTALL_PREFIX /usr)

ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I. -DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")

OPTION(UCI_PLUGIN_SUPPORT "plugin support" ON)
OPTION(UCI_DEBUG "debugging support" OFF)
OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
OPTION(BUILD_LUA "build Lua plugin" ON)

CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/uci_config.h.in ${CMAKE_SOURCE_DIR}/uci_config.h )

SET(LIB_SOURCES libuci.c file.c util.c delta.c parse.c)

ADD_LIBRARY(uci-shared SHARED ${LIB_SOURCES})
SET_TARGET_PROPERTIES(uci-shared PROPERTIES OUTPUT_NAME uci)
TARGET_LINK_LIBRARIES(uci-shared dl)

ADD_LIBRARY(uci-static STATIC ${LIB_SOURCES})
SET_TARGET_PROPERTIES(uci-static PROPERTIES OUTPUT_NAME uci)

ADD_EXECUTABLE(cli cli.c)
SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME uci)
TARGET_LINK_LIBRARIES(cli uci-shared dl)

ADD_EXECUTABLE(cli-static cli.c)
SET_TARGET_PROPERTIES(cli-static PROPERTIES OUTPUT_NAME uci-static)
TARGET_LINK_LIBRARIES(cli-static uci-static dl)

ADD_LIBRARY(ucimap STATIC ucimap.c)

ADD_EXECUTABLE(ucimap-example ucimap-example.c)
TARGET_LINK_LIBRARIES(ucimap-example uci-static ucimap dl)

ADD_SUBDIRECTORY(lua)

INSTALL(FILES uci.h uci_config.h ucimap.h
    DESTINATION include
)

INSTALL(TARGETS uci-shared uci-static cli cli-static
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)
4

1 回答 1

4

我不知道这种特殊情况,但 CMake 的通用操作模式如下。假设您解压缩了包源,以便 CMakeList 位于/some/path/to/source/CMakeLists.txt. 然后:

> cd /path/where/you/want/to/build
> mkdir package_name
> cd package_name
> cmake /some/path/to/source

接下来,如果需要,启动(控制台)GUI 以编辑选项的可选步骤:

> ccmake

对设置满意后:

> make
> make install

CMake 也有一个非控制台 GUI,但我从未在 Unix 上使用过它,所以我不能在那里发表评论。不过基本思路是一样的:设置一个构建目录,将 GUI 指向源目录(包含 CMakeLists.txt 的目录),配置、修改 uptions 并根据需要重新配置,生成 Makefile,退出 GUI 并运行make.

于 2013-02-05T12:17:41.723 回答