baresip/re

Add support for building static and/or dynamic library

alfredh opened this issue · 8 comments

A usecase for CMake is to be able to select only static library, or dynamic library, or both.

This is used by package managers such as e.g. VCPKG

A sample solution may be found here:

https://github.com/microsoft/vcpkg/pull/30859/files#diff-0fffa68a767e7b53cac73774ef963034a32a87ebdd58ed70defc983ca564a359

There is a CMake variable BUILD_SHARED_LIBS that can be used:

https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

Should we use this one, or are there better options ?

Yes BUILD_SHARED_LIBS is more the normal cmake way. With cmake migration I tried to keep the old behavior as much as possible (old Makefile builds always both (static + shared)). I think we can reduce complexity and build only once at a time. I can prepare a PR for this.

thanks

I think one important
usecase is Android project
from Juha

@juha-h

After seeing this issue, I yesterday tested and my libbaresip-android build already builds only static re library like this:

libre.a: Makefile
	cd re && \
	rm -rf build && rm -rf .cache && mkdir build && cd build && \
	cmake .. \
		$(CMAKE_ANDROID_FLAGS) \
		-DCMAKE_FIND_ROOT_PATH="$(NDK_PATH);$(PWD)/openssl" \
		-DOPENSSL_VERSION_MAJOR=3 \
		-DOPENSSL_ROOT_DIR=$(PWD)/openssl && \
	cmake --build . --target re -j

So if something new is needed, it is for building only dynamic lib or static and dynamic libs.

I dont think any changes are needed for Android, with Android I think it needs a static lib.

correction:

with this patch you can select to use static or shared:

$ cmake -DBUILD_SHARED_LIBS=OFF .

OK, will try after the PR has been committed.

fixed in 64e5843