blob: ae3cc025e8ebd218b8868c70ea7ad3d4f8c91363 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Path to the CMake file to process.
2OECMAKE_SOURCEPATH ?= "${S}"
3
4DEPENDS_prepend = "cmake-native "
5B = "${WORKDIR}/build"
6
7# We need to unset CCACHE otherwise cmake gets too confused
8CCACHE = ""
9
10# We want the staging and installing functions from autotools
11inherit autotools
12
13# C/C++ Compiler (without cpu arch/tune arguments)
14OECMAKE_C_COMPILER ?= "`echo ${CC} | sed 's/^\([^ ]*\).*/\1/'`"
15OECMAKE_CXX_COMPILER ?= "`echo ${CXX} | sed 's/^\([^ ]*\).*/\1/'`"
16OECMAKE_AR ?= "${AR}"
17
18# Compiler flags
19OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CFLAGS}"
20OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS}"
21OECMAKE_C_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} ${CFLAGS} -DNDEBUG"
22OECMAKE_CXX_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} ${CXXFLAGS} -DNDEBUG"
23OECMAKE_C_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CPPFLAGS} ${LDFLAGS}"
24OECMAKE_CXX_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} ${LDFLAGS}"
25
26OECMAKE_RPATH ?= ""
27OECMAKE_PERLNATIVE_DIR ??= ""
28OECMAKE_EXTRA_ROOT_PATH ?= ""
29
30OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "ONLY"
31OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM_class-native = "BOTH"
32
33# CMake expects target architectures in the format of uname(2),
34# which do not always match TARGET_ARCH, so all the necessary
35# conversions should happen here.
36def map_target_arch_to_uname_arch(target_arch):
37 if target_arch == "powerpc":
38 return "ppc"
39 if target_arch == "powerpc64":
40 return "ppc64"
41 return target_arch
42
43cmake_do_generate_toolchain_file() {
44 cat > ${WORKDIR}/toolchain.cmake <<EOF
45# CMake system name must be something like "Linux".
46# This is important for cross-compiling.
47set( CMAKE_SYSTEM_NAME `echo ${TARGET_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` )
48set( CMAKE_SYSTEM_PROCESSOR ${@map_target_arch_to_uname_arch(d.getVar('TARGET_ARCH', True))} )
49set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} )
50set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} )
51set( CMAKE_ASM_COMPILER ${OECMAKE_C_COMPILER} )
52set( CMAKE_AR ${OECMAKE_AR} CACHE FILEPATH "Archiver" )
53set( CMAKE_C_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "CFLAGS" )
54set( CMAKE_CXX_FLAGS "${OECMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" )
55set( CMAKE_ASM_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "ASM FLAGS" )
56set( CMAKE_C_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "CFLAGS for release" )
57set( CMAKE_CXX_FLAGS_RELEASE "${OECMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "CXXFLAGS for release" )
58set( CMAKE_ASM_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "ASM FLAGS for release" )
59set( CMAKE_C_LINK_FLAGS "${OECMAKE_C_LINK_FLAGS}" CACHE STRING "LDFLAGS" )
60set( CMAKE_CXX_LINK_FLAGS "${OECMAKE_CXX_LINK_FLAGS}" CACHE STRING "LDFLAGS" )
61
62# only search in the paths provided so cmake doesnt pick
63# up libraries and tools from the native build machine
64set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_HOST} ${STAGING_DIR_NATIVE} ${CROSS_DIR} ${OECMAKE_PERLNATIVE_DIR} ${OECMAKE_EXTRA_ROOT_PATH} ${EXTERNAL_TOOLCHAIN})
65set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
66set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM} )
67set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
68set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
69
70# Use qt.conf settings
71set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf )
72
73# We need to set the rpath to the correct directory as cmake does not provide any
74# directory as rpath by default
75set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} )
76
77# Use native cmake modules
78list(APPEND CMAKE_MODULE_PATH "${STAGING_DATADIR}/cmake/Modules/")
79
80# add for non /usr/lib libdir, e.g. /usr/lib64
81set( CMAKE_LIBRARY_PATH ${libdir} ${base_libdir})
82
83EOF
84}
85
86addtask generate_toolchain_file after do_patch before do_configure
87
88cmake_do_configure() {
89 if [ "${OECMAKE_BUILDPATH}" ]; then
90 bbnote "cmake.bbclass no longer uses OECMAKE_BUILDPATH. The default behaviour is now out-of-tree builds with B=WORKDIR/build."
91 fi
92
93 if [ "${S}" != "${B}" ]; then
94 rm -rf ${B}
95 mkdir -p ${B}
96 cd ${B}
97 else
98 find ${B} -name CMakeFiles -or -name Makefile -or -name cmake_install.cmake -or -name CMakeCache.txt -delete
99 fi
100
101 # Just like autotools cmake can use a site file to cache result that need generated binaries to run
102 if [ -e ${WORKDIR}/site-file.cmake ] ; then
103 OECMAKE_SITEFILE=" -C ${WORKDIR}/site-file.cmake"
104 else
105 OECMAKE_SITEFILE=""
106 fi
107
108 cmake \
109 ${OECMAKE_SITEFILE} \
110 ${OECMAKE_SOURCEPATH} \
111 -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \
112 -DCMAKE_INSTALL_BINDIR:PATH=${bindir} \
113 -DCMAKE_INSTALL_SBINDIR:PATH=${sbindir} \
114 -DCMAKE_INSTALL_LIBEXECDIR:PATH=${libexecdir} \
115 -DCMAKE_INSTALL_SYSCONFDIR:PATH=${sysconfdir} \
116 -DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=${sharedstatedir} \
117 -DCMAKE_INSTALL_LOCALSTATEDIR:PATH=${localstatedir} \
118 -DCMAKE_INSTALL_LIBDIR:PATH=${libdir} \
119 -DCMAKE_INSTALL_INCLUDEDIR:PATH=${includedir} \
120 -DCMAKE_INSTALL_DATAROOTDIR:PATH=${datadir} \
121 -DCMAKE_INSTALL_SO_NO_EXE=0 \
122 -DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \
123 -DCMAKE_VERBOSE_MAKEFILE=1 \
124 ${EXTRA_OECMAKE} \
125 -Wno-dev
126}
127
128cmake_do_compile() {
129 cd ${B}
130 base_do_compile
131}
132
133cmake_do_install() {
134 cd ${B}
135 autotools_do_install
136}
137
138EXPORT_FUNCTIONS do_configure do_compile do_install do_generate_toolchain_file