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
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
32 # argument 3 is the uppercase package name, without the HOST_ prefix
34 # argument 4 is the type (target or host)
35 ################################################################################
37 define inner-cmake-package
44 $(2)_INSTALL_HOST_OPT ?= install
45 $(2)_INSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) install
46 $(2)_INSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) install
48 $(2)_SRCDIR = $$($(2)_DIR)/$($(2)_SUBDIR)
49 $(2)_BUILDDIR = $$($(2)_SRCDIR)
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
56 ifndef $(2)_CONFIGURE_CMDS
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) \
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) \
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
100 ifndef $(2)_BUILD_CMDS
102 define $(2)_BUILD_CMDS
103 $(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_BUILDDIR)
106 define $(2)_BUILD_CMDS
107 $(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPT) -C $$($$(PKG)_BUILDDIR)
113 # Host installation step. Only define it if not already defined by the
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)
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)
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)
142 # Call the generic package infrastructure to generate the necessary
144 $(call inner-generic-package,$(1),$(2),$(3),$(4))
148 ################################################################################
149 # cmake-package -- the target generator macro for CMake packages
150 ################################################################################
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)
155 ################################################################################
156 # Generation of the CMake toolchain file
157 ################################################################################
159 $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
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\