summaryrefslogtreecommitdiffstats
path: root/meta/classes/cmake.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/cmake.bbclass')
-rw-r--r--meta/classes/cmake.bbclass115
1 files changed, 115 insertions, 0 deletions
diff --git a/meta/classes/cmake.bbclass b/meta/classes/cmake.bbclass
new file mode 100644
index 0000000..c9c15f3
--- /dev/null
+++ b/meta/classes/cmake.bbclass
@@ -0,0 +1,115 @@
1DEPENDS_prepend = "cmake-native "
2B = "${WORKDIR}/build"
3
4# We need to unset CCACHE otherwise cmake gets too confused
5CCACHE = ""
6
7# We want the staging and installing functions from autotools
8inherit autotools
9
10# C/C++ Compiler (without cpu arch/tune arguments)
11OECMAKE_C_COMPILER ?= "`echo ${CC} | sed 's/^\([^ ]*\).*/\1/'`"
12OECMAKE_CXX_COMPILER ?= "`echo ${CXX} | sed 's/^\([^ ]*\).*/\1/'`"
13
14# Compiler flags
15OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CFLAGS}"
16OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} -fpermissive"
17OECMAKE_C_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} ${CFLAGS} -DNDEBUG"
18OECMAKE_CXX_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} ${CXXFLAGS} -DNDEBUG"
19OECMAKE_C_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CPPFLAGS} ${LDFLAGS}"
20OECMAKE_CXX_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} ${LDFLAGS}"
21
22OECMAKE_RPATH ?= ""
23OECMAKE_PERLNATIVE_DIR ??= ""
24OECMAKE_EXTRA_ROOT_PATH ?= ""
25
26cmake_do_generate_toolchain_file() {
27 cat > ${WORKDIR}/toolchain.cmake <<EOF
28# CMake system name must be something like "Linux".
29# This is important for cross-compiling.
30set( CMAKE_SYSTEM_NAME `echo ${TARGET_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` )
31set( CMAKE_SYSTEM_PROCESSOR ${TARGET_ARCH} )
32set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} )
33set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} )
34set( CMAKE_C_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "CFLAGS" )
35set( CMAKE_CXX_FLAGS "${OECMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" )
36set( CMAKE_C_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "CFLAGS for release" )
37set( CMAKE_CXX_FLAGS_RELEASE "${OECMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "CXXFLAGS for release" )
38set( CMAKE_C_LINK_FLAGS "${OECMAKE_C_LINK_FLAGS}" CACHE STRING "LDFLAGS" )
39set( CMAKE_CXX_LINK_FLAGS "${OECMAKE_CXX_LINK_FLAGS}" CACHE STRING "LDFLAGS" )
40
41# only search in the paths provided so cmake doesnt pick
42# up libraries and tools from the native build machine
43set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_HOST} ${STAGING_DIR_NATIVE} ${CROSS_DIR} ${OECMAKE_PERLNATIVE_DIR} ${OECMAKE_EXTRA_ROOT_PATH} ${EXTERNAL_TOOLCHAIN})
44set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
45set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
46set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
47set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
48
49# Use qt.conf settings
50set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf )
51
52# We need to set the rpath to the correct directory as cmake does not provide any
53# directory as rpath by default
54set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} )
55
56# Use native cmake modules
57set( CMAKE_MODULE_PATH ${STAGING_DATADIR}/cmake/Modules/ )
58
59# add for non /usr/lib libdir, e.g. /usr/lib64
60set( CMAKE_LIBRARY_PATH ${libdir} ${base_libdir})
61
62EOF
63}
64
65addtask generate_toolchain_file after do_patch before do_configure
66
67cmake_do_configure() {
68 if [ "${OECMAKE_BUILDPATH}" -o "${OECMAKE_SOURCEPATH}" ]; then
69 bbnote "cmake.bbclass no longer uses OECMAKE_SOURCEPATH and OECMAKE_BUILDPATH. The default behaviour is now out-of-tree builds with B=WORKDIR/build."
70 fi
71
72 if [ "${S}" != "${B}" ]; then
73 rm -rf ${B}
74 mkdir -p ${B}
75 cd ${B}
76 fi
77
78 # Just like autotools cmake can use a site file to cache result that need generated binaries to run
79 if [ -e ${WORKDIR}/site-file.cmake ] ; then
80 OECMAKE_SITEFILE=" -C ${WORKDIR}/site-file.cmake"
81 else
82 OECMAKE_SITEFILE=""
83 fi
84
85 cmake \
86 ${OECMAKE_SITEFILE} \
87 ${S} \
88 -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \
89 -DCMAKE_INSTALL_BINDIR:PATH=${bindir} \
90 -DCMAKE_INSTALL_SBINDIR:PATH=${sbindir} \
91 -DCMAKE_INSTALL_LIBEXECDIR:PATH=${libexecdir} \
92 -DCMAKE_INSTALL_SYSCONFDIR:PATH=${sysconfdir} \
93 -DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=${sharedstatedir} \
94 -DCMAKE_INSTALL_LOCALSTATEDIR:PATH=${localstatedir} \
95 -DCMAKE_INSTALL_LIBDIR:PATH=${libdir} \
96 -DCMAKE_INSTALL_INCLUDEDIR:PATH=${includedir} \
97 -DCMAKE_INSTALL_DATAROOTDIR:PATH=${datadir} \
98 -DCMAKE_INSTALL_SO_NO_EXE=0 \
99 -DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \
100 -DCMAKE_VERBOSE_MAKEFILE=1 \
101 ${EXTRA_OECMAKE} \
102 -Wno-dev
103}
104
105cmake_do_compile() {
106 cd ${B}
107 base_do_compile
108}
109
110cmake_do_install() {
111 cd ${B}
112 autotools_do_install
113}
114
115EXPORT_FUNCTIONS do_configure do_compile do_install do_generate_toolchain_file