Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Path to the CMake file to process. |
| 2 | OECMAKE_SOURCEPATH ?= "${S}" |
| 3 | |
| 4 | DEPENDS_prepend = "cmake-native " |
| 5 | B = "${WORKDIR}/build" |
| 6 | |
| 7 | # We need to unset CCACHE otherwise cmake gets too confused |
| 8 | CCACHE = "" |
| 9 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | # C/C++ Compiler (without cpu arch/tune arguments) |
| 11 | OECMAKE_C_COMPILER ?= "`echo ${CC} | sed 's/^\([^ ]*\).*/\1/'`" |
| 12 | OECMAKE_CXX_COMPILER ?= "`echo ${CXX} | sed 's/^\([^ ]*\).*/\1/'`" |
| 13 | OECMAKE_AR ?= "${AR}" |
| 14 | |
| 15 | # Compiler flags |
| 16 | OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CFLAGS}" |
| 17 | OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 18 | OECMAKE_C_FLAGS_RELEASE ?= "-DNDEBUG" |
| 19 | OECMAKE_CXX_FLAGS_RELEASE ?= "-DNDEBUG" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | OECMAKE_C_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CPPFLAGS} ${LDFLAGS}" |
| 21 | OECMAKE_CXX_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} ${LDFLAGS}" |
| 22 | |
| 23 | OECMAKE_RPATH ?= "" |
| 24 | OECMAKE_PERLNATIVE_DIR ??= "" |
| 25 | OECMAKE_EXTRA_ROOT_PATH ?= "" |
| 26 | |
| 27 | OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "ONLY" |
| 28 | OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM_class-native = "BOTH" |
| 29 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 30 | EXTRA_OECMAKE_append = " ${PACKAGECONFIG_CONFARGS}" |
| 31 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | # 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. |
| 35 | def 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 | |
| 42 | cmake_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. |
| 46 | set( CMAKE_SYSTEM_NAME `echo ${TARGET_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` ) |
| 47 | set( CMAKE_SYSTEM_PROCESSOR ${@map_target_arch_to_uname_arch(d.getVar('TARGET_ARCH', True))} ) |
| 48 | set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} ) |
| 49 | set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} ) |
| 50 | set( CMAKE_ASM_COMPILER ${OECMAKE_C_COMPILER} ) |
| 51 | set( CMAKE_AR ${OECMAKE_AR} CACHE FILEPATH "Archiver" ) |
| 52 | set( CMAKE_C_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "CFLAGS" ) |
| 53 | set( CMAKE_CXX_FLAGS "${OECMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" ) |
| 54 | set( CMAKE_ASM_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "ASM FLAGS" ) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 55 | set( CMAKE_C_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "Additional CFLAGS for release" ) |
| 56 | set( CMAKE_CXX_FLAGS_RELEASE "${OECMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "Additional CXXFLAGS for release" ) |
| 57 | set( CMAKE_ASM_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "Additional ASM FLAGS for release" ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | set( CMAKE_C_LINK_FLAGS "${OECMAKE_C_LINK_FLAGS}" CACHE STRING "LDFLAGS" ) |
| 59 | set( 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 |
| 63 | set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_HOST} ${STAGING_DIR_NATIVE} ${CROSS_DIR} ${OECMAKE_PERLNATIVE_DIR} ${OECMAKE_EXTRA_ROOT_PATH} ${EXTERNAL_TOOLCHAIN}) |
| 64 | set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY ) |
| 65 | set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM} ) |
| 66 | set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) |
| 67 | set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) |
| 68 | |
| 69 | # Use qt.conf settings |
| 70 | set( 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 |
| 74 | set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} ) |
| 75 | |
| 76 | # Use native cmake modules |
| 77 | list(APPEND CMAKE_MODULE_PATH "${STAGING_DATADIR}/cmake/Modules/") |
| 78 | |
| 79 | # add for non /usr/lib libdir, e.g. /usr/lib64 |
| 80 | set( CMAKE_LIBRARY_PATH ${libdir} ${base_libdir}) |
| 81 | |
| 82 | EOF |
| 83 | } |
| 84 | |
| 85 | addtask generate_toolchain_file after do_patch before do_configure |
| 86 | |
| 87 | cmake_do_configure() { |
| 88 | if [ "${OECMAKE_BUILDPATH}" ]; then |
| 89 | bbnote "cmake.bbclass no longer uses OECMAKE_BUILDPATH. The default behaviour is now out-of-tree builds with B=WORKDIR/build." |
| 90 | fi |
| 91 | |
| 92 | if [ "${S}" != "${B}" ]; then |
| 93 | rm -rf ${B} |
| 94 | mkdir -p ${B} |
| 95 | cd ${B} |
| 96 | else |
| 97 | find ${B} -name CMakeFiles -or -name Makefile -or -name cmake_install.cmake -or -name CMakeCache.txt -delete |
| 98 | fi |
| 99 | |
| 100 | # Just like autotools cmake can use a site file to cache result that need generated binaries to run |
| 101 | if [ -e ${WORKDIR}/site-file.cmake ] ; then |
| 102 | OECMAKE_SITEFILE=" -C ${WORKDIR}/site-file.cmake" |
| 103 | else |
| 104 | OECMAKE_SITEFILE="" |
| 105 | fi |
| 106 | |
| 107 | cmake \ |
| 108 | ${OECMAKE_SITEFILE} \ |
| 109 | ${OECMAKE_SOURCEPATH} \ |
| 110 | -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \ |
| 111 | -DCMAKE_INSTALL_BINDIR:PATH=${bindir} \ |
| 112 | -DCMAKE_INSTALL_SBINDIR:PATH=${sbindir} \ |
| 113 | -DCMAKE_INSTALL_LIBEXECDIR:PATH=${libexecdir} \ |
| 114 | -DCMAKE_INSTALL_SYSCONFDIR:PATH=${sysconfdir} \ |
| 115 | -DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=${sharedstatedir} \ |
| 116 | -DCMAKE_INSTALL_LOCALSTATEDIR:PATH=${localstatedir} \ |
| 117 | -DCMAKE_INSTALL_LIBDIR:PATH=${libdir} \ |
| 118 | -DCMAKE_INSTALL_INCLUDEDIR:PATH=${includedir} \ |
| 119 | -DCMAKE_INSTALL_DATAROOTDIR:PATH=${datadir} \ |
| 120 | -DCMAKE_INSTALL_SO_NO_EXE=0 \ |
| 121 | -DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \ |
| 122 | -DCMAKE_VERBOSE_MAKEFILE=1 \ |
| 123 | ${EXTRA_OECMAKE} \ |
| 124 | -Wno-dev |
| 125 | } |
| 126 | |
| 127 | cmake_do_compile() { |
| 128 | cd ${B} |
| 129 | base_do_compile |
| 130 | } |
| 131 | |
| 132 | cmake_do_install() { |
| 133 | cd ${B} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 134 | oe_runmake 'DESTDIR=${D}' install |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | EXPORT_FUNCTIONS do_configure do_compile do_install do_generate_toolchain_file |