]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - package/pkg-cmake.mk
infra: remove unused 4th parameter to package infrastructures (pkgparentdir)
[coffee/buildroot.git] / package / pkg-cmake.mk
1 ################################################################################
2 # CMake package infrastructure
3 #
4 # This file implements an infrastructure that eases development of
5 # package .mk files for CMake packages. It should be used for all
6 # packages that use CMake as their build system.
7 #
8 # See the Buildroot documentation for details on the usage of this
9 # infrastructure
10 #
11 # In terms of implementation, this CMake infrastructure requires
12 # the .mk file to only specify metadata informations about the
13 # package: name, version, download URL, etc.
14 #
15 # We still allow the package .mk file to override what the different
16 # steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
17 # already defined, it is used as the list of commands to perform to
18 # build the package, instead of the default CMake behaviour. The
19 # package can also define some post operation hooks.
20 #
21 ################################################################################
22
23 ################################################################################
24 # inner-cmake-package -- defines how the configuration, compilation and
25 # installation of a CMake package should be done, implements a few hooks to
26 # tune the build process and calls the generic package infrastructure to
27 # generate the necessary make targets
28 #
29 #  argument 1 is the lowercase package name
30 #  argument 2 is the uppercase package name, including an HOST_ prefix
31 #             for host packages
32 #  argument 3 is the uppercase package name, without the HOST_ prefix
33 #             for host packages
34 #  argument 4 is the type (target or host)
35 ################################################################################
36
37 define inner-cmake-package
38
39 $(2)_CONF_ENV                   ?=
40 $(2)_CONF_OPT                   ?=
41 $(2)_MAKE                       ?= $(MAKE)
42 $(2)_MAKE_ENV                   ?=
43 $(2)_MAKE_OPT                   ?=
44 $(2)_INSTALL_HOST_OPT           ?= install
45 $(2)_INSTALL_STAGING_OPT        ?= DESTDIR=$$(STAGING_DIR) install
46 $(2)_INSTALL_TARGET_OPT         ?= DESTDIR=$$(TARGET_DIR) install
47
48 $(2)_SRCDIR                     = $$($(2)_DIR)/$($(2)_SUBDIR)
49 $(2)_BUILDDIR                   = $$($(2)_SRCDIR)
50
51 #
52 # Configure step. Only define it if not already defined by the package
53 # .mk file. And take care of the differences between host and target
54 # packages.
55 #
56 ifndef $(2)_CONFIGURE_CMDS
57 ifeq ($(4),target)
58
59 # Configure package for target
60 define $(2)_CONFIGURE_CMDS
61         (cd $$($$(PKG)_BUILDDIR) && \
62         rm -f CMakeCache.txt && \
63         $$($$(PKG)_CONF_ENV) $(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
64                 -DCMAKE_TOOLCHAIN_FILE="$$(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake" \
65                 -DCMAKE_INSTALL_PREFIX="/usr" \
66                 -DCMAKE_COLOR_MAKEFILE=OFF \
67                 -DBUILD_SHARED_LIBS=$(if $(BR2_PREFER_STATIC_LIB),OFF,ON) \
68                 $$($$(PKG)_CONF_OPT) \
69         )
70 endef
71 else
72
73 # Configure package for host
74 define $(2)_CONFIGURE_CMDS
75         (cd $$($$(PKG)_BUILDDIR) && \
76         rm -f CMakeCache.txt && \
77         $(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
78                 -DCMAKE_INSTALL_SO_NO_EXE=0 \
79                 -DCMAKE_FIND_ROOT_PATH="$$(HOST_DIR)" \
80                 -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="BOTH" \
81                 -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
82                 -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
83                 -DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
84                 $$($$(PKG)_CONF_OPT) \
85         )
86 endef
87 endif
88 endif
89
90 # This must be repeated from inner-generic-package, otherwise we only get
91 # host-cmake in _DEPENDENCIES because of the following line
92 $(2)_DEPENDENCIES ?= $(filter-out $(1),$(patsubst host-host-%,host-%,$(addprefix host-,$($(3)_DEPENDENCIES))))
93
94 $(2)_DEPENDENCIES += host-cmake
95
96 #
97 # Build step. Only define it if not already defined by the package .mk
98 # file.
99 #
100 ifndef $(2)_BUILD_CMDS
101 ifeq ($(4),target)
102 define $(2)_BUILD_CMDS
103         $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_BUILDDIR)
104 endef
105 else
106 define $(2)_BUILD_CMDS
107         $(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_BUILDDIR)
108 endef
109 endif
110 endif
111
112 #
113 # Host installation step. Only define it if not already defined by the
114 # package .mk file.
115 #
116 ifndef $(2)_INSTALL_CMDS
117 define $(2)_INSTALL_CMDS
118         $(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) $$($$(PKG)_INSTALL_HOST_OPT) -C $$($$(PKG)_BUILDDIR)
119 endef
120 endif
121
122 #
123 # Staging installation step. Only define it if not already defined by
124 # the package .mk file.
125 #
126 ifndef $(2)_INSTALL_STAGING_CMDS
127 define $(2)_INSTALL_STAGING_CMDS
128         $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) $$($$(PKG)_INSTALL_STAGING_OPT) -C $$($$(PKG)_BUILDDIR)
129 endef
130 endif
131
132 #
133 # Target installation step. Only define it if not already defined by
134 # the package .mk file.
135 #
136 ifndef $(2)_INSTALL_TARGET_CMDS
137 define $(2)_INSTALL_TARGET_CMDS
138         $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) $$($$(PKG)_INSTALL_TARGET_OPT) -C $$($$(PKG)_BUILDDIR)
139 endef
140 endif
141
142 # Call the generic package infrastructure to generate the necessary
143 # make targets
144 $(call inner-generic-package,$(1),$(2),$(3),$(4))
145
146 endef
147
148 ################################################################################
149 # cmake-package -- the target generator macro for CMake packages
150 ################################################################################
151
152 cmake-package = $(call inner-cmake-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
153 host-cmake-package = $(call inner-cmake-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
154
155 ################################################################################
156 # Generation of the CMake toolchain file
157 ################################################################################
158
159 $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
160         @mkdir -p $(@D)
161         @echo -en "\
162         set(CMAKE_SYSTEM_NAME Linux)\n\
163         set(CMAKE_C_COMPILER $(TARGET_CC_NOCCACHE))\n\
164         set(CMAKE_CXX_COMPILER $(TARGET_CXX_NOCCACHE))\n\
165         set(CMAKE_C_FLAGS \"\$${CMAKE_C_FLAGS} $(TARGET_CFLAGS)\" CACHE STRING \"Buildroot CFLAGS\" FORCE)\n\
166         set(CMAKE_CXX_FLAGS \"\$${CMAKE_CXX_FLAGS} $(TARGET_CXXFLAGS)\" CACHE STRING \"Buildroot CXXFLAGS\" FORCE)\n\
167         set(CMAKE_INSTALL_SO_NO_EXE 0)\n\
168         set(CMAKE_PROGRAM_PATH \"$(HOST_DIR)/usr/bin\")\n\
169         set(CMAKE_FIND_ROOT_PATH \"$(STAGING_DIR)\")\n\
170         set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n\
171         set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\n\
172         set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\n\
173         set(ENV{PKG_CONFIG_SYSROOT_DIR} \"$(STAGING_DIR)\")\n\
174         " > $@