build: add FIXUP option for make check
[oweals/openwrt.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_BINARY_DIR = $(PKG_BUILD_DIR)$(if $(CMAKE_BINARY_SUBDIR),/$(CMAKE_BINARY_SUBDIR))
10 CMAKE_SOURCE_DIR = $(PKG_BUILD_DIR)
11 HOST_CMAKE_SOURCE_DIR = $(HOST_BUILD_DIR)
12 MAKE_PATH = $(firstword $(CMAKE_BINARY_SUBDIR) .)
13
14 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
15   cmake_tool=$(TOOLCHAIN_DIR)/bin/$(1)
16 else
17   cmake_tool=$(shell which $(1))
18 endif
19
20 ifeq ($(CONFIG_CCACHE),)
21  CMAKE_C_COMPILER:=$(call cmake_tool,$(TARGET_CC))
22  CMAKE_CXX_COMPILER:=$(call cmake_tool,$(TARGET_CXX))
23  CMAKE_C_COMPILER_ARG1:=
24  CMAKE_CXX_COMPILER_ARG1:=
25 else
26   CCACHE:=$(STAGING_DIR_HOST)/bin/ccache
27   CMAKE_C_COMPILER:=$(CCACHE)
28   CMAKE_C_COMPILER_ARG1:=$(TARGET_CC_NOCACHE)
29   CMAKE_CXX_COMPILER:=$(CCACHE)
30   CMAKE_CXX_COMPILER_ARG1:=$(TARGET_CXX_NOCACHE)
31 endif
32 CMAKE_AR:=$(call cmake_tool,$(TARGET_AR))
33 CMAKE_NM:=$(call cmake_tool,$(TARGET_NM))
34 CMAKE_RANLIB:=$(call cmake_tool,$(TARGET_RANLIB))
35
36 CMAKE_FIND_ROOT_PATH:=$(STAGING_DIR)/usr;$(TOOLCHAIN_DIR)$(if $(CONFIG_EXTERNAL_TOOLCHAIN),;$(CONFIG_TOOLCHAIN_ROOT))
37 CMAKE_HOST_FIND_ROOT_PATH:=$(STAGING_DIR)/host;$(STAGING_DIR_HOST)
38 CMAKE_SHARED_LDFLAGS:=-Wl,-Bsymbolic-functions
39
40 define Build/Configure/Default
41         mkdir -p $(CMAKE_BINARY_DIR)
42         (cd $(CMAKE_BINARY_DIR); \
43                 CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)" \
44                 CXXFLAGS="$(TARGET_CXXFLAGS) $(EXTRA_CXXFLAGS)" \
45                 LDFLAGS="$(TARGET_LDFLAGS) $(EXTRA_LDFLAGS)" \
46                 cmake \
47                         -DCMAKE_SYSTEM_NAME=Linux \
48                         -DCMAKE_SYSTEM_VERSION=1 \
49                         -DCMAKE_SYSTEM_PROCESSOR=$(ARCH) \
50                         -DCMAKE_BUILD_TYPE=Release \
51                         -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
52                         -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
53                         -DCMAKE_C_COMPILER="$(CMAKE_C_COMPILER)" \
54                         -DCMAKE_C_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
55                         -DCMAKE_CXX_COMPILER="$(CMAKE_CXX_COMPILER)" \
56                         -DCMAKE_CXX_COMPILER_ARG1="$(CMAKE_CXX_COMPILER_ARG1)" \
57                         -DCMAKE_ASM_COMPILER="$(CMAKE_C_COMPILER)" \
58                         -DCMAKE_ASM_COMPILER_ARG1="$(CMAKE_C_COMPILER_ARG1)" \
59                         -DCMAKE_EXE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
60                         -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS) $(CMAKE_SHARED_LDFLAGS)" \
61                         -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS) $(CMAKE_SHARED_LDFLAGS)" \
62                         -DCMAKE_AR="$(CMAKE_AR)" \
63                         -DCMAKE_NM="$(CMAKE_NM)" \
64                         -DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
65                         -DCMAKE_FIND_ROOT_PATH="$(CMAKE_FIND_ROOT_PATH)" \
66                         -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
67                         -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
68                         -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
69                         -DCMAKE_STRIP=: \
70                         -DCMAKE_INSTALL_PREFIX=/usr \
71                         -DDL_LIBRARY=$(STAGING_DIR) \
72                         -DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
73                         -DCMAKE_SKIP_RPATH=TRUE  \
74                         $(CMAKE_OPTIONS) \
75                 $(CMAKE_SOURCE_DIR) \
76         )
77 endef
78
79 define Build/InstallDev/cmake
80         $(INSTALL_DIR) $(1)
81         $(CP) $(PKG_INSTALL_DIR)/* $(1)/
82 endef
83
84 Build/InstallDev = $(if $(CMAKE_INSTALL),$(Build/InstallDev/cmake))
85
86 define Host/Configure/Default
87         (cd $(HOST_BUILD_DIR); \
88                 CFLAGS="$(HOST_CFLAGS)" \
89                 CXXFLAGS="$(HOST_CFLAGS)" \
90                 LDFLAGS="$(HOST_LDFLAGS)" \
91                 cmake \
92                         -DCMAKE_BUILD_TYPE=Release \
93                         -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \
94                         -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" \
95                         -DCMAKE_EXE_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
96                         -DCMAKE_MODULE_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
97                         -DCMAKE_SHARED_LINKER_FLAGS:STRING="$(HOST_LDFLAGS)" \
98                         -DCMAKE_FIND_ROOT_PATH="$(CMAKE_HOST_FIND_ROOT_PATH)" \
99                         -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
100                         -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
101                         -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
102                         -DCMAKE_STRIP=: \
103                         -DCMAKE_INSTALL_PREFIX=$(HOST_BUILD_PREFIX) \
104                         -DCMAKE_PREFIX_PATH=$(HOST_BUILD_PREFIX) \
105                         -DCMAKE_SKIP_RPATH=TRUE  \
106                         $(CMAKE_HOST_OPTIONS) \
107                 $(HOST_CMAKE_SOURCE_DIR) \
108         )
109 endef