InstallTargetDependencies.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. include(DefineInstallVar)
  2. SET(DEFAULT_SEARCH_DIRECTORIES "${BIN_DIR}" "${LIB_DIR}" "${CMAKE_FIND_ROOT_PATH}" "${CMAKE_PREFIX_PATH}")
  3. SET(DEFAULT_SEARCH_SUFFIXES "bin" "lib" "../bin")
  4. # Like INSTALL_DEPENDENCIES but can be called from regular cmake code
  5. # (instead of install(CODE)), takes targets instead of files,
  6. # takes care of configuring search paths, and other platform-specific tweaks.
  7. # Arguments:
  8. # TARGETS: list of cmake targets to install.
  9. # NAME: unique string for this install.
  10. # DESTINATION: directory path to install the binaries to.
  11. # LIB_DIRS: list of paths for looking up dependencies.
  12. # LIB_DIRS_SUFFIXES: list of possible suffixes for LIB_DIRS entries.
  13. # NO_DEFAULT_PATHS: supply this value to avoid adding DEFAULT_SEARCH_DIRECTORIES
  14. # to LIB_DIRS and DEFAULT_SEARCH_SUFFIXES to LIB_DIRS_SUFFIXES.
  15. FUNCTION(INSTALL_TARGET_DEPENDENCIES)
  16. set(options NO_DEFAULT_PATHS)
  17. set(oneValueArgs NAME)
  18. set(multiValueArgs TARGETS DESTINATION LIB_DIRS_SUFFIXES LIB_DIRS)
  19. cmake_parse_arguments(DEPS "${options}" "${oneValueArgs}"
  20. "${multiValueArgs}" ${ARGN} )
  21. if(NOT DEPS_LIB_DIRS)
  22. set(DEPS_LIB_DIRS "")
  23. endif()
  24. # Set default values.
  25. if(NOT DEPS_NO_DEFAULT_PATHS)
  26. list(APPEND DEPS_LIB_DIRS ${DEFAULT_SEARCH_DIRECTORIES})
  27. set(DEPS_LIB_DIRS_SUFFIXES "${DEPS_LIB_DIRS_SUFFIXES}" ${DEFAULT_SEARCH_SUFFIXES})
  28. endif()
  29. FOREACH(TARGET ${DEPS_TARGETS})
  30. IF(NOT TARGET ${TARGET})
  31. message(FATAL_ERROR "Not a target: ${TARGET}")
  32. ENDIF()
  33. # Collect target output files.
  34. LIST(APPEND DEPLOY_TARGETS "$<TARGET_FILE:${TARGET}>")
  35. # Collect target link directories
  36. get_target_property(target_libs ${TARGET} LINK_LIBRARIES)
  37. foreach(lib ${target_libs})
  38. if(TARGET ${lib} OR NOT IS_ABSOLUTE ${lib})
  39. continue()
  40. endif()
  41. get_filename_component(lib_dir ${lib} PATH)
  42. list(APPEND DEPS_LIB_DIRS ${lib_dir})
  43. endforeach()
  44. ENDFOREACH()
  45. LIST(APPEND DEPS_LIB_DIRS ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
  46. FOREACH(LIB_PATH ${DEPS_LIB_DIRS})
  47. FOREACH(suffix ${DEPS_LIB_DIRS_SUFFIXES})
  48. list(APPEND DEPS_LIB_DIRS "${LIB_PATH}/${suffix}")
  49. ENDFOREACH()
  50. ENDFOREACH()
  51. DEFINE_INSTALL_VAR(NAME "DEPLOY_FILES" CONTENT "${DEPLOY_TARGETS}" GENERATOR_EXPRESSION)
  52. LIST(REMOVE_DUPLICATES DEPS_LIB_DIRS)
  53. IF(LMMS_BUILD_LINUX)
  54. FILE(DOWNLOAD "https://raw.githubusercontent.com/AppImage/AppImages/master/excludelist"
  55. "${CMAKE_BINARY_DIR}/excludelist")
  56. SET(additional_args INCLUDE_SYSTEM IGNORE_LIBS_FILE ${CMAKE_BINARY_DIR}/excludelist)
  57. ELSEIF(LMMS_BUILD_WIN32)
  58. SET(additional_args IGNORE_CASE IGNORE_LIBS_FILE "${LMMS_SOURCE_DIR}/cmake/install/excludelist-win")
  59. IF(CMAKE_CROSSCOMPILING)
  60. SET(additional_args "${additional_args}" GP_TOOL objdump)
  61. ENDIF()
  62. ENDIF()
  63. INSTALL(CODE "
  64. INCLUDE(\"${LMMS_SOURCE_DIR}/cmake/modules/InstallDependencies.cmake\")
  65. INSTALL_DEPENDENCIES(
  66. FILES \"\${DEPLOY_FILES}\"
  67. DESTINATION \"${DEPS_DESTINATION}\"
  68. LIB_DIRS \"${DEPS_LIB_DIRS}\"
  69. SEARCH_PATHS \"${DEPS_SEARCH_PATHS}\"
  70. ${additional_args}
  71. )
  72. ")
  73. ENDFUNCTION()