Makefile.cmake.in 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. ################################################################################
  2. # CMake package infrastructure
  3. #
  4. # This file implements an infrastructure that eases development of
  5. # package .mk files for CMake packages. It should be used for all
  6. # packages that use CMake as their build system.
  7. #
  8. # See the Buildroot documentation for details on the usage of this
  9. # infrastructure
  10. #
  11. # In terms of implementation, this CMake infrastructure requires
  12. # the .mk file to only specify metadata informations about the
  13. # package: name, version, download URL, etc.
  14. #
  15. # We still allow the package .mk file to override what the different
  16. # steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
  17. # already defined, it is used as the list of commands to perform to
  18. # build the package, instead of the default CMake behaviour. The
  19. # package can also define some post operation hooks.
  20. #
  21. ################################################################################
  22. ################################################################################
  23. # CMAKETARGETS_INNER -- defines how the configuration, compilation and
  24. # installation of a CMake package should be done, implements a few hooks to
  25. # tune the build process and calls the generic package infrastructure to
  26. # generate the necessary make targets
  27. #
  28. # argument 1 is the lowercase package name
  29. # argument 2 is the uppercase package name, including an HOST_ prefix
  30. # for host packages
  31. # argument 3 is the uppercase package name, without the HOST_ prefix
  32. # for host packages
  33. # argument 4 is the package directory prefix
  34. # argument 5 is the type (target or host)
  35. ################################################################################
  36. define CMAKETARGETS_INNER
  37. # define package-specific variables to default values
  38. ifndef $(2)_SUBDIR
  39. ifdef $(3)_SUBDIR
  40. $(2)_SUBDIR = $($(3)_SUBDIR)
  41. else
  42. $(2)_SUBDIR ?=
  43. endif
  44. endif
  45. $(2)_CONF_ENV ?=
  46. $(2)_CONF_OPT ?=
  47. $(2)_MAKE ?= $(MAKE)
  48. $(2)_MAKE_ENV ?=
  49. $(2)_MAKE_OPT ?=
  50. $(2)_INSTALL_HOST_OPT ?= install
  51. $(2)_INSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) install
  52. $(2)_INSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) install
  53. $(2)_CLEAN_OPT ?= clean
  54. $(2)_SRCDIR = $$($(2)_DIR)/$($(2)_SUBDIR)
  55. $(2)_BUILDDIR = $$($(2)_SRCDIR)
  56. #
  57. # Configure step. Only define it if not already defined by the package
  58. # .mk file. And take care of the differences between host and target
  59. # packages.
  60. #
  61. ifndef $(2)_CONFIGURE_CMDS
  62. ifeq ($(5),target)
  63. # Configure package for target
  64. define $(2)_CONFIGURE_CMDS
  65. (cd $$($$(PKG)_BUILDDIR) && \
  66. rm -f CMakeCache.txt && \
  67. $$($$(PKG)_CONF_ENV) $(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
  68. -DCMAKE_TOOLCHAIN_FILE="$$(BASE_DIR)/toolchainfile.cmake" \
  69. -DCMAKE_INSTALL_PREFIX="/usr" \
  70. $$($$(PKG)_CONF_OPT) \
  71. )
  72. endef
  73. else
  74. # Configure package for host
  75. define $(2)_CONFIGURE_CMDS
  76. (cd $$($$(PKG)_BUILDDIR) && \
  77. rm -f CMakeCache.txt && \
  78. $(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
  79. -DCMAKE_INSTALL_SO_NO_EXE=0 \
  80. -DCMAKE_FIND_ROOT_PATH="$$(HOST_DIR)" \
  81. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="BOTH" \
  82. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
  83. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
  84. -DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
  85. $$($$(PKG)_CONF_OPT) \
  86. )
  87. endef
  88. endif
  89. endif
  90. $(2)_DEPENDENCIES += host-cmake
  91. #
  92. # Build step. Only define it if not already defined by the package .mk
  93. # file.
  94. #
  95. ifndef $(2)_BUILD_CMDS
  96. ifeq ($(5),target)
  97. define $(2)_BUILD_CMDS
  98. $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_BUILDDIR)
  99. endef
  100. else
  101. define $(2)_BUILD_CMDS
  102. $(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_BUILDDIR)
  103. endef
  104. endif
  105. endif
  106. #
  107. # Host installation step. Only define it if not already defined by the
  108. # package .mk file.
  109. #
  110. ifndef $(2)_INSTALL_CMDS
  111. define $(2)_INSTALL_CMDS
  112. $(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) $$($$(PKG)_INSTALL_HOST_OPT) -C $$($$(PKG)_BUILDDIR)
  113. endef
  114. endif
  115. #
  116. # Staging installation step. Only define it if not already defined by
  117. # the package .mk file.
  118. #
  119. ifndef $(2)_INSTALL_STAGING_CMDS
  120. define $(2)_INSTALL_STAGING_CMDS
  121. $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) $$($$(PKG)_INSTALL_STAGING_OPT) -C $$($$(PKG)_BUILDDIR)
  122. endef
  123. endif
  124. #
  125. # Target installation step. Only define it if not already defined by
  126. # the package .mk file.
  127. #
  128. ifndef $(2)_INSTALL_TARGET_CMDS
  129. define $(2)_INSTALL_TARGET_CMDS
  130. $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) $$($$(PKG)_INSTALL_TARGET_OPT) -C $$($$(PKG)_BUILDDIR)
  131. endef
  132. endif
  133. #
  134. # Clean step. Only define it if not already defined by
  135. # the package .mk file.
  136. #
  137. ifndef $(2)_CLEAN_CMDS
  138. define $(2)_CLEAN_CMDS
  139. -$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) $$($$(PKG)_CLEAN_OPT) -C $$($$(PKG)_BUILDDIR)
  140. endef
  141. endif
  142. #
  143. # Uninstall from staging step. Only define it if not already defined by
  144. # the package .mk file.
  145. #
  146. ifndef $(2)_UNINSTALL_STAGING_CMDS
  147. define $(2)_UNINSTALL_STAGING_CMDS
  148. (cd $$($$(PKG)_BUILDDIR) && sed "s:\(.*\):$$(STAGING_DIR)\1:" install_manifest.txt | xargs rm -f)
  149. endef
  150. endif
  151. #
  152. # Uninstall from target step. Only define it if not already defined
  153. # by the package .mk file.
  154. #
  155. ifndef $(2)_UNINSTALL_TARGET_CMDS
  156. define $(2)_UNINSTALL_TARGET_CMDS
  157. (cd $$($$(PKG)_BUILDDIR) && sed "s:\(.*\):$$(TARGET_DIR)\1:" install_manifest.txt | xargs rm -f)
  158. endef
  159. endif
  160. # Call the generic package infrastructure to generate the necessary
  161. # make targets
  162. $(call GENTARGETS_INNER,$(1),$(2),$(3),$(4),$(5))
  163. endef
  164. ################################################################################
  165. # CMAKETARGETS -- the target generator macro for CMake packages
  166. #
  167. # Argument 1 is the package directory prefix [mandatory]
  168. # Argument 2 is the lowercase package name [mandatory]
  169. # Argument 3 is "target" or "host" [optional, default: "target"]
  170. ################################################################################
  171. define CMAKETARGETS
  172. ifeq ($(3),host)
  173. $(call CMAKETARGETS_INNER,$(3)-$(2),$(call UPPERCASE,$(3)-$(2)),$(call UPPERCASE,$(2)),$(1),host)
  174. else
  175. $(call CMAKETARGETS_INNER,$(2),$(call UPPERCASE,$(2)),$(call UPPERCASE,$(2)),$(1),target)
  176. endif
  177. endef