CMAKE: How to Set Target Dependencies

I am trying to install an executable using cmake. My real problem here is: how to install the executable and its dependencies.

Here is an example: I want to install one executable, which depends on two libraries of my cmake and one 3rd party (pre-compiled).

set(EXECUTABLE_NAME MyExecutable)
file(GLOB_RECURSE ${EXECUTABLE_NAME}_SOURCES *.cpp)    
add_executable(${EXECUTABLE_NAME} ${${EXECUTABLE_NAME}_SOURCES})
target_link_libraries(${EXECUTABLE_NAME} MyLibrary1
  MyLibrary2
  ${Boost_PROGRAM_OPTIONS_LIBRARY})
install(TARGETS ${EXECUTABLE_NAME}
 ARCHIVE DESTINATION lib
 LIBRARY DESTINATION lib
 RUNTIME DESTINATION bin
 COMPONENT ${EXECUTABLE_NAME})

In the end, I would like to find my two libraries with this kind of CMakeLists.txt, my executable file and Boost_PROGRAM_OPTIONS_LIBRARY in the installation folder and in my package.

What I found but failed to use:

  1. BundleUtilities.cmake, : https://cmake.org/Wiki/BundleUtilitiesExample. , , , , " ". , , . (: , .: https://cmake.org/cmake/help/v3.5/module/BundleUtilities.html)

  2. GetPrerequisites.cmake. get_prerequisites - , . , / .

,

+7
1

add_library(MyLibrary1 STATIC/SHARED/INTERFACE) add_library(boost INTERFACE) .a .so.

MyExecutable . install .

install(TARGETS target
 ARCHIVE DESTINATION lib
 LIBRARY DESTINATION lib
 RUNTIME DESTINATION bin
 COMPONENT target
)

, -

function(INSTALL_CUSTOM target
  install(TARGETS target
   ARCHIVE DESTINATION lib
   LIBRARY DESTINATION lib
   RUNTIME DESTINATION bin
   COMPONENT target
  )
endfunction()

INSTALL_CUSTOM(MyLibrary1) INSTALL_CUSTOM(boost).

0

All Articles