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