Hi Dan,

Thank you very much for the in-depth and detailed explanation!
I really appreciate the time and seriousness you put into the answer.
It definitely sorted me out.

Netanel

ב-יום שלישי, 10 בינואר 2023 בשעה 06:39:35 UTC+2, [email protected] כתב/ה:

> A common way for this to work would be to use a static library:
>
> Common/Android.bp:
>
>   cc_library_static {
>       name: "libCommon",
>       srcs: ["Common.cpp"],
>       export_include_dirs: ["."],
>   }
>
> Foo/Android.bp:
>
>   cc_library_shared {
>       name: "libFoo",
>       static_libs: ["libCommon"],
>       srcs: ["Foo.cpp"],
>   }
>
> That works best if the common code is actually common, and doesn't need to 
> try to include Foo.h or Bar.h at build time. It also works in the inverse 
> case, where Foo and Bar can be independently built static libraries 
> included by Common. It has the advantage that there's only one link that 
> provides both the sources and headers, so you can't accidentally forget 
> one, or change one but not the other. It'll also only build Common.cpp 
> once, even if it's used by both libFoo and libBar.
>
> If that's not the case, I'd suggest some refactoring :-) But it is 
> possible to use a header-only library instead, along with a filegroup for 
> the source:
>
> Common/Android.bp:
>
>   filegroup {
>       name: "CommonSrcs",
>       srcs: ["Common.cpp"],
>   }
>   cc_library_headers {
>       name: "libCommonHdrs",
>       export_include_dirs: ["."],
>   }
>
> Foo/Android.bp:
>
>   cc_library_shared {
>       name: "libFoo",
>       header_libs: ["libCommonHdrs"],
>       srcs: ["Foo.cpp", ":CommonSrcs"],
>   }
>
> cc_library_headers is really meant to be used only for header-only 
> libraries -- cases where there are no source files, and everything you need 
> is in the header files. So this is outside the expected use cases, which 
> may cause problems as the build system evolves in the future (though 
> misuses of this are fairly common).
>
> - Dan
>
> On Mon, Jan 9, 2023 at 2:28 PM Netanel Hadad <[email protected]> wrote:
>
>> Hi,
>>
>> I'm trying to include cpp and header files from the external folder in 
>> soong build.
>>
>> I saw here 
>> <https://groups.google.com/g/android-building/c/CHOSvZNlnaY/m/I590b-rOBAAJ> 
>> that 
>> for cpp files I can use *filegroup *and it indeed works, but I didn't 
>> find a way to include header files.
>>
>> In the example below, I want to include common files in both Foo and Bar 
>> Android.bp.
>>
>> - Root
>> - - Android.bp
>> -
>> - - Common(folder)
>> - - - Common.cpp
>> - - - Common.h
>> - - - Defs.h
>> -
>> - - Foo(folder)
>> - - - Android.bp
>> - - - Foo.cpp
>> - - - Foo.h
>> -
>> - - Bar(folder)
>> - - - Android.bp
>> - - - Bar.cpp
>> - - - Bar.h
>>
>> Regards,
>> Netanel
>>
>> -- 
>> -- 
>> You received this message because you are subscribed to the "Android 
>> Building" mailing list.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/android-building?hl=en
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Android Building" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/android-building/b2e5a425-90a8-4358-920b-86b7e2def8d6n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/android-building/b2e5a425-90a8-4358-920b-86b7e2def8d6n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
-- 
You received this message because you are subscribed to the "Android Building" 
mailing list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-building/61b55883-df23-4535-8858-fdb1724893afn%40googlegroups.com.

Reply via email to