Commit 0ed137cd authored by Ghislain MARY's avatar Ghislain MARY

Allow building both shared and static libraries.

parent e540e0c4
......@@ -21,12 +21,12 @@
############################################################################
cmake_minimum_required(VERSION 3.0)
project(BCG729 C)
project(bcg729 VERSION 1.0.1 LANGUAGES C)
set(PACKAGE "bcg729")
set(PACKAGE_NAME "${PACKAGE}")
set(PACKAGE_VERSION "1.0.1")
set(PACKAGE "${PROJECT_NAME}")
set(PACKAGE_NAME "${PROJECT_NAME}")
set(PACKAGE_VERSION "${PROJECT_VERSION}")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "support@belledonne-communications.com")
set(PACKAGE_TARNAME "bcg729")
......@@ -34,9 +34,12 @@ set(PACKAGE_URL "")
set(VERSION "${PACKAGE_VERSION}")
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
option(ENABLE_TESTS "Enable compilation of the tests." NO)
option(ENABLE_MSPLUGIN "Enable compilation of the mediastreamer2 plugin." YES)
option(ENABLE_STATIC "Build static library (default is shared library)." NO)
include(GNUInstallDirs)
if(ENABLE_MSPLUGIN)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
......@@ -99,13 +102,13 @@ configure_file(Bcg729Config.cmake
COPYONLY
)
set(ConfigPackageLocation lib/cmake/Bcg729)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/Bcg729/cmake")
install(EXPORT Bcg729Targets
FILE Bcg729Targets.cmake
DESTINATION ${ConfigPackageLocation}
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/Bcg729Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Bcg729ConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
......@@ -27,27 +27,35 @@ set(SOURCE_FILES
include_directories(${MEDIASTREAMER2_INCLUDE_DIRS})
add_library(msbcg729-objects OBJECT ${SOURCE_FILES})
set_target_properties(msbcg729-objects PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
if(ENABLE_STATIC)
add_library(msbcg729 STATIC ${BCG729_SOURCE_FILES} ${SOURCE_FILES})
else()
add_library(msbcg729 SHARED ${BCG729_SOURCE_FILES} ${SOURCE_FILES})
add_library(msbcg729-static STATIC $<TARGET_OBJECTS:bcg729-objects> $<TARGET_OBJECTS:msbcg729-objects>)
set_target_properties(msbcg729-static PROPERTIES OUTPUT_NAME msbcg729)
target_link_libraries(msbcg729-static ${MEDIASTREAMER2_LIBRARIES})
install(TARGETS msbcg729-static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/mediastreamer/plugins
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
if(ENABLE_SHARED)
add_library(msbcg729 MODULE $<TARGET_OBJECTS:bcg729-objects> $<TARGET_OBJECTS:msbcg729-objects>)
set_target_properties(msbcg729 PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION 0)
target_link_libraries(msbcg729 ${MEDIASTREAMER2_LIBRARIES})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/libmsbcg729.pdb
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
set_target_properties(msbcg729 PROPERTIES PREFIX "lib")
endif()
install(TARGETS msbcg729
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/mediastreamer/plugins
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/mediastreamer/plugins
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/mediastreamer/plugins
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
target_link_libraries(msbcg729 ${MEDIASTREAMER2_LIBRARIES})
install(TARGETS msbcg729
RUNTIME DESTINATION lib/mediastreamer/plugins
LIBRARY DESTINATION lib/mediastreamer/plugins
ARCHIVE DESTINATION lib/mediastreamer/plugins
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
......@@ -46,31 +46,33 @@ set(BCG729_SOURCE_FILES
utils.c
)
if (ENABLE_STATIC)
add_library(bcg729 STATIC ${BCG729_SOURCE_FILES})
else()
add_library(bcg729-objects OBJECT ${BCG729_SOURCE_FILES})
set_target_properties(bcg729-objects PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
if(ENABLE_STATIC)
add_library(bcg729-static STATIC $<TARGET_OBJECTS:bcg729-objects>)
set_target_properties(bcg729-static PROPERTIES OUTPUT_NAME bcg729)
install(TARGETS bcg729-static EXPORT Bcg729Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
if(ENABLE_SHARED)
add_library(bcg729 SHARED ${BCG729_SOURCE_FILES})
set_target_properties(bcg729 PROPERTIES VERSION 0)
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/libbcg729.pdb
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
set_target_properties(bcg729 PROPERTIES PREFIX "lib")
endif()
install(TARGETS bcg729 EXPORT Bcg729Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
install(TARGETS bcg729 EXPORT Bcg729Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
set(ABS_BCG729_SOURCE_FILES )
foreach(elem ${BCG729_SOURCE_FILES})
list(APPEND ABS_BCG729_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${elem}")
endforeach()
set(BCG729_SOURCE_FILES ${ABS_BCG729_SOURCE_FILES} PARENT_SCOPE)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment