cmake.mk 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. cmake_bool = $(patsubst %,-D%:BOOL=$(if $($(1)),ON,OFF),$(2))
  2. PKG_INSTALL:=1
  3. ifneq ($(findstring c,$(LIBRECMC_VERBOSE)),)
  4. MAKE_FLAGS+=VERBOSE=1
  5. endif
  6. CMAKE_BINARY_DIR = $(PKG_BUILD_DIR)$(if $(CMAKE_BINARY_SUBDIR),/$(CMAKE_BINARY_SUBDIR))
  7. CMAKE_SOURCE_DIR = $(PKG_BUILD_DIR)$(if $(CMAKE_SOURCE_SUBDIR),/$(CMAKE_SOURCE_SUBDIR))
  8. HOST_CMAKE_SOURCE_DIR = $(HOST_BUILD_DIR)$(if $(CMAKE_SOURCE_SUBDIR),/$(CMAKE_SOURCE_SUBDIR))
  9. MAKE_PATH = $(firstword $(CMAKE_BINARY_SUBDIR) .)
  10. ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
  11. cmake_tool=$(TOOLCHAIN_DIR)/bin/$(1)
  12. else
  13. cmake_tool=$(shell which $(1))
  14. endif
  15. ifeq ($(CONFIG_CCACHE),)
  16. CMAKE_C_COMPILER:=$(call cmake_tool,$(TARGET_CC))
  17. CMAKE_CXX_COMPILER:=$(call cmake_tool,$(TARGET_CXX))
  18. CMAKE_C_COMPILER_ARG1:=
  19. CMAKE_CXX_COMPILER_ARG1:=
  20. CMAKE_HOST_C_COMPILER:=$(HOSTCC)
  21. CMAKE_HOST_CXX_COMPILER:=$(HOSTCXX)
  22. CMAKE_HOST_C_COMPILER_ARG1:=
  23. CMAKE_HOST_CXX_COMPILER_ARG1:=
  24. else
  25. CCACHE:=$(STAGING_DIR_HOST)/bin/ccache
  26. CMAKE_C_COMPILER:=$(CCACHE)
  27. CMAKE_C_COMPILER_ARG1:=$(TARGET_CC_NOCACHE)
  28. CMAKE_CXX_COMPILER:=$(CCACHE)
  29. CMAKE_CXX_COMPILER_ARG1:=$(TARGET_CXX_NOCACHE)
  30. CMAKE_HOST_C_COMPILER:=$(CCACHE)
  31. CMAKE_HOST_C_COMPILER_ARG1:=$(HOSTCC_NOCACHE)
  32. CMAKE_HOST_CXX_COMPILER:=$(CCACHE)
  33. CMAKE_HOST_CXX_COMPILER_ARG1:=$(HOSTCXX_NOCACHE)
  34. endif
  35. CMAKE_AR:=$(call cmake_tool,$(TARGET_AR))
  36. CMAKE_NM:=$(call cmake_tool,$(TARGET_NM))
  37. CMAKE_RANLIB:=$(call cmake_tool,$(TARGET_RANLIB))
  38. CMAKE_FIND_ROOT_PATH:=$(STAGING_DIR)/usr;$(TOOLCHAIN_DIR)$(if $(CONFIG_EXTERNAL_TOOLCHAIN),;$(CONFIG_TOOLCHAIN_ROOT))
  39. CMAKE_HOST_FIND_ROOT_PATH:=$(STAGING_DIR)/host;$(STAGING_DIR_HOSTPKG);$(STAGING_DIR_HOST)
  40. CMAKE_SHARED_LDFLAGS:=-Wl,-Bsymbolic-functions
  41. define Build/Configure/Default
  42. mkdir -p $(CMAKE_BINARY_DIR)
  43. (cd $(CMAKE_BINARY_DIR); \
  44. CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
  45. CXXFLAGS="$(TARGET_CXXFLAGS) $(EXTRA_CXXFLAGS)" \
  46. LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS)" \
  47. cmake \
  48. -DCMAKE_SYSTEM_NAME=Linux \
  49. -DCMAKE_SYSTEM_VERSION=1 \
  50. -DCMAKE_SYSTEM_PROCESSOR=$(ARCH) \
  51. -DCMAKE_BUILD_TYPE=Release \
  52. -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
  53. -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
  54. -DCMAKE_C_COMPILER="$(CMAKE_C_COMPILER)" \
  55. -DCMAKE_C_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
  56. -DCMAKE_CXX_COMPILER="$(CMAKE_CXX_COMPILER)" \
  57. -DCMAKE_CXX_COMPILER_ARG1="$(CMAKE_CXX_COMPILER_ARG1)" \
  58. -DCMAKE_ASM_COMPILER="$(CMAKE_C_COMPILER)" \
  59. -DCMAKE_ASM_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
  60. -DCMAKE_EXE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
  61. -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS) $(CMAKE_SHARED_LDFLAGS)" \
  62. -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS) $(CMAKE_SHARED_LDFLAGS)" \
  63. -DCMAKE_AR="$(CMAKE_AR)" \
  64. -DCMAKE_NM="$(CMAKE_NM)" \
  65. -DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
  66. -DCMAKE_FIND_ROOT_PATH="$(CMAKE_FIND_ROOT_PATH)" \
  67. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
  68. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  69. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  70. -DCMAKE_STRIP=: \
  71. -DCMAKE_INSTALL_PREFIX=/usr \
  72. -DDL_LIBRARY=$(STAGING_DIR) \
  73. -DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
  74. -DCMAKE_SKIP_RPATH=TRUE \
  75. $(CMAKE_OPTIONS) \
  76. $(CMAKE_SOURCE_DIR) \
  77. )
  78. endef
  79. define Build/InstallDev/cmake
  80. $(INSTALL_DIR) $(1)
  81. $(CP) $(PKG_INSTALL_DIR)/* $(1)/
  82. endef
  83. Build/InstallDev = $(if $(CMAKE_INSTALL),$(Build/InstallDev/cmake))
  84. define Host/Configure/Default
  85. (cd $(HOST_BUILD_DIR); \
  86. CFLAGS="$(HOST_CFLAGS)" \
  87. CXXFLAGS="$(HOST_CFLAGS)" \
  88. LDFLAGS="$(HOST_LDFLAGS)" \
  89. cmake \
  90. -DCMAKE_BUILD_TYPE=Release \
  91. -DCMAKE_C_COMPILER="$(CMAKE_HOST_C_COMPILER)" \
  92. -DCMAKE_C_COMPILER_ARG1="$(CMAKE_HOST_C_COMPILER_ARG1)" \
  93. -DCMAKE_CXX_COMPILER="$(CMAKE_HOST_CXX_COMPILER)" \
  94. -DCMAKE_CXX_COMPILER_ARG1="$(CMAKE_HOST_CXX_COMPILER_ARG1)" \
  95. -DCMAKE_ASM_COMPILER="$(CMAKE_HOST_C_COMPILER)" \
  96. -DCMAKE_ASM_COMPILER_ARG1="$(CMAKE_HOST_C_COMPILER_ARG1)" \
  97. -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
  98. -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
  99. -DCMAKE_EXE_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  100. -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  101. -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  102. -DCMAKE_FIND_ROOT_PATH="$(CMAKE_HOST_FIND_ROOT_PATH)" \
  103. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
  104. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  105. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  106. -DCMAKE_STRIP=: \
  107. -DCMAKE_INSTALL_PREFIX=$(HOST_BUILD_PREFIX) \
  108. -DCMAKE_PREFIX_PATH=$(HOST_BUILD_PREFIX) \
  109. -DCMAKE_SKIP_RPATH=TRUE \
  110. -DCMAKE_INSTALL_LIBDIR=lib \
  111. $(CMAKE_HOST_OPTIONS) \
  112. $(HOST_CMAKE_SOURCE_DIR) \
  113. )
  114. endef
  115. MAKE_FLAGS += \
  116. CMAKE_COMMAND='$$(if $$(CMAKE_DISABLE_$$@),:,$(STAGING_DIR_HOST)/bin/cmake)' \
  117. CMAKE_DISABLE_cmake_check_build_system=1