Commit 0324cd36 authored by Ghislain MARY's avatar Ghislain MARY

Allow building both shared and static libraries with CMake.

parent c8402413
......@@ -21,12 +21,12 @@
############################################################################
cmake_minimum_required(VERSION 3.0)
project(MSOPENH264)
project(msopenh264 VERSION 1.1.1 LANGUAGES CXX)
set(PACKAGE "msopenh264")
set(PACKAGE_NAME "${PACKAGE}")
set(PACKAGE_VERSION "1.1.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 "msopenh264")
......@@ -34,9 +34,16 @@ set(PACKAGE_URL "")
set(VERSION "${PACKAGE_VERSION}")
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
option(ENABLE_DECODER "Enable the openh264 decoder" Yes)
option(ENABLE_STATIC "Build static library (default is shared library)." NO)
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()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
......@@ -65,12 +72,12 @@ include_directories(
add_definitions(-DHAVE_CONFIG_H)
if(NOT MSVC)
add_definitions(-Wall -Wno-error=unknown-pragmas)
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_definitions("-Wno-error=unknown-warning-option")
if (NOT IOS)
add_definitions("-Werror")
endif()
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_definitions("-Werror -Wno-error=pragmas")
endif()
endif(NOT MSVC)
......
......@@ -35,27 +35,35 @@ if(ENABLE_DECODER)
add_definitions(-DOPENH264_DECODER_ENABLED)
endif()
add_library(msopenh264-objects OBJECT ${SOURCE_FILES})
set_target_properties(msopenh264-objects PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
if(ENABLE_STATIC)
add_library(msopenh264 STATIC ${SOURCE_FILES})
else()
add_library(msopenh264 SHARED ${SOURCE_FILES})
add_library(msopenh264-static STATIC $<TARGET_OBJECTS:msopenh264-objects>)
set_target_properties(msopenh264-static PROPERTIES OUTPUT_NAME msopenh264)
target_link_libraries(msopenh264-static ${LIBS})
install(TARGETS msopenh264-static
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(msopenh264 MODULE $<TARGET_OBJECTS:msopenh264-objects>)
set_target_properties(msopenh264 PROPERTIES VERSION 0)
target_link_libraries(msopenh264 ${LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/libmsopenh264.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(msopenh264 PROPERTIES PREFIX "lib")
endif()
install(TARGETS msopenh264
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()
set_target_properties(msopenh264 PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LINK_FLAGS}")
target_link_libraries(msopenh264 ${LIBS})
install(TARGETS msopenh264
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
)
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