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