InstallTargetDependencies.cmake 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. # SEARCH_PATHS: list of library search paths on runtime
  14. # NO_DEFAULT_PATHS: supply this value to avoid adding DEFAULT_SEARCH_DIRECTORIES
  15. # to LIB_DIRS and DEFAULT_SEARCH_SUFFIXES to LIB_DIRS_SUFFIXES.
  16. FUNCTION(INSTALL_TARGET_DEPENDENCIES)
  17. set(options NO_DEFAULT_PATHS)
  18. set(oneValueArgs NAME)
  19. set(multiValueArgs TARGETS DESTINATION LIB_DIRS_SUFFIXES LIB_DIRS SEARCH_PATHS)
  20. cmake_parse_arguments(DEPS "${options}" "${oneValueArgs}"
  21. "${multiValueArgs}" ${ARGN} )
  22. if(NOT DEPS_LIB_DIRS)
  23. set(DEPS_LIB_DIRS "")
  24. endif()
  25. # Set default values.
  26. if(NOT DEPS_NO_DEFAULT_PATHS)
  27. list(APPEND DEPS_LIB_DIRS ${DEFAULT_SEARCH_DIRECTORIES})
  28. set(DEPS_LIB_DIRS_SUFFIXES "${DEPS_LIB_DIRS_SUFFIXES}" ${DEFAULT_SEARCH_SUFFIXES})
  29. endif()
  30. FOREACH(TARGET ${DEPS_TARGETS})
  31. IF(NOT TARGET ${TARGET})
  32. message(FATAL_ERROR "Not a target: ${TARGET}")
  33. ENDIF()
  34. # Collect target output files.
  35. LIST(APPEND DEPLOY_TARGETS "$<TARGET_FILE:${TARGET}>")
  36. # Collect target link directories
  37. get_target_property(target_libs ${TARGET} LINK_LIBRARIES)
  38. foreach(lib ${target_libs})
  39. if(TARGET ${lib} OR NOT IS_ABSOLUTE ${lib})
  40. continue()
  41. endif()
  42. get_filename_component(lib_dir ${lib} PATH)
  43. list(APPEND DEPS_LIB_DIRS ${lib_dir})
  44. endforeach()
  45. ENDFOREACH()
  46. LIST(APPEND DEPS_LIB_DIRS ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
  47. FOREACH(LIB_PATH ${DEPS_LIB_DIRS})
  48. FOREACH(suffix ${DEPS_LIB_DIRS_SUFFIXES})
  49. list(APPEND DEPS_LIB_DIRS "${LIB_PATH}/${suffix}")
  50. ENDFOREACH()
  51. ENDFOREACH()
  52. DEFINE_INSTALL_VAR(NAME "DEPLOY_FILES" CONTENT "${DEPLOY_TARGETS}" GENERATOR_EXPRESSION)
  53. LIST(REMOVE_DUPLICATES DEPS_LIB_DIRS)
  54. IF(LMMS_BUILD_LINUX)
  55. FILE(DOWNLOAD "https://raw.githubusercontent.com/AppImage/AppImages/master/excludelist"
  56. "${CMAKE_BINARY_DIR}/excludelist")
  57. SET(additional_args INCLUDE_SYSTEM IGNORE_LIBS_FILE ${CMAKE_BINARY_DIR}/excludelist)
  58. ELSEIF(LMMS_BUILD_WIN32)
  59. SET(additional_args IGNORE_CASE IGNORE_LIBS_FILE "${LMMS_SOURCE_DIR}/cmake/install/excludelist-win")
  60. IF(CMAKE_CROSSCOMPILING)
  61. SET(additional_args "${additional_args}" GP_TOOL objdump)
  62. ENDIF()
  63. ENDIF()
  64. INSTALL(CODE "
  65. INCLUDE(\"${LMMS_SOURCE_DIR}/cmake/modules/InstallDependencies.cmake\")
  66. INSTALL_DEPENDENCIES(
  67. FILES \"\${DEPLOY_FILES}\"
  68. DESTINATION \"${DEPS_DESTINATION}\"
  69. LIB_DIRS \"${DEPS_LIB_DIRS}\"
  70. SEARCH_PATHS \"${DEPS_SEARCH_PATHS}\"
  71. ${additional_args}
  72. )
  73. ")
  74. ENDFUNCTION()