Boris Salimov
Boris Salimov

Reputation: 693

How to install only one executable with make install?

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

/Project
  /build
  /Subprogram1
  /Subprogram2
  ...
  /Subprogram7
  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})

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

cmake ../
make Subprogram3
make install

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?

Upvotes: 2

Views: 3773

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66118

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

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).

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).

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

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.

Upvotes: 2

Related Questions