build: fix CMake assembly builds with ccache
[openwrt/staging/chunkeey.git] / include / cmake.mk
1 PKG_INSTALL:=1
2
3 ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
4 MAKE_FLAGS+=VERBOSE=1
5 endif
6
7 CMAKE_SOURCE_DIR:=.
8
9 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
10 cmake_tool=$(TOOLCHAIN_DIR)/bin/$(1)
11 else
12 cmake_tool=$(shell which $(1))
13 endif
14
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 else
21 CCACHE:=$(shell which ccache)
22 ifeq ($(CCACHE),)
23 CCACHE:=$(STAGING_DIR_HOST)/bin/ccache
24 endif
25 CMAKE_C_COMPILER:=$(CCACHE)
26 CMAKE_C_COMPILER_ARG1:=$(TARGET_CC_NOCACHE)
27 CMAKE_CXX_COMPILER:=$(CCACHE)
28 CMAKE_CXX_COMPILER_ARG1:=$(TARGET_CXX_NOCACHE)
29 endif
30 CMAKE_AR:=$(call cmake_tool,$(TARGET_AR))
31 CMAKE_NM:=$(call cmake_tool,$(TARGET_NM))
32 CMAKE_RANLIB:=$(call cmake_tool,$(TARGET_RANLIB))
33
34 CMAKE_FIND_ROOT_PATH:=$(STAGING_DIR);$(TOOLCHAIN_DIR)$(if $(CONFIG_EXTERNAL_TOOLCHAIN),;$(CONFIG_TOOLCHAIN_ROOT))
35
36 define Build/Configure/Default
37 (cd $(PKG_BUILD_DIR); \
38 CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
39 CXXFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
40 LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS)" \
41 cmake \
42 -DCMAKE_SYSTEM_NAME=Linux \
43 -DCMAKE_SYSTEM_VERSION=1 \
44 -DCMAKE_SYSTEM_PROCESSOR=$(ARCH) \
45 -DCMAKE_BUILD_TYPE=Release \
46 -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
47 -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
48 -DCMAKE_C_COMPILER="$(CMAKE_C_COMPILER)" \
49 -DCMAKE_C_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
50 -DCMAKE_CXX_COMPILER="$(CMAKE_CXX_COMPILER)" \
51 -DCMAKE_CXX_COMPILER_ARG1="$(CMAKE_CXX_COMPILER_ARG1)" \
52 -DCMAKE_ASM_COMPILER="$(CMAKE_C_COMPILER)" \
53 -DCMAKE_ASM_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
54 -DCMAKE_EXE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
55 -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
56 -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
57 -DCMAKE_AR="$(CMAKE_AR)" \
58 -DCMAKE_NM="$(CMAKE_NM)" \
59 -DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
60 -DCMAKE_FIND_ROOT_PATH="$(CMAKE_FIND_ROOT_PATH)" \
61 -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
62 -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
63 -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
64 -DCMAKE_STRIP=: \
65 -DCMAKE_INSTALL_PREFIX=/usr \
66 -DDL_LIBRARY=$(STAGING_DIR) \
67 -DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
68 -DCMAKE_SKIP_RPATH=TRUE \
69 $(CMAKE_OPTIONS) \
70 $(CMAKE_SOURCE_DIR) \
71 )
72 endef
73
74 define Build/InstallDev/cmake
75 $(INSTALL_DIR) $(1)
76 $(CP) $(PKG_INSTALL_DIR)/* $(1)/
77 endef
78
79 Build/InstallDev = $(if $(CMAKE_INSTALL),$(Build/InstallDev/cmake))