blob: ac2c1519b02de28af39447217015b0ccb99d6c7c [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Path to the CMake file to process.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002OECMAKE_SOURCEPATH ??= "${S}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003
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
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034EXTRA_OECMAKE_BUILD_prepend_task-compile = "${PARALLEL_MAKE} "
35EXTRA_OECMAKE_BUILD_prepend_task-install = "${PARALLEL_MAKEINST} "
36
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037# CMake expects target architectures in the format of uname(2),
38# which do not always match TARGET_ARCH, so all the necessary
39# conversions should happen here.
40def map_target_arch_to_uname_arch(target_arch):
41 if target_arch == "powerpc":
42 return "ppc"
43 if target_arch == "powerpc64":
44 return "ppc64"
45 return target_arch
46
47cmake_do_generate_toolchain_file() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then
49 cmake_crosscompiling="set( CMAKE_CROSSCOMPILING FALSE )"
50 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 cat > ${WORKDIR}/toolchain.cmake <<EOF
52# CMake system name must be something like "Linux".
53# This is important for cross-compiling.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054$cmake_crosscompiling
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055set( CMAKE_SYSTEM_NAME `echo ${TARGET_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` )
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056set( CMAKE_SYSTEM_PROCESSOR ${@map_target_arch_to_uname_arch(d.getVar('TARGET_ARCH'))} )
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} )
58set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} )
59set( CMAKE_ASM_COMPILER ${OECMAKE_C_COMPILER} )
60set( CMAKE_AR ${OECMAKE_AR} CACHE FILEPATH "Archiver" )
61set( CMAKE_C_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "CFLAGS" )
62set( CMAKE_CXX_FLAGS "${OECMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" )
63set( CMAKE_ASM_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "ASM FLAGS" )
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050064set( CMAKE_C_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "Additional CFLAGS for release" )
65set( CMAKE_CXX_FLAGS_RELEASE "${OECMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "Additional CXXFLAGS for release" )
66set( CMAKE_ASM_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "Additional ASM FLAGS for release" )
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067set( CMAKE_C_LINK_FLAGS "${OECMAKE_C_LINK_FLAGS}" CACHE STRING "LDFLAGS" )
68set( CMAKE_CXX_LINK_FLAGS "${OECMAKE_CXX_LINK_FLAGS}" CACHE STRING "LDFLAGS" )
69
70# only search in the paths provided so cmake doesnt pick
71# up libraries and tools from the native build machine
72set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_HOST} ${STAGING_DIR_NATIVE} ${CROSS_DIR} ${OECMAKE_PERLNATIVE_DIR} ${OECMAKE_EXTRA_ROOT_PATH} ${EXTERNAL_TOOLCHAIN})
73set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
74set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM} )
75set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
76set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
77
78# Use qt.conf settings
79set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf )
80
81# We need to set the rpath to the correct directory as cmake does not provide any
82# directory as rpath by default
83set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} )
84
85# Use native cmake modules
86list(APPEND CMAKE_MODULE_PATH "${STAGING_DATADIR}/cmake/Modules/")
87
88# add for non /usr/lib libdir, e.g. /usr/lib64
89set( CMAKE_LIBRARY_PATH ${libdir} ${base_libdir})
90
91EOF
92}
93
94addtask generate_toolchain_file after do_patch before do_configure
95
Patrick Williamsc0f7c042017-02-23 20:41:17 -060096CONFIGURE_FILES = "CMakeLists.txt"
97
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098cmake_do_configure() {
99 if [ "${OECMAKE_BUILDPATH}" ]; then
100 bbnote "cmake.bbclass no longer uses OECMAKE_BUILDPATH. The default behaviour is now out-of-tree builds with B=WORKDIR/build."
101 fi
102
103 if [ "${S}" != "${B}" ]; then
104 rm -rf ${B}
105 mkdir -p ${B}
106 cd ${B}
107 else
108 find ${B} -name CMakeFiles -or -name Makefile -or -name cmake_install.cmake -or -name CMakeCache.txt -delete
109 fi
110
111 # Just like autotools cmake can use a site file to cache result that need generated binaries to run
112 if [ -e ${WORKDIR}/site-file.cmake ] ; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500113 oecmake_sitefile="-C ${WORKDIR}/site-file.cmake"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 else
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500115 oecmake_sitefile=
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 fi
117
118 cmake \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500119 $oecmake_sitefile \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120 ${OECMAKE_SOURCEPATH} \
121 -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500122 -DCMAKE_INSTALL_BINDIR:PATH=${@os.path.relpath(d.getVar('bindir'), d.getVar('prefix'))} \
123 -DCMAKE_INSTALL_SBINDIR:PATH=${@os.path.relpath(d.getVar('sbindir'), d.getVar('prefix'))} \
124 -DCMAKE_INSTALL_LIBEXECDIR:PATH=${@os.path.relpath(d.getVar('libexecdir'), d.getVar('prefix'))} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 -DCMAKE_INSTALL_SYSCONFDIR:PATH=${sysconfdir} \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500126 -DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=${@os.path.relpath(d.getVar('sharedstatedir'), d. getVar('prefix'))} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127 -DCMAKE_INSTALL_LOCALSTATEDIR:PATH=${localstatedir} \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500128 -DCMAKE_INSTALL_LIBDIR:PATH=${@os.path.relpath(d.getVar('libdir'), d.getVar('prefix'))} \
129 -DCMAKE_INSTALL_INCLUDEDIR:PATH=${@os.path.relpath(d.getVar('includedir'), d.getVar('prefix'))} \
130 -DCMAKE_INSTALL_DATAROOTDIR:PATH=${@os.path.relpath(d.getVar('datadir'), d.getVar('prefix'))} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131 -DCMAKE_INSTALL_SO_NO_EXE=0 \
132 -DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \
133 -DCMAKE_VERBOSE_MAKEFILE=1 \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600134 -DCMAKE_NO_SYSTEM_FROM_IMPORTED=1 \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135 ${EXTRA_OECMAKE} \
136 -Wno-dev
137}
138
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600139do_compile[progress] = "percent"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140cmake_do_compile() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500141 bbnote VERBOSE=1 cmake --build '${B}' -- ${EXTRA_OECMAKE_BUILD}
142 VERBOSE=1 cmake --build '${B}' -- ${EXTRA_OECMAKE_BUILD}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500143}
144
145cmake_do_install() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500146 bbnote DESTDIR='${D}' cmake --build '${B}' --target install -- ${EXTRA_OECMAKE_BUILD}
147 DESTDIR='${D}' cmake --build '${B}' --target install -- ${EXTRA_OECMAKE_BUILD}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148}
149
150EXPORT_FUNCTIONS do_configure do_compile do_install do_generate_toolchain_file