Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Path to the CMake file to process. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | OECMAKE_SOURCEPATH ??= "${S}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 10 | # What CMake generator to use. |
| 11 | # The supported options are "Unix Makefiles" or "Ninja". |
| 12 | OECMAKE_GENERATOR ?= "Ninja" |
| 13 | |
| 14 | python() { |
| 15 | generator = d.getVar("OECMAKE_GENERATOR") |
| 16 | if generator == "Unix Makefiles": |
| 17 | args = "-G 'Unix Makefiles' -DCMAKE_MAKE_PROGRAM=" + d.getVar("MAKE") |
| 18 | d.setVar("OECMAKE_GENERATOR_ARGS", args) |
| 19 | d.setVarFlag("do_compile", "progress", "percent") |
| 20 | elif generator == "Ninja": |
| 21 | d.appendVar("DEPENDS", " ninja-native") |
| 22 | d.setVar("OECMAKE_GENERATOR_ARGS", "-G Ninja -DCMAKE_MAKE_PROGRAM=ninja") |
| 23 | d.setVarFlag("do_compile", "progress", "outof:^\[(\d+)/(\d+)\]\s+") |
| 24 | else: |
| 25 | bb.fatal("Unknown CMake Generator %s" % generator) |
| 26 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | # C/C++ Compiler (without cpu arch/tune arguments) |
| 28 | OECMAKE_C_COMPILER ?= "`echo ${CC} | sed 's/^\([^ ]*\).*/\1/'`" |
| 29 | OECMAKE_CXX_COMPILER ?= "`echo ${CXX} | sed 's/^\([^ ]*\).*/\1/'`" |
| 30 | OECMAKE_AR ?= "${AR}" |
| 31 | |
| 32 | # Compiler flags |
| 33 | OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CFLAGS}" |
| 34 | OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 35 | OECMAKE_C_FLAGS_RELEASE ?= "-DNDEBUG" |
| 36 | OECMAKE_CXX_FLAGS_RELEASE ?= "-DNDEBUG" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | OECMAKE_C_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CPPFLAGS} ${LDFLAGS}" |
| 38 | OECMAKE_CXX_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} ${LDFLAGS}" |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 39 | CXXFLAGS += "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}" |
| 40 | CFLAGS += "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 41 | |
| 42 | OECMAKE_RPATH ?= "" |
| 43 | OECMAKE_PERLNATIVE_DIR ??= "" |
| 44 | OECMAKE_EXTRA_ROOT_PATH ?= "" |
| 45 | |
| 46 | OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "ONLY" |
| 47 | OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM_class-native = "BOTH" |
| 48 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 49 | EXTRA_OECMAKE_append = " ${PACKAGECONFIG_CONFARGS}" |
| 50 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 51 | EXTRA_OECMAKE_BUILD_prepend_task-compile = "${PARALLEL_MAKE} " |
| 52 | EXTRA_OECMAKE_BUILD_prepend_task-install = "${PARALLEL_MAKEINST} " |
| 53 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 54 | OECMAKE_TARGET_COMPILE ?= "all" |
| 55 | OECMAKE_TARGET_INSTALL ?= "install" |
| 56 | |
| 57 | FILES_${PN}-dev += "${libdir}/cmake ${datadir}/cmake" |
| 58 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | # CMake expects target architectures in the format of uname(2), |
| 60 | # which do not always match TARGET_ARCH, so all the necessary |
| 61 | # conversions should happen here. |
| 62 | def map_target_arch_to_uname_arch(target_arch): |
| 63 | if target_arch == "powerpc": |
| 64 | return "ppc" |
| 65 | if target_arch == "powerpc64": |
| 66 | return "ppc64" |
| 67 | return target_arch |
| 68 | |
| 69 | cmake_do_generate_toolchain_file() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 70 | if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then |
| 71 | cmake_crosscompiling="set( CMAKE_CROSSCOMPILING FALSE )" |
| 72 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | cat > ${WORKDIR}/toolchain.cmake <<EOF |
| 74 | # CMake system name must be something like "Linux". |
| 75 | # This is important for cross-compiling. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 76 | $cmake_crosscompiling |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | set( CMAKE_SYSTEM_NAME `echo ${TARGET_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` ) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 78 | set( CMAKE_SYSTEM_PROCESSOR ${@map_target_arch_to_uname_arch(d.getVar('TARGET_ARCH'))} ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} ) |
| 80 | set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} ) |
| 81 | set( CMAKE_ASM_COMPILER ${OECMAKE_C_COMPILER} ) |
| 82 | set( CMAKE_AR ${OECMAKE_AR} CACHE FILEPATH "Archiver" ) |
| 83 | set( CMAKE_C_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "CFLAGS" ) |
| 84 | set( CMAKE_CXX_FLAGS "${OECMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" ) |
| 85 | set( CMAKE_ASM_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "ASM FLAGS" ) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 86 | set( CMAKE_C_FLAGS_RELEASE "${OECMAKE_C_FLAGS_RELEASE}" CACHE STRING "Additional CFLAGS for release" ) |
| 87 | set( CMAKE_CXX_FLAGS_RELEASE "${OECMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "Additional CXXFLAGS for release" ) |
| 88 | 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] | 89 | set( CMAKE_C_LINK_FLAGS "${OECMAKE_C_LINK_FLAGS}" CACHE STRING "LDFLAGS" ) |
| 90 | set( CMAKE_CXX_LINK_FLAGS "${OECMAKE_CXX_LINK_FLAGS}" CACHE STRING "LDFLAGS" ) |
| 91 | |
| 92 | # only search in the paths provided so cmake doesnt pick |
| 93 | # up libraries and tools from the native build machine |
| 94 | set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_HOST} ${STAGING_DIR_NATIVE} ${CROSS_DIR} ${OECMAKE_PERLNATIVE_DIR} ${OECMAKE_EXTRA_ROOT_PATH} ${EXTERNAL_TOOLCHAIN}) |
| 95 | set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY ) |
| 96 | set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM} ) |
| 97 | set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) |
| 98 | set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) |
| 99 | |
| 100 | # Use qt.conf settings |
| 101 | set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf ) |
| 102 | |
| 103 | # We need to set the rpath to the correct directory as cmake does not provide any |
| 104 | # directory as rpath by default |
| 105 | set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} ) |
| 106 | |
| 107 | # Use native cmake modules |
| 108 | list(APPEND CMAKE_MODULE_PATH "${STAGING_DATADIR}/cmake/Modules/") |
| 109 | |
| 110 | # add for non /usr/lib libdir, e.g. /usr/lib64 |
| 111 | set( CMAKE_LIBRARY_PATH ${libdir} ${base_libdir}) |
| 112 | |
| 113 | EOF |
| 114 | } |
| 115 | |
| 116 | addtask generate_toolchain_file after do_patch before do_configure |
| 117 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 118 | CONFIGURE_FILES = "CMakeLists.txt" |
| 119 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | cmake_do_configure() { |
| 121 | if [ "${OECMAKE_BUILDPATH}" ]; then |
| 122 | bbnote "cmake.bbclass no longer uses OECMAKE_BUILDPATH. The default behaviour is now out-of-tree builds with B=WORKDIR/build." |
| 123 | fi |
| 124 | |
| 125 | if [ "${S}" != "${B}" ]; then |
| 126 | rm -rf ${B} |
| 127 | mkdir -p ${B} |
| 128 | cd ${B} |
| 129 | else |
| 130 | find ${B} -name CMakeFiles -or -name Makefile -or -name cmake_install.cmake -or -name CMakeCache.txt -delete |
| 131 | fi |
| 132 | |
| 133 | # Just like autotools cmake can use a site file to cache result that need generated binaries to run |
| 134 | if [ -e ${WORKDIR}/site-file.cmake ] ; then |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 135 | oecmake_sitefile="-C ${WORKDIR}/site-file.cmake" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | else |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 137 | oecmake_sitefile= |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | fi |
| 139 | |
| 140 | cmake \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 141 | ${OECMAKE_GENERATOR_ARGS} \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 142 | $oecmake_sitefile \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | ${OECMAKE_SOURCEPATH} \ |
| 144 | -DCMAKE_INSTALL_PREFIX:PATH=${prefix} \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 145 | -DCMAKE_INSTALL_BINDIR:PATH=${@os.path.relpath(d.getVar('bindir'), d.getVar('prefix'))} \ |
| 146 | -DCMAKE_INSTALL_SBINDIR:PATH=${@os.path.relpath(d.getVar('sbindir'), d.getVar('prefix'))} \ |
| 147 | -DCMAKE_INSTALL_LIBEXECDIR:PATH=${@os.path.relpath(d.getVar('libexecdir'), d.getVar('prefix'))} \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 148 | -DCMAKE_INSTALL_SYSCONFDIR:PATH=${sysconfdir} \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 149 | -DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=${@os.path.relpath(d.getVar('sharedstatedir'), d. getVar('prefix'))} \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | -DCMAKE_INSTALL_LOCALSTATEDIR:PATH=${localstatedir} \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 151 | -DCMAKE_INSTALL_LIBDIR:PATH=${@os.path.relpath(d.getVar('libdir'), d.getVar('prefix'))} \ |
| 152 | -DCMAKE_INSTALL_INCLUDEDIR:PATH=${@os.path.relpath(d.getVar('includedir'), d.getVar('prefix'))} \ |
| 153 | -DCMAKE_INSTALL_DATAROOTDIR:PATH=${@os.path.relpath(d.getVar('datadir'), d.getVar('prefix'))} \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | -DCMAKE_INSTALL_SO_NO_EXE=0 \ |
| 155 | -DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain.cmake \ |
| 156 | -DCMAKE_VERBOSE_MAKEFILE=1 \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 157 | -DCMAKE_NO_SYSTEM_FROM_IMPORTED=1 \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 158 | ${EXTRA_OECMAKE} \ |
| 159 | -Wno-dev |
| 160 | } |
| 161 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 162 | cmake_runcmake_build() { |
| 163 | bbnote ${DESTDIR:+DESTDIR=${DESTDIR} }VERBOSE=1 cmake --build '${B}' "$@" -- ${EXTRA_OECMAKE_BUILD} |
| 164 | eval ${DESTDIR:+DESTDIR=${DESTDIR} }VERBOSE=1 cmake --build '${B}' "$@" -- ${EXTRA_OECMAKE_BUILD} |
| 165 | } |
| 166 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 167 | cmake_do_compile() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 168 | cmake_runcmake_build --target ${OECMAKE_TARGET_COMPILE} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | cmake_do_install() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 172 | DESTDIR='${D}' cmake_runcmake_build --target ${OECMAKE_TARGET_INSTALL} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | EXPORT_FUNCTIONS do_configure do_compile do_install do_generate_toolchain_file |