CPack构建外部自动项目,输出位置不良

时间:2017-06-23 14:47:26

标签: linux cmake cpack

我正在尝试使用CMake ExternalProject_Add在基于autogen的项目上构建debian。项目安装到我设置的任何前缀目录(默认为/usr/local)。问题是,当我在项目上运行make package时,生成的debian使用该前缀目录而不是/usr/local。我已经尝试了一个额外的CMake install()命令,它可以正常工作,但我仍然可以在前缀目录位置获得额外的目标输出副本。

这是完整的CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

project("sphinxbase")

find_package(Git REQUIRED)

set(CPACK_GENERATOR "DEB")
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64)
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Chuck Claunch <cclaunch@gmail.com>")
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH 1)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-list master..
                COMMAND wc -l
                OUTPUT_VARIABLE GIT_REVISION
                OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} VERSION_LESS 2.8.11)
    message(STATUS "CMake older than 2.8.11, generating timestamp using execute_process().")
    execute_process(COMMAND date -u +%Y.%m.%d.%H.%M.%S
                OUTPUT_VARIABLE DATE_STRING
                OUTPUT_STRIP_TRAILING_WHITESPACE
    )
else(if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} VERSION_LESS 2.8.11))
    message(STATUS "CMake newer than 2.8.11, generating timestamp using string(TIMESTAMP).")
    string(TIMESTAMP DATE_STRING %Y.%m.%d.%H.%M.%S UTC)
endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} VERSION_LESS 2.8.11)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
                OUTPUT_VARIABLE GIT_SHA_COMPLETE
                OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(SUBSTRING ${GIT_SHA_COMPLETE} 0 8 GIT_SHA_SHORT)
set(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${GIT_REVISION}-${DATE_STRING}-${GIT_SHA_SHORT}")
set(CPACK_DEBIAN_PACKAGE_PROVIDES ${PROJECT_NAME})
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${PROJECT_NAME})
set(CPACK_DEBIAN_PACKAGE_REPLACES ${PROJECT_NAME})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "bison, python-dev, swig")
set(CPACK_DEBIAN_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Sphinx speech recognition libraries")

set(SPHINXBASE_PREFIX_DIR ${CMAKE_BINARY_DIR}/sphinxbase)
set(SPHINXBASE_SRC_DIR ${SPHINXBASE_PREFIX_DIR}/src/libsphinxbase)
set(SPHINXBASE_INSTALL_DIR ${SPHINXBASE_PREFIX_DIR}/install)

include(ExternalProject)
ExternalProject_Add(libsphinxbase
    GIT_REPOSITORY https://github.com/cmusphinx/sphinxbase
    GIT_TAG master
    PREFIX ${SPHINXBASE_PREFIX_DIR}
    DESTDIR ${CMAKE_PREFIX_PATH}
    CONFIGURE_COMMAND cd ${SPHINXBASE_SRC_DIR} && ./autogen.sh && ./configure --prefix=${SPHINXBASE_INSTALL_DIR}
    BUILD_IN_SOURCE 1
)

add_custom_target(libsphinxbase-build
    DEPENDS libsphinxbase)

set(CPACK_PACKAGE_FILE_NAME ${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})

include(CPack)

如果我添加install(DIRECTORY ${SPHINXBASE_INSTALL_DIR} DESTINATION ${CMAKE_PREFIX_PATH}),我最终会得到正确的安装,但仍有额外的副本试图在${SPHINXBASE_INSTALLDIR}安装。如果我在PREFIX中运行构建为没有ExternalProject_Add的sudo,它可以正常工作,但我不希望构建以sudo身份运行。

我是否可以通过某种方式强制CPack获取${SPHINXBASE_INSTALL_DIR}并仅将其安装到${CMAKE_PREFIX_PATH}

1 个答案:

答案 0 :(得分:0)

我今天遇到了同样的问题。实际上,如果你运行make package,cmake将会运行,包括你不想要的make install部分。 仅使用“cpack”作为命令行。它将直接构建一个包。

你也可以这样做:DESTDIR = / tmp / truc make package

make package首先运行cmake,它执行make install。 cpack首先将安装前缀设置为临时目录,然后运行make install。