cmake.mk 3.4 KB

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