1
0

cmake.mk 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. cmake_bool = $(patsubst %,-D%:BOOL=$(if $($(1)),ON,OFF),$(2))
  2. PKG_USE_NINJA ?= 1
  3. HOST_USE_NINJA ?= 1
  4. ifeq ($(PKG_USE_NINJA),1)
  5. PKG_BUILD_PARALLEL ?= 1
  6. endif
  7. ifeq ($(HOST_USE_NINJA),1)
  8. HOST_BUILD_PARALLEL ?= 1
  9. endif
  10. PKG_INSTALL:=1
  11. ifneq ($(findstring c,$(LIBRECMC_VERBOSE)),)
  12. MAKE_FLAGS+=VERBOSE=1
  13. HOST_MAKE_FLAGS+=VERBOSE=1
  14. endif
  15. CMAKE_BINARY_DIR = $(PKG_BUILD_DIR)$(if $(CMAKE_BINARY_SUBDIR),/$(CMAKE_BINARY_SUBDIR))
  16. CMAKE_SOURCE_DIR = $(PKG_BUILD_DIR)$(if $(CMAKE_SOURCE_SUBDIR),/$(CMAKE_SOURCE_SUBDIR))
  17. HOST_CMAKE_SOURCE_DIR = $(HOST_BUILD_DIR)$(if $(CMAKE_SOURCE_SUBDIR),/$(CMAKE_SOURCE_SUBDIR))
  18. HOST_CMAKE_BINARY_DIR = $(HOST_BUILD_DIR)$(if $(CMAKE_BINARY_SUBDIR),/$(CMAKE_BINARY_SUBDIR))
  19. MAKE_PATH = $(firstword $(CMAKE_BINARY_SUBDIR) .)
  20. ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
  21. cmake_tool=$(TOOLCHAIN_DIR)/bin/$(1)
  22. else
  23. cmake_tool=$(shell command -v $(1))
  24. endif
  25. ifeq ($(CONFIG_CCACHE),)
  26. CMAKE_C_COMPILER_LAUNCHER:=
  27. CMAKE_CXX_COMPILER_LAUNCHER:=
  28. CMAKE_C_COMPILER:=$(call cmake_tool,$(TARGET_CC))
  29. CMAKE_CXX_COMPILER:=$(call cmake_tool,$(TARGET_CXX))
  30. CMAKE_HOST_C_COMPILER:=$(HOSTCC)
  31. CMAKE_HOST_CXX_COMPILER:=$(HOSTCXX)
  32. else
  33. CCACHE:=$(STAGING_DIR_HOST)/bin/ccache
  34. CMAKE_C_COMPILER_LAUNCHER:=$(CCACHE)
  35. CMAKE_CXX_COMPILER_LAUNCHER:=$(CCACHE)
  36. CMAKE_C_COMPILER:=$(TARGET_CC_NOCACHE)
  37. CMAKE_CXX_COMPILER:=$(TARGET_CXX_NOCACHE)
  38. CMAKE_HOST_C_COMPILER:=$(HOSTCC_NOCACHE)
  39. CMAKE_HOST_CXX_COMPILER:=$(HOSTCXX_NOCACHE)
  40. endif
  41. CMAKE_AR:=$(call cmake_tool,$(TARGET_AR))
  42. CMAKE_NM:=$(call cmake_tool,$(TARGET_NM))
  43. CMAKE_RANLIB:=$(call cmake_tool,$(TARGET_RANLIB))
  44. CMAKE_FIND_ROOT_PATH:=$(STAGING_DIR)/usr;$(TOOLCHAIN_DIR)$(if $(CONFIG_EXTERNAL_TOOLCHAIN),;$(CONFIG_TOOLCHAIN_ROOT))
  45. CMAKE_HOST_FIND_ROOT_PATH:=$(STAGING_DIR)/host;$(STAGING_DIR_HOSTPKG);$(STAGING_DIR_HOST)
  46. CMAKE_SHARED_LDFLAGS:=-Wl,-Bsymbolic-functions
  47. CMAKE_HOST_INSTALL_PREFIX = $(HOST_BUILD_PREFIX)
  48. ifeq ($(HOST_USE_NINJA),1)
  49. CMAKE_HOST_OPTIONS += -DCMAKE_GENERATOR="Ninja"
  50. define Host/Compile/Default
  51. +$(NINJA) -C $(HOST_CMAKE_BINARY_DIR) $(1)
  52. endef
  53. define Host/Install/Default
  54. +$(NINJA) -C $(HOST_CMAKE_BINARY_DIR) install
  55. endef
  56. define Host/Uninstall/Default
  57. +$(NINJA) -C $(HOST_CMAKE_BINARY_DIR) uninstall
  58. endef
  59. endif
  60. ifeq ($(PKG_USE_NINJA),1)
  61. CMAKE_OPTIONS += -DCMAKE_GENERATOR="Ninja"
  62. define Build/Compile/Default
  63. +$(NINJA) -C $(CMAKE_BINARY_DIR) $(1)
  64. endef
  65. define Build/Install/Default
  66. +DESTDIR="$(PKG_INSTALL_DIR)" $(NINJA) -C $(CMAKE_BINARY_DIR) install
  67. endef
  68. endif
  69. define Build/Configure/Default
  70. mkdir -p $(CMAKE_BINARY_DIR)
  71. (cd $(CMAKE_BINARY_DIR); \
  72. CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
  73. CXXFLAGS="$(TARGET_CXXFLAGS) $(EXTRA_CXXFLAGS)" \
  74. LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS)" \
  75. cmake \
  76. -DCMAKE_SYSTEM_NAME=Linux \
  77. -DCMAKE_SYSTEM_VERSION=1 \
  78. -DCMAKE_SYSTEM_PROCESSOR=$(ARCH) \
  79. -DCMAKE_BUILD_TYPE=Release \
  80. -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
  81. -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
  82. -DCMAKE_C_COMPILER_LAUNCHER="$(CMAKE_C_COMPILER_LAUNCHER)" \
  83. -DCMAKE_C_COMPILER="$(CMAKE_C_COMPILER)" \
  84. -DCMAKE_CXX_COMPILER_LAUNCHER="$(CMAKE_CXX_COMPILER_LAUNCHER)" \
  85. -DCMAKE_CXX_COMPILER="$(CMAKE_CXX_COMPILER)" \
  86. -DCMAKE_ASM_COMPILER_LAUNCHER="$(CMAKE_C_COMPILER_LAUNCHER)" \
  87. -DCMAKE_ASM_COMPILER="$(CMAKE_C_COMPILER)" \
  88. -DCMAKE_EXE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
  89. -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS) $(CMAKE_SHARED_LDFLAGS)" \
  90. -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS) $(CMAKE_SHARED_LDFLAGS)" \
  91. -DCMAKE_AR="$(CMAKE_AR)" \
  92. -DCMAKE_NM="$(CMAKE_NM)" \
  93. -DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
  94. -DCMAKE_FIND_ROOT_PATH="$(CMAKE_FIND_ROOT_PATH)" \
  95. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
  96. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  97. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  98. -DCMAKE_STRIP=: \
  99. -DCMAKE_INSTALL_PREFIX=/usr \
  100. -DDL_LIBRARY=$(STAGING_DIR) \
  101. -DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
  102. -DCMAKE_SKIP_RPATH=TRUE \
  103. -DCMAKE_EXPORT_PACKAGE_REGISTRY=FALSE \
  104. -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=TRUE \
  105. -DCMAKE_FIND_USE_PACKAGE_REGISTRY=FALSE \
  106. -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=TRUE \
  107. -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=FALSE \
  108. -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=TRUE \
  109. $(CMAKE_OPTIONS) \
  110. $(CMAKE_SOURCE_DIR) \
  111. )
  112. endef
  113. define Build/InstallDev/cmake
  114. $(INSTALL_DIR) $(1)
  115. $(CP) $(PKG_INSTALL_DIR)/* $(1)/
  116. endef
  117. Build/InstallDev = $(if $(CMAKE_INSTALL),$(Build/InstallDev/cmake))
  118. define Host/Configure/Default
  119. mkdir -p "$(HOST_CMAKE_BINARY_DIR)"
  120. (cd $(HOST_CMAKE_BINARY_DIR); \
  121. CFLAGS="$(HOST_CFLAGS)" \
  122. CXXFLAGS="$(HOST_CFLAGS)" \
  123. LDFLAGS="$(HOST_LDFLAGS)" \
  124. cmake \
  125. -DCMAKE_BUILD_TYPE=Release \
  126. -DCMAKE_C_COMPILER_LAUNCHER="$(CMAKE_C_COMPILER_LAUNCHER)" \
  127. -DCMAKE_C_COMPILER="$(CMAKE_HOST_C_COMPILER)" \
  128. -DCMAKE_CXX_COMPILER_LAUNCHER="$(CMAKE_CXX_COMPILER_LAUNCHER)" \
  129. -DCMAKE_CXX_COMPILER="$(CMAKE_HOST_CXX_COMPILER)" \
  130. -DCMAKE_ASM_COMPILER_LAUNCHER="$(CMAKE_C_COMPILER_LAUNCHER)" \
  131. -DCMAKE_ASM_COMPILER="$(CMAKE_HOST_C_COMPILER)" \
  132. -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
  133. -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
  134. -DCMAKE_EXE_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  135. -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  136. -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  137. -DCMAKE_FIND_ROOT_PATH="$(CMAKE_HOST_FIND_ROOT_PATH)" \
  138. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
  139. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  140. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  141. -DCMAKE_STRIP=: \
  142. -DCMAKE_INSTALL_PREFIX=$(CMAKE_HOST_INSTALL_PREFIX) \
  143. -DCMAKE_PREFIX_PATH=$(HOST_BUILD_PREFIX) \
  144. -DCMAKE_SKIP_RPATH=TRUE \
  145. -DCMAKE_INSTALL_LIBDIR=lib \
  146. -DCMAKE_EXPORT_PACKAGE_REGISTRY=FALSE \
  147. -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=TRUE \
  148. -DCMAKE_FIND_USE_PACKAGE_REGISTRY=FALSE \
  149. -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=TRUE \
  150. -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=FALSE \
  151. -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=TRUE \
  152. $(CMAKE_HOST_OPTIONS) \
  153. $(HOST_CMAKE_SOURCE_DIR) \
  154. )
  155. endef
  156. MAKE_FLAGS += \
  157. CMAKE_COMMAND='$$(if $$(CMAKE_DISABLE_$$@),:,$(STAGING_DIR_HOST)/bin/cmake)' \
  158. CMAKE_DISABLE_cmake_check_build_system=1