[CMake] Install shared libraries only if required

Dushara Jayasinghe dushara at successful.com.au
Wed Jun 21 00:27:45 EDT 2017


Hi all,

I've got a cmake project that builds multiple executables and shared 
libraries. There are option() settings that determine which of these 
executables are built. What I'd like to be able to do is prevent the 
building and installation of shared libraries that are not required. So 
what I did is as follows:

 1. set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE) on the top level
    CMakeLists file
 2. add_library(${SHARED_LIBRARY} SHARED EXCLUDE_FROM_ALL ...)
 3. install(TARGETS ${SHARED_LIBRARY} DESTINATION ${DESTINATION} OPTIONAL)

These three settings result in the desired behaviour. However, cmake 
generates the following warning:

WARNING: Target "xxxx" has EXCLUDE_FROM_ALL set and will not be built by 
default but an install rule has been provided for it. CMake does not 
define behavior for this case.

  * Is this warning still valid in this specific scenario?
  * If so is there another/more correct way to achieve what I want?
  * If what I'm doing is acceptable, is there a way to suppress this
    warning?

Thank you

Dushara



More information about the CMake mailing list