cmake.mk 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. PKG_INSTALL:=1
  2. ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
  3. MAKE_FLAGS+=VERBOSE=1
  4. endif
  5. CMAKE_SOURCE_DIR:=.
  6. ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
  7. cmake_tool=$(TOOLCHAIN_DIR)/bin/$(1)
  8. else
  9. cmake_tool=$(shell which $(1))
  10. endif
  11. ifeq ($(CONFIG_CCACHE),)
  12. CMAKE_C_COMPILER:=$(call cmake_tool,$(TARGET_CC))
  13. CMAKE_CXX_COMPILER:=$(call cmake_tool,$(TARGET_CXX))
  14. CMAKE_C_COMPILER_ARG1:=
  15. CMAKE_CXX_COMPILER_ARG1:=
  16. else
  17. CCACHE:=$(shell which ccache)
  18. ifeq ($(CCACHE),)
  19. CCACHE:=$(STAGING_DIR_HOST)/bin/ccache
  20. endif
  21. CMAKE_C_COMPILER:=$(CCACHE)
  22. CMAKE_C_COMPILER_ARG1:=$(TARGET_CC_NOCACHE)
  23. CMAKE_CXX_COMPILER:=$(CCACHE)
  24. CMAKE_CXX_COMPILER_ARG1:=$(TARGET_CXX_NOCACHE)
  25. endif
  26. CMAKE_AR:=$(call cmake_tool,$(TARGET_AR))
  27. CMAKE_NM:=$(call cmake_tool,$(TARGET_NM))
  28. CMAKE_RANLIB:=$(call cmake_tool,$(TARGET_RANLIB))
  29. CMAKE_FIND_ROOT_PATH:=$(STAGING_DIR);$(TOOLCHAIN_DIR)$(if $(CONFIG_EXTERNAL_TOOLCHAIN),;$(CONFIG_TOOLCHAIN_ROOT))
  30. CMAKE_HOST_FIND_ROOT_PATH:=$(STAGING_DIR_HOST)
  31. CMAKE_SHARED_LDFLAGS:=-Wl,-Bsymbolic-functions
  32. define Build/Configure/Default
  33. (cd $(PKG_BUILD_DIR); \
  34. CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
  35. CXXFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
  36. LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS)" \
  37. cmake \
  38. -DCMAKE_SYSTEM_NAME=Linux \
  39. -DCMAKE_SYSTEM_VERSION=1 \
  40. -DCMAKE_SYSTEM_PROCESSOR=$(ARCH) \
  41. -DCMAKE_BUILD_TYPE=Release \
  42. -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
  43. -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
  44. -DCMAKE_C_COMPILER="$(CMAKE_C_COMPILER)" \
  45. -DCMAKE_C_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
  46. -DCMAKE_CXX_COMPILER="$(CMAKE_CXX_COMPILER)" \
  47. -DCMAKE_CXX_COMPILER_ARG1="$(CMAKE_CXX_COMPILER_ARG1)" \
  48. -DCMAKE_ASM_COMPILER="$(CMAKE_C_COMPILER)" \
  49. -DCMAKE_ASM_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
  50. -DCMAKE_EXE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
  51. -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS) $(CMAKE_SHARED_LDFLAGS)" \
  52. -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS) $(CMAKE_SHARED_LDFLAGS)" \
  53. -DCMAKE_AR="$(CMAKE_AR)" \
  54. -DCMAKE_NM="$(CMAKE_NM)" \
  55. -DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
  56. -DCMAKE_FIND_ROOT_PATH="$(CMAKE_FIND_ROOT_PATH)" \
  57. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
  58. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  59. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  60. -DCMAKE_STRIP=: \
  61. -DCMAKE_INSTALL_PREFIX=/usr \
  62. -DDL_LIBRARY=$(STAGING_DIR) \
  63. -DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
  64. -DCMAKE_SKIP_RPATH=TRUE \
  65. $(CMAKE_OPTIONS) \
  66. $(CMAKE_SOURCE_DIR) \
  67. )
  68. endef
  69. define Build/InstallDev/cmake
  70. $(INSTALL_DIR) $(1)
  71. $(CP) $(PKG_INSTALL_DIR)/* $(1)/
  72. endef
  73. Build/InstallDev = $(if $(CMAKE_INSTALL),$(Build/InstallDev/cmake))
  74. define Host/Configure/Default
  75. (cd $(HOST_BUILD_DIR); \
  76. CFLAGS="$(HOST_CFLAGS)" \
  77. CXXFLAGS="$(HOST_CFLAGS)" \
  78. LDFLAGS="$(HOST_LDFLAGS)" \
  79. cmake \
  80. -DCMAKE_BUILD_TYPE=Release \
  81. -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
  82. -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
  83. -DCMAKE_EXE_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  84. -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  85. -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
  86. -DCMAKE_FIND_ROOT_PATH="$(CMAKE_HOST_FIND_ROOT_PATH)" \
  87. -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
  88. -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
  89. -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
  90. -DCMAKE_STRIP=: \
  91. -DCMAKE_INSTALL_PREFIX=$(STAGING_DIR_HOST) \
  92. -DCMAKE_PREFIX_PATH=$(STAGING_DIR_HOST) \
  93. -DCMAKE_SKIP_RPATH=TRUE \
  94. $(CMAKE_HOST_OPTIONS) \
  95. $(CMAKE_SOURCE_DIR) \
  96. )
  97. endef