This repository was archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcmake.mk
130 lines (96 loc) · 3.07 KB
/
cmake.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Link this file to projects root as Makefile:
# ln -s buildsys/cmake/cmake.mk Makefile
.DEFAULT_GOAL := all
# find out path to buildsys directory etc.
BUILDSYS := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
BUILDSYS_COMMON := $(BUILDSYS)../common/common.mk
ifneq ($(BUILDSYS_FLAVOR),)
BUILDDIR=build.$(BUILDSYS_FLAVOR)
else
BUILDDIR=build
endif
include $(BUILDSYS_COMMON)
CMAKE_SHARED_MODULE_SUPPORT ?= NO
BINARY_LINKS = bin lib
ifeq ($(CMAKE_SHARED_MODULE_SUPPORT),YES)
BINARY_LINKS += module
endif
BINARY_DIRS = $(foreach dir,${BINARY_LINKS}, $(BUILDDIR)/${dir})
# include configuration
include $(BUILDSYS)config.mk
all .DEFAULT: FORCE
# bootstrap if needed
$(call bootstrap)
# forward to build directory
@(unset MAKELEVEL; cd $(BUILDDIR) && $(MAKE) $@)
purge:
rm -rf $(BINARY_LINKS) $(BUILDDIR)
default debug release relwithdebinfo customerdebug customerrelease:
$(call bootstrap_dirs)
@echo "* Switching to ${BUILD_TYPE_$@} build type"
@(cd $(BUILDDIR) && cmake .. -DCMAKE_BUILD_TYPE:STRING=${BUILD_TYPE_$@})
native:
$(call bootstrap_dirs)
@echo "* Code will be compiled for current machine"
@(cd $(BUILDDIR) && cmake .. -DBUILDSYS_ARCHITECTURE:STRING=$@)
generic:
$(call bootstrap_dirs)
@echo "* Code will be compiled for generic machine"
@(cd $(BUILDDIR) && cmake .. -UBUILDSYS_ARCHITECTURE)
setarch:
$(call bootstrap_dirs)
@echo "* Switching architecture to $(ARCH)"
@(cd $(BUILDDIR) && cmake .. -DBUILDSYS_ARCHITECTURE:STRING=$(ARCH))
buildtype:
$(call bootstrap)
@echo "$(call get_cmake_variable,CMAKE_BUILD_TYPE)"
arch:
$(call bootstrap)
@echo "$(call get_cmake_variable,BUILDSYS_ARCHITECTURE)"
set-variable:
$(call bootstrap_dirs)
@(cd $(BUILDDIR) && cmake .. -D$(VARIABLE))
unset-variable:
$(call bootstrap_dirs)
@(cd $(BUILDDIR) && cmake .. -U$(VARIABLE))
enable:
$(call bootstrap_dirs)
@(cd $(BUILDDIR) && cmake .. -DBUILDSYS_BUILD_TARGET_$(TARGET)=TRUE)
disable:
$(call bootstrap_dirs)
@(cd $(BUILDDIR) && cmake .. -DBUILDSYS_BUILD_TARGET_$(TARGET)=FALSE)
configure:
cmake-gui $(BUILDDIR)
list-modules:
@(sort $(BUILDDIR)/module.list)
FORCE:
.PHONY: FORCE purge
.PHONY: buildtype default debug release relwithdebinfo
.PHONY: customerdebug customerrelease
.PHONY: arch native generic setarch
.PHONY: set-variable unset-variable enable disable
.PHONY: configure
.PHONY: list-modules
define bootstrap_dirs
@echo "* Building in $(BUILDDIR)"
@(mkdir -p $(BINARY_DIRS) $(foreach dir,${BINARY_DIRS}, && ln -sf $(dir)))
@((test -f .module && mkdir -p $(BUILDDIR)/module && ln -sf $(BUILDDIR)/module) || exit 0)
endef
define bootstrap
$(call bootstrap_dirs)
@test -f $(BUILDDIR)/Makefile || (cd $(BUILDDIR) && cmake ..)
endef
define get_cmake_variable
$(shell cmake -L $(BUILDDIR) | sed '/$(1)/ {s/.*=\(.*\)/\1/p; D; q}; D' \
| sed 's/^$$/<DEFAULT>/')
endef
# Missing include stuff handler
define BUILDSYS_COMMON_ERROR
missing include file
$(BUILDSYS_COMMON)
Please add buildsys-common project into your submodules under externals/buildsys/common
endef
$(BUILDSYS_COMMON):
$(error $(BUILDSYS_COMMON_ERROR))
local.mk:
-include local.mk