简体   繁体   中英

CMake install target dependencies

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 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 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM