From patchwork Fri Apr 21 06:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Poonam Jadhav X-Patchwork-Id: 22820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30C7DC7618E for ; Fri, 21 Apr 2023 06:08:20 +0000 (UTC) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mx.groups.io with SMTP id smtpd.web11.5499.1682057298167804951 for ; Thu, 20 Apr 2023 23:08:18 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=ccW4n1fR; spf=pass (domain: gmail.com, ip: 209.85.214.181, mailfrom: ppjadhav456@gmail.com) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1a526aa3dd5so21004575ad.3 for ; Thu, 20 Apr 2023 23:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682057297; x=1684649297; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/iVa7Vo9Ff8Eh3jQ2tAzhSa5Gzq5qrF38XtXp+xTN5c=; b=ccW4n1fRa9FKSf4wS8rq+bF6i+QYrFwKyCJKvI83p726b3pNxf087gt2Qz4yPI5yE5 3GVOoT0SWFXHGzwj+zPAZ+t//92fNuNFKYoG8Y+z9iuYeDdRxe3LYXvQkYe0/o/xb4K7 8cp8JtmzFq0CSYNlzPr5a+6KeSL0dlz88OiNVAqGMoyBCAGtrLotpsZOBuvuAdyDQGna 0Z877A8n4zJ5fv/acrHPDlLNTDx9AF2MATt3D7NptEDVm/IHAE9Rde61OZF/TOGaYFeJ 2AWQQ3fCKJLF9O45QBQ3fbLySe5v0cnqZoMlghCJq2XB2yKKSTSHRqm2fIw914DsUsQv zNDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682057297; x=1684649297; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/iVa7Vo9Ff8Eh3jQ2tAzhSa5Gzq5qrF38XtXp+xTN5c=; b=mGKMbjLWMEX5JFvg5CdVv2Vq2W87eTBw/X6i9NKecmP1HGnz4NdU3/PQseItRkA25l FbFARe/SL2z0HZM8I5qxKk5LH1wUzVCawa1A5sTqCldG+8mLMs6kc5wsFBpepLvOb6K5 /p08xyPJl0xfpWunYX+tvQB2/yuUqtyvcQiZTVt7WVRZqUysQskrA6t/wZDVz5CIp3n6 Zz6Lf4I5/9IPvw00T6xPGIsMelaIiiQiVcAr61y+Aro+j686P7iVtFqWx9YKhbwLzqbf lRusltDKYhZ3u5mQFl7mSkAuhJ1WWOJhTMg8aHFqI1F8Zo7nOrBoIml4QK5KBRWqWuMj iOhg== X-Gm-Message-State: AAQBX9eoq92llOU6XL8svPtf2AqCkPLtZ4qZ8rd+ZVDLuzvrnPq/JdHc eaXZa6ErY1/lknSMGne56y+n2+KoQnCzCQ== X-Google-Smtp-Source: AKy350YOJGwbHDRVnVjbBshV84hhpIh0bhRhMa3qvb/PDKOXJcqYw/O5ZO597SjuyN1xs8ctKLAAaQ== X-Received: by 2002:a17:903:234b:b0:1a1:e33f:d567 with SMTP id c11-20020a170903234b00b001a1e33fd567mr4828521plh.52.1682057297063; Thu, 20 Apr 2023 23:08:17 -0700 (PDT) Received: from localhost.localdomain ([38.41.69.0]) by smtp.gmail.com with ESMTPSA id y23-20020a1709029b9700b001a69c1c78e7sm2027236plp.71.2023.04.20.23.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 23:08:15 -0700 (PDT) From: Poonam Jadhav To: openembedded-core@lists.openembedded.org, poonam.jadhav@kpit.com Cc: ranjitsinh.rathod@kpit.com, Poonam Jadhav , Pascal Bach , Mikko Rapeli , Poonam Jadhav Subject: [OE-core][master][PATCH] cmake: add CMAKE_SYSROOT to generated toolchain file Date: Fri, 21 Apr 2023 11:37:41 +0530 Message-Id: <20230421060741.21471-1-ppjadhav456@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Fri, 21 Apr 2023 06:08:20 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/180274 From: Poonam Jadhav This already got fixed in the toolchain file that is used during development in https://github.com/openembedded/openembedded-core/commit/cb42802f2fe1760f894a435b07286bca3a220364 The toolchain file generated by the cmake.bbclass however does not set CMAKE_SYSROOT. Under certain circumstances this also leads to the error: `"stdlib.h: No such file or directory #include_next "` during the build of a recipe. An example where this accured was during the upgrade of the Apache Thrift recipe in meta-openembedded to 0.11.0. With this change the build works out of the box. CMAKE_SYSROOT must only be set when crosscompiling, otherwise it will interfere with the native compiler headers. Signed-off-by: Pascal Bach (from http://lists.openembedded.org/pipermail/openembedded-core/2018-August/154791.html ) Signed-off-by: Mikko Rapeli Signed-off-by: Poonam Jadhav --- meta/classes/cmake.bbclass | 223 +++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 meta/classes/cmake.bbclass diff --git a/meta/classes/cmake.bbclass b/meta/classes/cmake.bbclass new file mode 100644 index 0000000000..68326b1ea0 --- /dev/null +++ b/meta/classes/cmake.bbclass @@ -0,0 +1,223 @@ +# Path to the CMake file to process. +OECMAKE_SOURCEPATH ??= "${S}" + +DEPENDS_prepend = "cmake-native " +B = "${WORKDIR}/build" + +# What CMake generator to use. +# The supported options are "Unix Makefiles" or "Ninja". +OECMAKE_GENERATOR ?= "Ninja" + +python() { + generator = d.getVar("OECMAKE_GENERATOR") + if "Unix Makefiles" in generator: + args = "-G '" + generator + "' -DCMAKE_MAKE_PROGRAM=" + d.getVar("MAKE") + d.setVar("OECMAKE_GENERATOR_ARGS", args) + d.setVarFlag("do_compile", "progress", "percent") + elif "Ninja" in generator: + args = "-G '" + generator + "' -DCMAKE_MAKE_PROGRAM=ninja" + d.appendVar("DEPENDS", " ninja-native") + d.setVar("OECMAKE_GENERATOR_ARGS", args) + d.setVarFlag("do_compile", "progress", r"outof:^\[(\d+)/(\d+)\]\s+") + else: + bb.fatal("Unknown CMake Generator %s" % generator) + + # C/C++ Compiler (without cpu arch/tune arguments) + if not d.getVar('OECMAKE_C_COMPILER'): + cc_list = d.getVar('CC').split() + if cc_list[0] == 'ccache': + d.setVar('OECMAKE_C_COMPILER_LAUNCHER', cc_list[0]) + d.setVar('OECMAKE_C_COMPILER', cc_list[1]) + else: + d.setVar('OECMAKE_C_COMPILER', cc_list[0]) + + if not d.getVar('OECMAKE_CXX_COMPILER'): + cxx_list = d.getVar('CXX').split() + if cxx_list[0] == 'ccache': + d.setVar('OECMAKE_CXX_COMPILER_LAUNCHER', cxx_list[0]) + d.setVar('OECMAKE_CXX_COMPILER', cxx_list[1]) + else: + d.setVar('OECMAKE_CXX_COMPILER', cxx_list[0]) +} +OECMAKE_AR ?= "${AR}" + +# Compiler flags +OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CFLAGS}" +OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS}" +OECMAKE_C_FLAGS_RELEASE ?= "-DNDEBUG" +OECMAKE_CXX_FLAGS_RELEASE ?= "-DNDEBUG" +OECMAKE_C_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CPPFLAGS} ${LDFLAGS}" +OECMAKE_CXX_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} ${LDFLAGS}" +CXXFLAGS += "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}" +CFLAGS += "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}" + +OECMAKE_C_COMPILER_LAUNCHER ?= "" +OECMAKE_CXX_COMPILER_LAUNCHER ?= "" + +OECMAKE_RPATH ?= "" +OECMAKE_PERLNATIVE_DIR ??= "" +OECMAKE_EXTRA_ROOT_PATH ?= "" + +OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "ONLY" +OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM_class-native = "BOTH" + +EXTRA_OECMAKE_append = " ${PACKAGECONFIG_CONFARGS}" + +export CMAKE_BUILD_PARALLEL_LEVEL +CMAKE_BUILD_PARALLEL_LEVEL_task-compile = "${@oe.utils.parallel_make(d, False)}" +CMAKE_BUILD_PARALLEL_LEVEL_task-install = "${@oe.utils.parallel_make(d, True)}" + +OECMAKE_TARGET_COMPILE ?= "all" +OECMAKE_TARGET_INSTALL ?= "install" + +def map_host_os_to_system_name(host_os): + if host_os.startswith('mingw'): + return 'Windows' + if host_os.startswith('linux'): + return 'Linux' + return host_os + +# CMake expects target architectures in the format of uname(2), +# which do not always match TARGET_ARCH, so all the necessary +# conversions should happen here. +def map_host_arch_to_uname_arch(host_arch): + if host_arch == "powerpc": + return "ppc" + if host_arch == "powerpc64": + return "ppc64" + return host_arch + + +cmake_do_generate_toolchain_file() { + if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then + cmake_crosscompiling="set( CMAKE_CROSSCOMPILING FALSE )" + else + cmake_sysroot="set( CMAKE_SYSROOT \"${RECIPE_SYSROOT}\" )" + fi + cat > ${WORKDIR}/toolchain.cmake <