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