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