Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: add optional static and shared build options #778

Merged
merged 3 commits into from
May 2, 2023

Conversation

sreimers
Copy link
Member

@sreimers sreimers commented May 1, 2023

refs #771

@sreimers sreimers changed the title cmake: add optional static and shared build cmake: add optional static and shared build options May 1, 2023
@alfredh
Copy link
Contributor

alfredh commented May 1, 2023

many thanks, this looks like a good and flexible approach.

it also does not require any user changes, which is good for Juha's project.

@alfredh
Copy link
Contributor

alfredh commented May 2, 2023

I think we can merge this now ...

@sreimers sreimers merged commit 64e5843 into main May 2, 2023
@sreimers sreimers deleted the build_static_optional branch May 2, 2023 07:14
@juha-h
Copy link
Contributor

juha-h commented May 2, 2023

I pulled latest re:

/usr/src/libbaresip-android$ grep SHARED re/CMakeLists.txt 
option(LIBRE_BUILD_SHARED "Build shared library" ON)
if(LIBRE_BUILD_SHARED)
  add_library(re-shared SHARED $<TARGET_OBJECTS:re-objs>)
if(LIBRE_BUILD_SHARED)

and made libre Android build:

/usr/src/libbaresip-android$ make libre.a
cd re && \
rm -rf build && rm -rf .cache && mkdir build && cd build && \
cmake .. \
	-DANDROID=ON -DANDROID_PLATFORM=23 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=23 -DCMAKE_TOOLCHAIN_FILE=/opt/Android/ndk/25.2.9519653/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_SKIP_INSTALL_RPATH=ON -DCMAKE_C_COMPILER=aarch64-linux-android23-clang -DCMAKE_CXX_COMPILER=aarch64-linux-android23-clang++ -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_FIND_ROOT_PATH="/opt/Android/ndk/25.2.9519653;/usr/src/libbaresip-android/openssl" \
	-DOPENSSL_VERSION_MAJOR=3 \
	-DOPENSSL_ROOT_DIR=/usr/src/libbaresip-android/openssl && \
cmake --build . --target re -j
-- The C compiler identification is Clang 14.0.7
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/Android/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test COMPILER_SUPPORTS_WATOMIC
-- Performing Test COMPILER_SUPPORTS_WATOMIC - Success
-- Looking for backtrace
-- Looking for backtrace - not found
-- Could NOT find Backtrace (missing: Backtrace_LIBRARY) 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- Found ZLIB: /opt/Android/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/23/libz.so (found version "1.2.12") 
-- Found OpenSSL: /usr/src/libbaresip-android/openssl/libcrypto.a (found suitable version "3.1.0", minimum required is "1.1.1")  
-- Looking for arc4random
-- Looking for arc4random - found
-- Looking for syslog.h
-- Looking for syslog.h - found
-- Looking for getopt.h
-- Looking for getopt.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for res_ninit
-- Looking for res_ninit - not found
-- Looking for thrd_create
-- Looking for thrd_create - not found
-- Looking for accept4
-- Looking for accept4 - found
-- Looking for epoll_create
-- Looking for epoll_create - found
-- Looking for kqueue
-- Looking for kqueue - not found
-- Looking for sys/prctl.h
-- Looking for sys/prctl.h - found
-- Could NOT find Backtrace (missing: Backtrace_LIBRARY) 
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/src/libbaresip-android/re/build
...
gmake[4]: Entering directory '/usr/src/libbaresip-android/re/build'
[  1%] Building C object CMakeFiles/re-objs.dir/src/async/async.c.o
...

[100%] Building C object CMakeFiles/re-objs.dir/rem/vidmix/vidmix.c.o
gmake[4]: Leaving directory '/usr/src/libbaresip-android/re/build'
[100%] Built target re-objs
gmake[4]: Entering directory '/usr/src/libbaresip-android/re/build'
[100%] Linking C static library libre.a
gmake[4]: Leaving directory '/usr/src/libbaresip-android/re/build'
[100%] Built target re
gmake[3]: Leaving directory '/usr/src/libbaresip-android/re/build'

And the result was that (like before) only static lib was build. I don't need shared libs, but I am just wondering.

@sreimers
Copy link
Member Author

sreimers commented May 2, 2023

You just specify only the static target with --target re, thats fine.

@alfredh
Copy link
Contributor

alfredh commented May 2, 2023

hi Juha,

in your cmake command line options you can now select which type of libs your want to build:

option(LIBRE_BUILD_SHARED "Build shared library" ON)
option(LIBRE_BUILD_STATIC "Build static library" ON)
$ cmake -DLIBRE_BUILD_SHARED=OFF .
$ make

i.e. you can skip the target if you want.

KORuL pushed a commit to KORuL/re that referenced this pull request May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants