如何通过make install仅安装一个可执行文件? [英] How to install only one executable with make install?

查看:56
本文介绍了如何通过make install仅安装一个可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有CMakeLists.txt和7个可执行文件的项目:

I have a project with CMakeLists.txt and 7 executables with it:

/Project
  /build
  /Subprogram1
  /Subprogram2
  ...
  /Subprogram7
  CMakeLists.txt

我的CMakeLists.txt:

My CMakeLists.txt :

project(Project)
cmake_minimum_required(VERSION 2.8)

set( CMAKE_CXX_FLAGS "-O0 -Wall -pedantic -std=c++11" )

include_directories( "${PROJECT_SOURCE_DIR}/headers" )
include_directories( "${PROJECT_SOURCE_DIR}/Subprogram1/headers" )
include_directories( "${PROJECT_SOURCE_DIR}/Subprogram2/headers" )
include_directories( "${PROJECT_SOURCE_DIR}/Subprogram3/headers" )
....
include_directories( "${PROJECT_SOURCE_DIR}/Subprogram7/headers" )



set( INSTALL_PATH /usr/local/bin/ )
set( INSTALL_MANPAGES_PATH /usr/local/man/man1 )



add_executable(Subprogram1
         "${PROJECT_SOURCE_DIR}/headers/headers.h"
         "${PROJECT_SOURCE_DIR}/Subprogram1/headers/headers1.cpp"
         "${PROJECT_SOURCE_DIR}/Subprogram1/src/main.cpp")

....

add_executable(Subprogram7
         "${PROJECT_SOURCE_DIR}/headers/headers.h"
         "${PROJECT_SOURCE_DIR}/Subprogram7/headers/headers7.cpp"
         "${PROJECT_SOURCE_DIR}/Subprogram7/src/main.cpp")




install( TARGETS Subprogram1 DESTINATION ${INSTALL_PATH} )
...
install( TARGETS Subprogram7 DESTINATION ${INSTALL_PATH} )

install( FILES "${PROJECT_SOURCE_DIR}/manpages/Subprogram1.1" DESTINATION ${INSTALL_MANPAGES_PATH})
...
install( FILES "${PROJECT_SOURCE_DIR}/manpages/Subprogram7.1" DESTINATION ${INSTALL_MANPAGES_PATH})

那么我只想构建和安装一个子程序3.在文件夹/build中,我输入:

Well I want to build and install only ONE Subprogram3. In folder /build I typed:

cmake ../
make Subprogram3
make install

但是Cmake和Make util制作了所有程序并安装了它们.我只需要一个Subprogram3.怎么做?而且我想将我的CMakeLists.txt保存为不可变的,仅找到cmake或制作实用程序所需的命令行参数.怎么做?

But Cmake and Make util made ALL programs and installed them. I want only one Subprogram3. How to make it? And I want to save my CMakeLists.txt immutable and only find needed commandline parameters to cmake or make utils. How to do it?

推荐答案

CMake项目的安装始终处理所有 install()调用 CMakeLists.txt .不能要求CMake仅安装特定于 的文件.

Installation of CMake project always processes all install() invocations in CMakeLists.txt. One cannot ask CMake to install only a specific file.

此外,安装阶段取决于全部 ALL 目标.CMake不会在已安装文件(或目标)与创建这些文件(或目标)的命令之间建立依赖关系.

Also, installation phase depends from the ALL target as whole. CMake doesn't create dependency between installed files (or targets) and commands which creates these files (or targets).

因此,如果您打算仅构建和安装选定的文件/目标,则脚本应发出仅创建此文件/目标的命令,并仅针对给定的文件/目标发出 install .这可以通过例如传递给 cmake option 来实现.

So, if you plan to build and install only a selected file/target, your scripts should issue commands which create only this file/target, and issue install only for given file/target. This can be achieved by, e.g., an option you passed to cmake.

如果未安装项目但打包(使用

Things are quite different, if the project is not installed but packed (using cpack).

仍然完全执行安装阶段,并且整个过程仍然取决于 ALL .

Still installation phase is completely performed, and it still depends from ALL as whole.

但是可以将在项目中 install -ed的文件分发到几个软件包中.因此,其中一个软件包将仅包含特定文件.这是通过为 install 命令分配不同的 COMPONENT 选项来实现的.

But it is possible to distribute files, install-ed in the project, into several packages. So one of this packages will contain only a specific file. This is achieved by assigning different COMPONENT options for install command.

这篇关于如何通过make install仅安装一个可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆