Skip to content
Snippets Groups Projects
Commit ac7e3e7d authored by Alexandre Eberhardt's avatar Alexandre Eberhardt Committed by Alexandre Eberhardt
Browse files

Build: clean CMakeList for Linux, Android and MacOS AudioFilter

Change-Id: Ia64d5e11d703ce66608836f2d11ece4b653c6fa2
parent 17deedc9
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required (VERSION 3.10) cmake_minimum_required (VERSION 3.10)
# set the project name # Set the project name and version
set (ProjectName AudioFilter) set (ProjectName AudioFilter)
set (Version 1.0.2) set (Version 2.0.0)
project (${ProjectName} VERSION ${Version}) project (${ProjectName} VERSION ${Version})
# Detect OS and architecture # Set default options
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) option (DEBUG "Build in debug mode" OFF)
message(FATAL_ERROR "Unsupported architecture. Only x64 or aarch64 (arm64) is supported.")
# Set platform to build for
set (PLATFORM_TYPE $ENV{PLATFORM_TYPE}) # can be LINUX or ANDROID or MACOS
if (PLATFORM_TYPE STREQUAL "ANDROID")
set (PLATFORM $ENV{ANDROID_ABI}) # can be arm64-v8a, armeabi-v7a or x86_64
elseif(PLATFORM_TYPE STREQUAL "LINUX")
set (PLATFORM x86_64-linux-gnu) # can be x86_64-linux-gnu
elseif(PLATFORM_TYPE STREQUAL "MACOS")
execute_process(
COMMAND sh -c "$(command -v cc || command -v gcc) -dumpmachine" # used to create the directory for daemon contribution, see daemon/contrib/bootstrap
OUTPUT_VARIABLE DUMP_MACHINE_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE # remove the trailing "\n"
)
set (PLATFORM ${DUMP_MACHINE_RESULT})
execute_process(
COMMAND sh -c "uname -m"
OUTPUT_VARIABLE ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE # remove the trailing "\n"
)
set (PLATFORM_LIB_DIR "${ARCH}-apple-darwin")
else() else()
set (ARCH $CMAKE_SYSTEM_PROCESSOR) message(FATAL_ERROR "Platform type not supported for now")
endif () endif ()
if(WIN32) set(CMAKE_ANDROID_ARCH_ABI ${PLATFORM})
set(DISTRIBUTION "x64-windows")
elseif(APPLE) # set compilation flags based on platform
set(DISTRIBUTION "${ARCH}-apple-darwin") if (PLATFORM STREQUAL "x86_64-linux-gnu")
elseif(ANDROID) set (CONTRIB_PLATFORM x86_64-linux-gnu)
set(DISTRIBUTION "android") set (distribution x86_64-linux-gnu)
elseif (PLATFORM STREQUAL "arm64-v8a")
set (CONTRIB_PLATFORM aarch64-linux-android)
set (distribution android)
elseif (PLATFORM STREQUAL "armeabi-v7a")
set (CONTRIB_PLATFORM arm-linux-androideabi)
set (distribution android)
elseif (PLATFORM STREQUAL "x86_64")
set (CONTRIB_PLATFORM x86_64-linux-android)
set (distribution android)
elseif (PLATFORM STREQUAL "x86_64-apple-darwin23.6.0")
set (CONTRIB_PLATFORM x86_64-apple-darwin23.6.0)
set (distribution x86_64-apple-darwin23.6.0)
else() else()
set(DISTRIBUTION "x86_64-linux-gnu") set (CONTRIB_PLATFORM ${PLATFORM})
set (dsitribution ${PLATFORM})
endif () endif ()
# Paths setup if (PLATFORM_TYPE STREQUAL "ANDROID")
set (JAMI_PLUGINS_PATH ${PROJECT_SOURCE_DIR}/.. ) # should be removed and use the toolchain in env instead
set (DAEMON ${JAMI_PLUGINS_PATH}/daemon) set(CMAKE_ANDROID_ARCH_ABI ${PLATFORM}) # Set the desired ABI
set (DAEMON_SRC ${DAEMON}/src) set(CMAKE_ANDROID_STL_TYPE c++_shared) # Use C++ shared library
set (CONTRIB_PATH ${DAEMON}/contrib) set(CMAKE_ANDROID_NDK_TOOLCHAIN_FILE /opt/android/ndk/26.3.11579264/build/cmake/android.toolchain.cmake)
set (PLUGINS_LIB ${JAMI_PLUGINS_PATH}/lib) set(CMAKE_TOOLCHAIN_FILE=/opt/android/ndk/26.3.11579264/build/cmake/android.toolchain.cmake)
set (JPL_DIRECTORY ${PROJECT_BINARY_DIR}/jpl) set(CMAKE_C_COMPILER /opt/android/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/${CONTRIB_PLATFORM}30-clang)
set (JPL_FILE_NAME ${ProjectName}.jpl) set(CMAKE_CXX_COMPILER /opt/android/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/${CONTRIB_PLATFORM}30-clang++)
set (SDK_PATH ${JAMI_PLUGINS_PATH}/SDK) endif()
set (PLUGIN_OUTPUT_DIR ${JPL_DIRECTORY}/lib/${DISTRIBUTION})
message ("PLATFORM_TYPE: ${PLATFORM_TYPE}")
message(Distribution:\ ${DISTRIBUTION}) message ("PLATFORM: ${PLATFORM}")
message(Building:\ ${ProjectName} ${Version}) message ("CONTRIB_PLATFORM: ${CONTRIB_PLATFORM}")
message(Build\ path:\ ${PROJECT_BINARY_DIR}) message ("distribution: ${distribution}")
message(JPL\ assembling\ path:\ ${JPL_DIRECTORY})
message(JPL\ path:\ ${JAMI_PLUGINS_PATH}/build/${DISTRIBUTION}/${JPL_FILE_NAME})
# Set variables
set (CMAKE_CXX_STANDARD 17) set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED True) set (CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /DMSGPACK_NO_BOOST /MT") set (DAEMON ${PROJECT_SOURCE_DIR}/../daemon)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DMSGPACK_NO_BOOST /MTd") set (CONTRIB_PATH ${DAEMON}/contrib)
set (PLUGINS_LIB ${PROJECT_SOURCE_DIR}/../lib)
set (CONTRIB_ROOT_PATH ${CONTRIB_PATH}/${CONTRIB_PLATFORM})
set (CMAKE_BUILD_RPATH "$ORIGIN")
set (SDK_PATH ${PROJECT_SOURCE_DIR}/../SDK)
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set platform specific variables
if (PLATFORM_TYPE STREQUAL "ANDROID")
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bsymbolic")
elseif (PLATFORM_TYPE STREQUAL "LINUX")
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bsymbolic")
elseif(PLATFORM_TYPE STREQUAL "MACOS")
set (CMAKE_SHARED_LINKER_FLAGS "-Wl")
endif ()
find_package (PkgConfig REQUIRED)
list (APPEND PKG_CONFIG_EXECUTABLE "--static")
list (APPEND CMAKE_FIND_ROOT_PATH ${CONTRIB_ROOT_PATH})
set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
list (APPEND CMAKE_PREFIX_PATH ${CONTRIB_ROOT_PATH})
# Find required packages
pkg_search_module (avutil REQUIRED IMPORTED_TARGET libavutil)
add_definitions (-DMSGPACK_NO_BOOST)
if (DEBUG)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -Wall -Wextra -Wno-unused-parameter")
add_definitions (-D__DEBUG__)
else ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -Wextra -Wno-unused-parameter")
endif ()
if(PLATEFORM_TYPE STREQUAL "MACOS")
find_library (COREFOUNDATION CoreFoundation)
find_library (COREMEDIA CoreMedia)
find_library (COREVIDEO CoreVideo)
find_library (CORESERVICES CoreServices)
find_library (FOUNDATION Foundation)
find_library (AVFOUNDATION AVFoundation)
find_library (COREGRAPHICS CoreGraphics)
set (MACOS_LIBS
${COREFOUNDATION}
${COREMEDIA}
${COREVIDEO}
${CORESERVICES}
${FOUNDATION}
${AVFOUNDATION}
${COREGRAPHICS}
)
endif()
# Source files
set (plugin_SRC set (plugin_SRC
FilterAudioSubscriber.cpp
main.cpp main.cpp
FilterAudioSubscriber.cpp
FilterMediaHandler.cpp FilterMediaHandler.cpp
${PLUGINS_LIB}/frameUtils.cpp
${PLUGINS_LIB}/frameFilter.cpp ${PLUGINS_LIB}/frameFilter.cpp
) ${PLUGINS_LIB}/frameUtils.cpp
set(plugin_HDR
FilterMediaHandler.h
FilterAudioSubscriber.h
${PLUGINS_LIB}/frameUtils.h
${PLUGINS_LIB}/pluglog.h
${PLUGINS_LIB}/frameFilter.h
) )
# Create shared library # Create shared library
add_library(${ProjectName} SHARED ${plugin_SRC} ${plugin_HDR}) add_library (${ProjectName} SHARED ${plugin_SRC})
find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter)
# Include directories
target_include_directories (${ProjectName} PUBLIC target_include_directories (${ProjectName} PUBLIC
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}
${DAEMON}/src
${CONTRIB_PATH}/${CONTRIB_PLATFORM}/include
${PLUGINS_LIB} ${PLUGINS_LIB}
${DAEMON_SRC}
${CONTRIB_PATH}
${CONTRIB_PATH}/build/fmt/include
${CONTRIB_PATH}/build/opendht/include
${CONTRIB_PATH}/build/msgpack-c/include
${FFMPEG}/include
) )
# Link directories and libraries
target_link_directories(${ProjectName} PUBLIC # Link directories
${CONTRIB_PATH} link_directories (
${CONTRIB_PATH}/build/fmt/msvc/Release ${CONTRIB_PATH}/${CONTRIB_PLATFORM}/lib
${FFMPEG}/bin
) )
target_link_libraries(${ProjectName} PUBLIC avutil) # Libraries to link
set (LINK_LIBS
PkgConfig::avutil
)
# Android-specific flags # Link libraries to the target
if(ANDROID) target_link_libraries (${ProjectName} PUBLIC ${MACOS_LIBS} ${LINK_LIBS}) # if the platform is not MACOS, MACOS_LIBS will be empty and will not affect the build
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a) # Set the desired ABI
set(CMAKE_ANDROID_STL_TYPE c++_shared) # Use C++ shared library
set(CMAKE_ANDROID_NDK_TOOLCHAIN_FILE ${CONTRIB_PATH}/build/cmake/android.toolchain.cmake)
set(CMAKE_ANDROID_STL_INCLUDE_DIR ${CONTRIB_PATH}/sysroot/usr/include)
set(CMAKE_ANDROID_STL_LIBRARIES ${CONTRIB_PATH}/sysroot/usr/lib)
endif()
if(CMAKE_CXX_FLAGS_DEBUG) if(PLATFORM_TYPE STREQUAL "MACOS")
set(OUTPUT "${ProjectName}") set_target_properties (${ProjectName} PROPERTIES
set(CLANG_OPTS "-g -fsanitize=address") LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/jpl/lib/${PLATFORM_LIB_DIR}"
set(EXTRA_DEBUG_LIBRARIES "-lyaml-cpp") )
set(EXTRA_DEFINES "-D__DEBUG__")
else () else ()
add_custom_command( set_target_properties (${ProjectName} PROPERTIES
TARGET ${ProjectName} LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/jpl/lib/${PLATFORM}"
PRE_BUILD
COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../SDK/jplManipulation.py --preassemble --plugin=${ProjectName}
COMMENT "Assembling Plugin files"
) )
endif() endif()
add_custom_command ( add_custom_command (
TARGET ${ProjectName} TARGET ${ProjectName}
PRE_BUILD PRE_BUILD
COMMAND ${Python3_EXECUTABLE} ${SDK_PATH}/jplManipulation.py --preassemble --plugin=${ProjectName} COMMAND ${Python3_EXECUTABLE} ${SDK_PATH}/jplManipulation.py --preassemble --plugin=${ProjectName} --distribution=${distribution} --arch=${ARCH}
--arch=${ARCH} --distribution=${DISTRIBUTION}
COMMENT "Assembling Plugin files" COMMENT "Assembling Plugin files"
) )
# Copy shared library to jpl directory
add_custom_command(
TARGET ${ProjectName}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${ProjectName}> ${PLUGIN_OUTPUT_DIR}
COMMENT "Copying output file to jpl directory"
)
add_custom_command ( add_custom_command (
TARGET ${ProjectName} TARGET ${ProjectName}
POST_BUILD POST_BUILD
COMMAND ${Python3_EXECUTABLE} ${SDK_PATH}/jplManipulation.py --assemble --plugin=${ProjectName} COMMAND ${Python3_EXECUTABLE} ${SDK_PATH}/jplManipulation.py --assemble --plugin=${ProjectName} --distribution=${distribution}
COMMENT "Generating JPL archive" COMMENT "Generating JPL archive"
) )
\ No newline at end of file
# To build AudioFilter, follow these steps:
build the folowing daemon contributions :
- fmt
- opendht
- ffmpeg
- msgpack
## from jami-plugins/ run:
### Linux:
```bash
PLATFORM_TYPE="LINUX" python3 build-plugin.py --projects='AudioFilter'
```
### Android:
```bash
PLATFORM_TYPE="ANDROID" ANDROID_ABI="{Android ABI}" python3 build-plugin.py --projects='AudioFilter'
```
### MacOS
```bash
PLATFORM_TYPE="MACOS" python3 build-plugin.py --projects='AudioFilter'
```
## Once the build is complete, you will find your unsigned `AudioFilter.jpl` in:
```
jami-plugins/build/{your distribution}/
```
## To install it on Jami, you need to sign the plugin. Refer to `sign.md` in the `jami-plugins/` directory for instructions on how to sign your plugin.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment