2

I am writing a library that contains library itself and examples and I am using CMake:

cmake_minimum_required(VERSION 3.6)
add_executable (example main.cpp)
install(DIRECTORY include DESTINATION include PATTERN ".DS_Store" EXCLUDE)

When I am running cmake --build . --target install - it compiles example target and makes installation of include directory

I want to exclude building example target and make only include directory installation when building install target and building example if running without any special target:

Here I want example to be NOT built: cmake --build . --target install

Here I want example to be built: cmake --build .

How should I change my CMakeLists.txt to make it work as I want?

Evgeniy
  • 2,481
  • 14
  • 24
  • I think it's impossible. At least the second should be `cmake --build . --target example`. At that point, a possible solution has been investigated here http://stackoverflow.com/questions/17164731/installing-only-one-target-and-its-dependencies-out-of-a-complex-project-with – Antonio Oct 14 '16 at 07:47

1 Answers1

4

You cannot exclude single CMake target when installing.

The problem is that 'install' target may depends only from 'all' (default) target.

While you may remove 'install' -> 'all' dependency (by setting CMAKE_SKIP_INSTALL_ALL_DEPENDENCY variable), you may not add another dependency for 'install'.

So, before installing

cmake --build . --target install

either performs

cmake --build .

or doesn't build anything (even library, which you want to build in any case).

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153