[PATCH] src/CMakeLists.txt: do not force the build of a shared library

43 views
Skip to first unread message

Pierre-Jean Texier

unread,
May 22, 2019, 12:12:01 PM5/22/19
to swup...@googlegroups.com, Pierre-Jean Texier
By definition, projects using CMake which can build either static or shared
libraries use a BUILD_SHARED_LIBS flag to allow selecting between both.
So, let CMake rely on the standard BUILD_SHARED_LIBS variable to decide
whether a static or shared library should be built.

however, we can control the behaviour as follows:

$. cmake -DBUILD_SHARED_LIBS=OFF ...

$. cmake -DBUILS_SHARED_LIBS=ON ...

With Yocto/OE, just add the following option into the libubootenv recipe :

EXTRA_OECMAKE = "-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON"

Signed-off-by: Pierre-Jean Texier <pjte...@koncepto.io>
---
src/CMakeLists.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 051732b..c5f6dcb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,10 +10,9 @@ SET(include_HEADERS
libuboot.h
)

-add_library(ubootenv SHARED ${libubootenv_SOURCES} ${include_HEADERS})
+add_library(ubootenv ${libubootenv_SOURCES} ${include_HEADERS})
SET_TARGET_PROPERTIES(ubootenv PROPERTIES SOVERSION ${SOVERSION})

-ADD_LIBRARY(ubootenv_static STATIC ${libubootenv_SOURCES} ${include_HEADERS})
add_executable(fw_printenv fw_printenv.c)
add_executable(fw_setenv fw_setenv.c)
target_link_libraries(fw_printenv ubootenv z)
--
2.7.4

Stefano Babic

unread,
May 31, 2019, 7:10:38 AM5/31/19
to Pierre-Jean Texier, swup...@googlegroups.com
Hi Pierre-Jean,

On 22/05/19 18:10, 'Pierre-Jean Texier' via swupdate wrote:
> By definition, projects using CMake which can build either static or shared
> libraries use a BUILD_SHARED_LIBS flag to allow selecting between both.
> So, let CMake rely on the standard BUILD_SHARED_LIBS variable to decide
> whether a static or shared library should be built.
>

Current recipe builds both shared and static library. A .bbappend could
then decide what it wants. Instead of this, should we not simply add a
libubootenv-static package ?

> however, we can control the behaviour as follows:
>
> $. cmake -DBUILD_SHARED_LIBS=OFF ...
>
> $. cmake -DBUILS_SHARED_LIBS=ON ...
>
> With Yocto/OE, just add the following option into the libubootenv recipe :
>
> EXTRA_OECMAKE = "-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON"
>

Does this constrain anyone to add a .bbappend ?

Best regards,
Stefano Babic

> Signed-off-by: Pierre-Jean Texier <pjte...@koncepto.io>
> ---
> src/CMakeLists.txt | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> index 051732b..c5f6dcb 100644
> --- a/src/CMakeLists.txt
> +++ b/src/CMakeLists.txt
> @@ -10,10 +10,9 @@ SET(include_HEADERS
> libuboot.h
> )
>
> -add_library(ubootenv SHARED ${libubootenv_SOURCES} ${include_HEADERS})
> +add_library(ubootenv ${libubootenv_SOURCES} ${include_HEADERS})
> SET_TARGET_PROPERTIES(ubootenv PROPERTIES SOVERSION ${SOVERSION})
>
> -ADD_LIBRARY(ubootenv_static STATIC ${libubootenv_SOURCES} ${include_HEADERS})
> add_executable(fw_printenv fw_printenv.c)
> add_executable(fw_setenv fw_setenv.c)
> target_link_libraries(fw_printenv ubootenv z)
>


--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================

Pierre-Jean Texier

unread,
May 31, 2019, 5:16:07 PM5/31/19
to Stefano Babic, swup...@googlegroups.com
Hi Stefano,


Le 31/05/2019 à 13:10, Stefano Babic a écrit :
Current recipe builds both shared and static library. A .bbappend could
then decide what it wants. Instead of this, should we not simply add a
libubootenv-static package ?

In fact, I made this patch for libubootenv when I had to use a
"full static toolchain" (br-arm-full-static), means without dynamic library support.
This is a test provided by Buildroot when integrating a new package (wih test-pkg).

For example, you can check the failure with the initial CMakeList.txt [1].
So I thought it would be better to use the CMake
mechanism (BUILD_SHARED_LIBS) to not build both libraries.



      
however, we can control the behaviour as follows:

   $. cmake -DBUILD_SHARED_LIBS=OFF ...

   $. cmake -DBUILS_SHARED_LIBS=ON ...

With Yocto/OE, just add the following option into the libubootenv recipe :

EXTRA_OECMAKE = "-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON"

Does this constrain anyone to add a .bbappend ?
As is, yes you are right, but maybe people using libubootenv (with Yocto/OE for sure)
already have a .bbappend (to install fw_env.config for instance) ?

So, maybe it would be interesting to set a default value for the Yocto/OE recipe ? (shared lib ?),
or do you prefer to keep the current implementation in libubootenv ?

Thanks,

[1] - http://autobuild.buildroot.net/results/e1837ccbe774071876642655b1fcffbd69dd7947/build-end.log
-- 
Best regards,
Pierre-Jean Texier

Stefano Babic

unread,
Jun 1, 2019, 4:54:49 AM6/1/19
to Pierre-Jean Texier, Stefano Babic, swup...@googlegroups.com
Hi Pierre-Jean,
Yes, at least a default is needed.

> or do you prefer to keep the current implementation in libubootenv ?
>

In OE it is quite common to have both shared and static libraries, and
static libraries sould be packaged into a ${PN}-staticdev. At least for
OE, I would like to get the static package in case of static linking
(mainly to the applicaton) - currently is not built.

To solve your use case, I would like to see that both libraries are
built as default, but it could be possible to override this via cmake
instead of just choosing one of the two types.

Best regards,
Stefano

> Thanks,
>
> [1] -
> http://autobuild.buildroot.net/results/e1837ccbe774071876642655b1fcffbd69dd7947/build-end.log
>
> --
> Best regards,
> Pierre-Jean Texier
>
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+u...@googlegroups.com
> <mailto:swupdate+u...@googlegroups.com>.
> To post to this group, send email to swup...@googlegroups.com
> <mailto:swup...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/swupdate/a83e0724-856f-2286-c7b6-cd8c3335c224%40koncepto.io
> <https://groups.google.com/d/msgid/swupdate/a83e0724-856f-2286-c7b6-cd8c3335c224%40koncepto.io?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages