From 487f86183a25156b0e97e18e70b0fd6fbbcb8b8c Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Wed, 29 Jan 2025 09:59:22 +0100 Subject: [PATCH] cmake: llext: avoid always compiling extensions In CMake, unless explicitly disabled, the 'add_library()' and 'add_executable()' functions add their result to the ALL target. This is undesirable for 'add_llext_target()', since it causes the source files for all defined extensions to be compiled even when the extension is not otherwise used by the build process. Add 'EXCLUDE_FROM_ALL' where appropriate so that the object files are only built when the extension is actually used by the project. Signed-off-by: Luca Burelli --- cmake/modules/extensions.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index 082ad2d2fd1..d425253a555 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -5640,7 +5640,7 @@ function(add_llext_target target_name) if(CONFIG_LLEXT_TYPE_ELF_OBJECT) # Create an object library to compile the source file - add_library(${llext_lib_target} OBJECT ${source_files}) + add_library(${llext_lib_target} EXCLUDE_FROM_ALL OBJECT ${source_files}) set(llext_lib_output $) elseif(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE) @@ -5668,7 +5668,7 @@ function(add_llext_target target_name) elseif(CONFIG_LLEXT_TYPE_ELF_SHAREDLIB) # Create a shared library - add_library(${llext_lib_target} SHARED ${source_files}) + add_library(${llext_lib_target} EXCLUDE_FROM_ALL SHARED ${source_files}) set_target_properties(${llext_lib_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/llext )