update_bundle.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. if (__update_bundle_included)
  2. return ()
  3. endif ()
  4. set ( __update_bundle_included YES )
  5. IF (POLICY CMP0135)
  6. CMAKE_POLICY ( SET CMP0135 NEW )
  7. ENDIF ()
  8. IF (POLICY CMP0169)
  9. CMAKE_POLICY ( SET CMP0169 OLD )
  10. ENDIF ()
  11. # env WRITEB (as bool) means that we can store downloaded stuff to our bundle (that's to refresh the bundle)
  12. # env CACHEB may provide path to persistent folder where we will build heavy stuff (unpacked sources, builds)
  13. include ( helpers )
  14. diag ( DIAGNOSTIC )
  15. SET ( SUFF "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" )
  16. string ( TOLOWER "${SUFF}" SUFF )
  17. # SUFF is line like 'darwin-x86_64' (system-arch)
  18. # special cache folder where artefacts keep. Make it absolute also
  19. if (DEFINED CACHEB)
  20. if (NOT EXISTS ${CACHEB})
  21. get_filename_component ( REL_BBUILD "${CACHEB}" REALPATH BASE_DIR "${MANTICORE_BINARY_DIR}" )
  22. file ( MAKE_DIRECTORY ${REL_BBUILD} )
  23. endif ()
  24. # get_filename_component(CACHEB "${CACHEB}" ABSOLUTE)
  25. diag ( CACHEB )
  26. set ( HAVE_BBUILD TRUE )
  27. endif ()
  28. # HAVE_BBUILD means we will build in aside folder (inside CACHEB) and then store the result for future.
  29. # make libs_bundle absolute, if any
  30. if (DEFINED LIBS_BUNDLE)
  31. get_filename_component ( LIBS_BUNDLE "${LIBS_BUNDLE}" ABSOLUTE )
  32. endif ()
  33. unset ( WRITEB )
  34. set ( WRITEB "$ENV{WRITEB}" )
  35. if (WRITEB)
  36. message ( STATUS "========================================================" )
  37. message ( STATUS "WRITEB is set, will modify bundle, will collect stuff..." )
  38. message ( STATUS "${LIBS_BUNDLE}" )
  39. message ( STATUS "========================================================" )
  40. file ( MAKE_DIRECTORY ${LIBS_BUNDLE} )
  41. else ()
  42. message ( STATUS "WRITEB is not set, bundle will NOT be modified..." )
  43. endif ()
  44. diag ( WRITEB )
  45. diag ( LIBS_BUNDLE )
  46. diag ( CACHEB )
  47. diag ( HAVE_BBUILD )
  48. if (HAVE_BBUILD)
  49. set ( CACHE_BUILDS "${CACHEB}/${SUFF}" )
  50. else ()
  51. set ( CACHE_BUILDS "${MANTICORE_BINARY_DIR}/cache" )
  52. endif ()
  53. # that is once populate cache to cmake prefix path
  54. prepend_prefix ( "${CACHE_BUILDS}" )
  55. # get path for build folder. In case with HAVE_BBUILD it will be suffixed with /arch/name flag.
  56. function ( GET_BUILD RESULT NAME )
  57. if (NOT HAVE_BBUILD)
  58. set ( detail "local " )
  59. endif ()
  60. diags ( "${NAME} build will be set to ${detail}${CACHE_BUILDS}/${NAME}" )
  61. set ( ${RESULT} "${CACHE_BUILDS}/${NAME}" PARENT_SCOPE )
  62. endfunction ()
  63. # set PLACE to external url or to path in bundle.
  64. # if WRITEB is active, download external url into bundle
  65. function ( select_nearest_url PLACE NAME BUNDLE_URL REMOTE_URL )
  66. if (NOT EXISTS "${BUNDLE_URL}" AND WRITEB)
  67. diags ( "fetch ${REMOTE_URL} into ${BUNDLE_URL}..." )
  68. file ( DOWNLOAD ${REMOTE_URL} ${BUNDLE_URL} SHOW_PROGRESS )
  69. message ( STATUS "Absent ${NAME} put into ${BUNDLE_URL}" )
  70. endif ()
  71. if (EXISTS "${BUNDLE_URL}")
  72. set ( ${PLACE} "${BUNDLE_URL}" PARENT_SCOPE )
  73. else ()
  74. set ( ${PLACE} "${REMOTE_URL}" PARENT_SCOPE )
  75. endif ()
  76. diag ( NAME )
  77. diag ( BUNDLE_URL )
  78. diag ( REMOTE_URL )
  79. endfunction ()
  80. function ( fetch_and_check NAME URL MD5 OUTDIR )
  81. include ( FetchContent )
  82. FetchContent_Declare ( ${NAME} URL "${URL}" URL_MD5 ${MD5} )
  83. FetchContent_GetProperties ( ${NAME} )
  84. if (NOT ${NAME}_POPULATED)
  85. message ( STATUS "Populate ${NAME} from ${URL}" )
  86. FetchContent_Populate ( ${NAME} )
  87. if (NOT ${NAME}_POPULATED)
  88. message (FATAL_ERROR "Populate ${NAME} from ${URL} failed.")
  89. endif()
  90. endif ()
  91. string ( TOUPPER "${NAME}" UNAME )
  92. mark_as_advanced ( FETCHCONTENT_SOURCE_DIR_${UNAME} FETCHCONTENT_UPDATES_DISCONNECTED_${UNAME} )
  93. set ( ${OUTDIR} "${${NAME}_SOURCE_DIR}" PARENT_SCOPE )
  94. endfunction ()
  95. function ( external_build module MODULE_SRC_NAME MODULE_BUILD_NAME )
  96. set ( extra_args ${ARGN} )
  97. # Did we get any optional args?
  98. unset (CMAKE_ARGS)
  99. list ( LENGTH extra_args num_extra_args )
  100. if (${num_extra_args} GREATER 0)
  101. string ( REPLACE ";" " -D" extra_args "${extra_args}" )
  102. set ( CMAKE_ARGS "-D${extra_args}" )
  103. endif ()
  104. if ( CMAKE_ARGS )
  105. set (CMAKE_ARGS "CMAKE_ARGS ${CMAKE_ARGS}")
  106. endif()
  107. set ( MODULE_SRC "${${MODULE_SRC_NAME}}" )
  108. set ( MODULE_BUILD "${${MODULE_BUILD_NAME}}" )
  109. configure_file ( ${MANTICORE_SOURCE_DIR}/cmake/external-build.cmake.in ${module}-build/CMakeLists.txt @ONLY )
  110. execute_process ( COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${module}-build )
  111. execute_process ( COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${module}-build )
  112. endfunction ()