From 5803846114a1556771bc73adda8814264f0adfc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Thu, 17 Oct 2019 14:25:34 +0200 Subject: [PATCH] cmake: Add option for exporting build metadata to Make MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an opt-in feature that will generate a Makefile with build variables like CC, and KBUILD_CFLAGS for consumption by third-party Make-based build systems. This emulates the 'outputexports' target that KBuild supported and is supported for the same reasons that KBuild supported it. Easier integration with third-party build systems. Signed-off-by: Sebastian Bøe --- CMakeLists.txt | 5 +++++ Kconfig.zephyr | 6 ++++++ cmake/makefile_exports/CMakeLists.txt | 29 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 cmake/makefile_exports/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 67e33b5f7b31e5..04bee90260852d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1497,6 +1497,11 @@ add_subdirectory(cmake/flash) add_subdirectory(cmake/usage) add_subdirectory(cmake/reports) +add_subdirectory_ifdef( + CONFIG_MAKEFILE_EXPORTS + cmake/makefile_exports + ) + if(NOT CONFIG_TEST) if(CONFIG_ASSERT AND (NOT CONFIG_FORCE_NO_ASSERT)) message(WARNING "__ASSERT() statements are globally ENABLED") diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 49530f48502565..269544dd98401f 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -332,6 +332,12 @@ config APPLICATION_DEFINED_SYSCALL Scan additional folders inside application source folder for application defined syscalls. +config MAKEFILE_EXPORTS + bool "Generate build metadata files named Makefile.exports" + help + Generates a file with build information that can be read by + third party Makefile-based build systems. + endmenu endmenu diff --git a/cmake/makefile_exports/CMakeLists.txt b/cmake/makefile_exports/CMakeLists.txt new file mode 100644 index 00000000000000..e864c02135ac55 --- /dev/null +++ b/cmake/makefile_exports/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2020 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +set(exports + " +CC = ${CMAKE_C_COMPILER} +CXX = ${CMAKE_CXX_COMPILER} +OBJCOPY = ${CMAKE_OBJCOPY} +OBJDUMP = ${CMAKE_OBJDUMP} +AS = ${CMAKE_AS} +AR = ${CMAKE_AR} +NM = ${CMAKE_NM} +GDB = ${CMAKE_GDB} +Z_CFLAGS = -I$, -I> -isystem $, -isystem > -D$, -D> $, > +" + ) + +# file(GENERATE writes a file at Generation time. Also, it writes one +# file per detected configuration, in this case, each COMPILE_LANGUAGE +# is a new configuration. +# +# We use 'file(GENERATE' instead of configure_file because we want to +# generate the file after Configure-time to have all the +# metadata. Also, we don't use 'add_custom_command' because it cannot +# read the generator expressions that we use. +file(GENERATE + OUTPUT ${CMAKE_BINARY_DIR}/Makefile.exports.$ + CONTENT "${exports}" +)