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 | |
| 10 | # We want the staging and installing functions from autotools |
| 11 | inherit autotools |
| 12 | |
| 13 | # C/C++ Compiler (without cpu arch/tune arguments) |
| 14 | OECMAKE_C_COMPILER ?= "`echo ${CC} | sed 's/^\([^ ]*\).*/\1/'`" |
| 15 | OECMAKE_CXX_COMPILER ?= "`echo ${CXX} | sed 's/^\([^ ]*\).*/\1/'`" |
| 16 | OECMAKE_AR ?= "${AR}" |
| 17 | |
| 18 | # Compiler flags |
| 19 | OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CFLAGS}" |
| 20 | OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS}" |
| 21 | OECMAKE_C_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} ${CFLAGS} -DNDEBUG" |
| 22 | OECMAKE_CXX_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} ${CXXFLAGS} -DNDEBUG" |
| 23 | OECMAKE_C_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CPPFLAGS} ${LDFLAGS}" |
| 24 | OECMAKE_CXX_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} ${LDFLAGS}" |
| 25 | |
| 26 | OECMAKE_RPATH ?= "" |
| 27 | OECMAKE_PERLNATIVE_DIR ??= "" |
| 28 | OECMAKE_EXTRA_ROOT_PATH ?= "" |
| 29 | |
| 30 | OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "ONLY" |
| 31 | OECMAKE_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. |
| 36 | def 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 | |
| 43 | cmake_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. |
| 47 | set( CMAKE_SYSTEM_NAME `echo ${TARGET_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` ) |
| 48 | set( CMAKE_SYSTEM_PROCESSOR ${@map_target_arch_to_uname_arch(d.getVar('TARGET_ARCH', True))} ) |
| 49 | set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} ) |
| 50 | set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} ) |
| 51 | set( CMAKE_ASM_COMPILER ${OECMAKE_C_COMPILER} ) |
| 52 | set( CMAKE_AR ${OECMAKE_AR} CACHE FILEPATH "Archiver" ) |
| 53 | set( CMAKE_C_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "CFLAGS" ) |
| 54 | set( CMAKE_CXX_FLAGS "${OECMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" ) |
| 55 | set( CMAKE_ASM_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "ASM FLAGS" ) |
| 56 | set( CMAKE_C_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "CFLAGS for release" ) |
| 57 | set( CMAKE_CXX_FLAGS_RELEASE "${OECMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "CXXFLAGS for release" ) |
| 58 | set( CMAKE_ASM_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "ASM FLAGS for release" ) |
| 59 | set( CMAKE_C_LINK_FLAGS "${OECMAKE_C_LINK_FLAGS}" CACHE STRING "LDFLAGS" ) |
| 60 | set( 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 |
| 64 | set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_HOST} ${STAGING_DIR_NATIVE} ${CROSS_DIR} ${OECMAKE_PERLNATIVE_DIR} ${OECMAKE_EXTRA_ROOT_PATH} ${EXTERNAL_TOOLCHAIN}) |
| 65 | set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY ) |
| 66 | set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM} ) |
| 67 | set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) |
| 68 | set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) |
| 69 | |
| 70 | # Use qt.conf settings |
| 71 | set( 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 |
| 75 | set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} ) |
| 76 | |
| 77 | # Use native cmake modules |
| 78 | list(APPEND CMAKE_MODULE_PATH "${STAGING_DATADIR}/cmake/Modules/") |
| 79 | |
| 80 | # add for non /usr/lib libdir, e.g. /usr/lib64 |
| 81 | set( CMAKE_LIBRARY_PATH ${libdir} ${base_libdir}) |
| 82 | |
| 83 | EOF |
| 84 | } |
| 85 | |
| 86 | addtask generate_toolchain_file after do_patch before do_configure |
| 87 | |
| 88 | cmake_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 | |
| 128 | cmake_do_compile() { |
| 129 | cd ${B} |
| 130 | base_do_compile |
| 131 | } |
| 132 | |
| 133 | cmake_do_install() { |
| 134 | cd ${B} |
| 135 | autotools_do_install |
| 136 | } |
| 137 | |
| 138 | EXPORT_FUNCTIONS do_configure do_compile do_install do_generate_toolchain_file |