luaposix: bump to version 31
[buildroot-gz.git] / package / pkg-cmake.mk
blob0e0872260d02772f4644d3be76d0905897d6e51c
1 ################################################################################
2 # CMake package infrastructure
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.
8 # See the Buildroot documentation for details on the usage of this
9 # infrastructure
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.
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.
21 ################################################################################
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
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 package directory prefix
35 # argument 5 is the type (target or host)
36 ################################################################################
38 define inner-cmake-package
40 $(2)_CONF_ENV ?=
41 $(2)_CONF_OPT ?=
42 $(2)_MAKE ?= $(MAKE)
43 $(2)_MAKE_ENV ?=
44 $(2)_MAKE_OPT ?=
45 $(2)_INSTALL_HOST_OPT ?= install
46 $(2)_INSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) install
47 $(2)_INSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) install
48 $(2)_CLEAN_OPT ?= clean
50 $(2)_SRCDIR = $$($(2)_DIR)/$($(2)_SUBDIR)
51 $(2)_BUILDDIR = $$($(2)_SRCDIR)
54 # Configure step. Only define it if not already defined by the package
55 # .mk file. And take care of the differences between host and target
56 # packages.
58 ifndef $(2)_CONFIGURE_CMDS
59 ifeq ($(5),target)
61 # Configure package for target
62 define $(2)_CONFIGURE_CMDS
63 (cd $$($$(PKG)_BUILDDIR) && \
64 rm -f CMakeCache.txt && \
65 $$($$(PKG)_CONF_ENV) $(HOST_DIR)/usr/bin/cmake $$($$(PKG)_SRCDIR) \
66 -DCMAKE_TOOLCHAIN_FILE="$$(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake" \
67 -DCMAKE_INSTALL_PREFIX="/usr" \
68 $$($$(PKG)_CONF_OPT) \
70 endef
71 else
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) \
86 endef
87 endif
88 endif
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))))
94 $(2)_DEPENDENCIES += host-cmake
97 # Build step. Only define it if not already defined by the package .mk
98 # file.
100 ifndef $(2)_BUILD_CMDS
101 ifeq ($(5),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
113 # Host installation step. Only define it if not already defined by the
114 # package .mk file.
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
123 # Staging installation step. Only define it if not already defined by
124 # the package .mk file.
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
133 # Target installation step. Only define it if not already defined by
134 # the package .mk file.
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
143 # Clean step. Only define it if not already defined by
144 # the package .mk file.
146 ifndef $(2)_CLEAN_CMDS
147 define $(2)_CLEAN_CMDS
148 -$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) $$($$(PKG)_CLEAN_OPT) -C $$($$(PKG)_BUILDDIR)
149 endef
150 endif
153 # Uninstall from staging step. Only define it if not already defined by
154 # the package .mk file.
156 ifndef $(2)_UNINSTALL_STAGING_CMDS
157 define $(2)_UNINSTALL_STAGING_CMDS
158 (cd $$($$(PKG)_BUILDDIR) && sed "s:\(.*\):$$(STAGING_DIR)\1:" install_manifest.txt | xargs rm -f)
159 endef
160 endif
163 # Uninstall from target step. Only define it if not already defined
164 # by the package .mk file.
166 ifndef $(2)_UNINSTALL_TARGET_CMDS
167 define $(2)_UNINSTALL_TARGET_CMDS
168 (cd $$($$(PKG)_BUILDDIR) && sed "s:\(.*\):$$(TARGET_DIR)\1:" install_manifest.txt | xargs rm -f)
169 endef
170 endif
172 # Call the generic package infrastructure to generate the necessary
173 # make targets
174 $(call inner-generic-package,$(1),$(2),$(3),$(4),$(5))
176 endef
178 ################################################################################
179 # cmake-package -- the target generator macro for CMake packages
180 ################################################################################
182 cmake-package = $(call inner-cmake-package,$(call pkgname),$(call UPPERCASE,$(call pkgname)),$(call UPPERCASE,$(call pkgname)),$(call pkgparentdir),target)
183 host-cmake-package = $(call inner-cmake-package,host-$(call pkgname),$(call UPPERCASE,host-$(call pkgname)),$(call UPPERCASE,$(call pkgname)),$(call pkgparentdir),host)
185 ################################################################################
186 # Generation of the CMake toolchain file
187 ################################################################################
189 $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
190 @mkdir -p $(@D)
191 @echo -en "\
192 set(CMAKE_SYSTEM_NAME Linux)\n\
193 set(CMAKE_C_COMPILER $(TARGET_CC_NOCCACHE))\n\
194 set(CMAKE_CXX_COMPILER $(TARGET_CXX_NOCCACHE))\n\
195 set(CMAKE_C_FLAGS \"\$${CMAKE_C_FLAGS} $(TARGET_CFLAGS)\" CACHE STRING \"Buildroot CFLAGS\" FORCE)\n\
196 set(CMAKE_CXX_FLAGS \"\$${CMAKE_CXX_FLAGS} $(TARGET_CXXFLAGS)\" CACHE STRING \"Buildroot CXXFLAGS\" FORCE)\n\
197 set(CMAKE_INSTALL_SO_NO_EXE 0)\n\
198 set(CMAKE_PROGRAM_PATH \"$(HOST_DIR)/usr/bin\")\n\
199 set(CMAKE_FIND_ROOT_PATH \"$(STAGING_DIR)\")\n\
200 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n\
201 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\n\
202 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\n\
203 set(ENV{PKG_CONFIG_SYSROOT_DIR} \"$(STAGING_DIR)\")\n\
204 " > $@