Commit 83ace6b8 authored by Ghislain MARY's avatar Ghislain MARY

Allow building both shared and static libraries with CMake.

parent b74335b0
......@@ -21,13 +21,13 @@
############################################################################
cmake_minimum_required(VERSION 3.0)
project(MEDIASTREAMER2 C CXX)
project(mediastreamer2 VERSION 2.12.1 LANGUAGES C CXX)
set(MEDIASTREAMER_MAJOR_VERSION "2")
set(MEDIASTREAMER_MINOR_VERSION "12")
set(MEDIASTREAMER_MICRO_VERSION "1")
set(MEDIASTREAMER_VERSION "${MEDIASTREAMER_MAJOR_VERSION}.${MEDIASTREAMER_MINOR_VERSION}.${MEDIASTREAMER_MICRO_VERSION}")
set(MEDIASTREAMER_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set(MEDIASTREAMER_MINOR_VERSION ${PROJECT_VERSION_MINOR})
set(MEDIASTREAMER_MICRO_VERSION ${PROJECT_VERSION_PATCH})
set(MEDIASTREAMER_VERSION ${PROJECT_VERSION})
set(MEDIASTREAMER_SO_VERSION "7") # incremented on January, the 20th 2016. DO NOT INCREMENT BEFORE MEDIASTREAMER 2.13
string(REGEX MATCH "^(arm*|aarch64)" FIXED_POINT_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
......@@ -57,7 +57,8 @@ endif()
include(CMakeDependentOption)
option(ENABLE_STATIC "Build static library (default is shared library)." NO)
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
option(ENABLE_DEBUG_LOGS "Enable the display of traces showing the execution of the library." NO)
option(ENABLE_DOC "Enable documentation generation with Doxygen." YES)
option(ENABLE_FIXED_POINT "Turn on fixed point computations." ${ENABLE_FIXED_POINT_DEFAULT_VALUE})
......@@ -119,6 +120,12 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CheckIncludeFile)
include(CheckLibraryExists)
include(CMakePushCheckState)
include(GNUInstallDirs)
if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif()
if(MSVC AND MSVC_VERSION LESS 1800)
set(MSVC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/MSVC")
......@@ -439,12 +446,12 @@ if(ENABLE_RELATIVE_PREFIX)
set(PACKAGE_PLUGINS_DIR ".")
set(PACKAGE_DATA_DIR ".")
else()
set(PACKAGE_PLUGINS_DIR "./lib/mediastreamer/plugins")
set(PACKAGE_DATA_DIR "./share")
set(PACKAGE_PLUGINS_DIR "./${CMAKE_INSTALL_LIBDIR}/mediastreamer/plugins")
set(PACKAGE_DATA_DIR "./${CMAKE_INSTALL_DATADIR}")
endif()
else()
set(PACKAGE_PLUGINS_DIR "${CMAKE_INSTALL_PREFIX}/lib/mediastreamer/plugins")
set(PACKAGE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share")
set(PACKAGE_PLUGINS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/mediastreamer/plugins")
set(PACKAGE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}")
endif()
set(LINK_FLAGS )
if(APPLE)
......@@ -533,13 +540,13 @@ configure_file(cmake/Mediastreamer2Config.cmake.in
@ONLY
)
set(ConfigPackageLocation lib/cmake/Mediastreamer2)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/Mediastreamer2/cmake")
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE Mediastreamer2Targets.cmake
DESTINATION ${ConfigPackageLocation}
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/Mediastreamer2Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Mediastreamer2ConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
DESTINATION ${CONFIG_PACKAGE_LOCATION}
)
......@@ -38,7 +38,7 @@ if(DOXYGEN_FOUND)
)
add_custom_target(ms2-html-doc ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc/html"
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/doc/mediastreamer2-${MEDIASTREAMER_VERSION}")
DESTINATION "${CMAKE_INSTALL_DATADIR}/doc/mediastreamer2-${MEDIASTREAMER_VERSION}")
else()
message(WARNING "The dot program is needed to generate the mediastreamer2 documentation. You can get it from http://www.graphviz.org/.")
endif()
......
......@@ -82,5 +82,6 @@ endforeach()
set(MEDIASTREAMER2_HEADER_FILES ${MEDIASTREAMER2_HEADER_FILES} PARENT_SCOPE)
install(FILES ${MEDIASTREAMER2_HEADER_FILES}
DESTINATION include/mediastreamer2
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mediastreamer2
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
......@@ -79,29 +79,38 @@ endif()
apply_compile_flags(BASE_SOURCE_FILES_C "CPP" "C")
add_library(mediastreamer_base-objects OBJECT ${MEDIASTREAMER2_HEADER_FILES} ${BASE_SOURCE_FILES_C})
set_target_properties(mediastreamer_base-objects PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
add_dependencies(mediastreamer_base-objects ms2-git-version ms2-basedescs-header)
if(ENABLE_STATIC)
add_library(mediastreamer_base STATIC ${MEDIASTREAMER2_HEADER_FILES} ${BASE_SOURCE_FILES_C})
else()
add_library(mediastreamer_base SHARED ${MEDIASTREAMER2_HEADER_FILES} ${BASE_SOURCE_FILES_C})
add_library(mediastreamer_base-static STATIC $<TARGET_OBJECTS:mediastreamer_base-objects>)
set_target_properties(mediastreamer_base-static PROPERTIES OUTPUT_NAME mediastreamer_base)
target_link_libraries(mediastreamer_base-static ${BASE_LIBS})
install(TARGETS mediastreamer_base-static EXPORT ${EXPORT_TARGETS_NAME}Targets
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(mediastreamer_base SHARED $<TARGET_OBJECTS:mediastreamer_base-objects>)
set_target_properties(mediastreamer_base PROPERTIES VERSION ${MEDIASTREAMER_SO_VERSION} LINKER_LANGUAGE C)
target_link_libraries(mediastreamer_base ${BASE_LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/mediastreamer_base.pdb
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
install(TARGETS mediastreamer_base EXPORT ${EXPORT_TARGETS_NAME}Targets
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()
add_dependencies(mediastreamer_base ms2-git-version ms2-basedescs-header)
target_link_libraries(mediastreamer_base ${BASE_LIBS})
install(TARGETS mediastreamer_base EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
......@@ -452,36 +461,48 @@ if (CAMAPI_FOUND)
list(APPEND VOIP_LIBS ${CAMAPI_LIBRARIES})
endif()
add_library(mediastreamer_voip-objects OBJECT ${MEDIASTREAMER2_HEADER_FILES} ${VOIP_SOURCE_FILES_C} ${VOIP_SOURCE_FILES_CXX} ${VOIP_SOURCE_FILES_OBJC})
set_target_properties(mediastreamer_voip-objects PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
add_dependencies(mediastreamer_voip-objects ms2-git-version ms2-voipdescs-header)
if(APPLE OR GLX_FOUND)
add_dependencies(mediastreamer_voip-objects ms2-yuv2rgb-fs-header ms2-yuv2rgb-vs-header)
endif()
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
if(ENABLE_STATIC)
add_library(mediastreamer_voip STATIC ${MEDIASTREAMER2_HEADER_FILES} ${VOIP_SOURCE_FILES_C} ${VOIP_SOURCE_FILES_CXX} ${VOIP_SOURCE_FILES_OBJC})
else()
add_library(mediastreamer_voip-static STATIC $<TARGET_OBJECTS:mediastreamer_voip-objects>)
set_target_properties(mediastreamer_voip-static PROPERTIES OUTPUT_NAME mediastreamer_voip)
if(LINK_FLAGS_STR)
set_target_properties(mediastreamer_voip-static PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_link_libraries(mediastreamer_voip-static ${VOIP_LIBS})
install(TARGETS mediastreamer_voip-static EXPORT ${EXPORT_TARGETS_NAME}Targets
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(mediastreamer_voip SHARED ${MEDIASTREAMER2_HEADER_FILES} ${VOIP_SOURCE_FILES_C} ${VOIP_SOURCE_FILES_CXX} ${VOIP_SOURCE_FILES_OBJC})
set_target_properties(mediastreamer_voip PROPERTIES VERSION ${MEDIASTREAMER_SO_VERSION} LINKER_LANGUAGE CXX)
if(LINK_FLAGS_STR)
set_target_properties(mediastreamer_voip PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
target_link_libraries(mediastreamer_voip ${VOIP_LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/mediastreamer_voip.pdb
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
install(TARGETS mediastreamer_voip EXPORT ${EXPORT_TARGETS_NAME}Targets
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()
add_dependencies(mediastreamer_voip ms2-git-version ms2-voipdescs-header)
if(APPLE OR GLX_FOUND)
add_dependencies(mediastreamer_voip ms2-yuv2rgb-fs-header ms2-yuv2rgb-vs-header)
endif()
target_link_libraries(mediastreamer_voip ${VOIP_LIBS})
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
if(LINK_FLAGS_STR)
set_target_properties(mediastreamer_voip PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
endif()
install(TARGETS mediastreamer_voip EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
if(ENABLE_VIDEO)
install(FILES voip/nowebcamCIF.jpg
......@@ -497,15 +518,15 @@ if(ENABLE_VIDEO AND CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
target_link_libraries(mswinrtjpeg2yuv mediastreamer_voip)
install(TARGETS mswinrtjpeg2yuv
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
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
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/mswinrtjpeg2yuv.pdb
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
......
......@@ -70,15 +70,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set_target_properties(mediastreamer2_tester_runtime PROPERTIES LINK_FLAGS "/WINMDFILE:BelledonneCommunications.Mediastreamer2.Tester.winmd")
install(TARGETS mediastreamer2_tester_runtime
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
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
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/BelledonneCommunications.Mediastreamer2.Tester.winmd" DESTINATION lib)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/BelledonneCommunications.Mediastreamer2.Tester.pdb
DESTINATION lib
DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
......
......@@ -65,6 +65,6 @@ if(ENABLE_VIDEO)
target_link_libraries(mkvstream mediastreamer_voip mediastreamer_base)
install(TARGETS mediastream mkvstream
RUNTIME DESTINATION bin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
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