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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ option(USE_JBUF "Enable JBUF" ON)
option(USE_PCP "Enable PCP" ON)
option(USE_RTMP "Enable RTMP" ON)
option(USE_SIP "Enable SIP" ON)
option(LIBRE_BUILD_SHARED "Build shared library" ON)
option(LIBRE_BUILD_STATIC "Build static library" ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down Expand Up @@ -670,29 +672,34 @@ target_include_directories(re-objs PRIVATE include
# Shared target libre.[so|dll|dylib]
#

add_library(re-shared SHARED $<TARGET_OBJECTS:re-objs>)
target_link_libraries(re-shared PRIVATE ${LINKLIBS})
set_target_properties(re-shared PROPERTIES VERSION
${PROJECT_SOVERSION}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
set_target_properties(re-shared PROPERTIES SOVERSION ${PROJECT_SOVERSION})
set_target_properties(re-shared PROPERTIES OUTPUT_NAME "re")
if(LIBRE_BUILD_SHARED)
list(APPEND RE_INSTALL_TARGETS re-shared)
add_library(re-shared SHARED $<TARGET_OBJECTS:re-objs>)
target_link_libraries(re-shared PRIVATE ${LINKLIBS})
set_target_properties(re-shared PROPERTIES VERSION
${PROJECT_SOVERSION}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
set_target_properties(re-shared PROPERTIES SOVERSION ${PROJECT_SOVERSION})
set_target_properties(re-shared PROPERTIES OUTPUT_NAME "re")
endif()


##############################################################################
#
# Static target libre.a
#

add_library(re STATIC $<TARGET_OBJECTS:re-objs>)
target_link_libraries(re PUBLIC ${LINKLIBS})
target_include_directories(re PUBLIC include)
set_target_properties(re PROPERTIES PUBLIC_HEADER "${HEADERS}")
if(LIBRE_BUILD_STATIC)
list(APPEND RE_INSTALL_TARGETS re)
add_library(re STATIC $<TARGET_OBJECTS:re-objs>)
target_link_libraries(re PUBLIC ${LINKLIBS})
target_include_directories(re PUBLIC include)
set_target_properties(re PROPERTIES PUBLIC_HEADER "${HEADERS}")

if(MSVC)
set_target_properties(re PROPERTIES OUTPUT_NAME "re-static")
if(MSVC)
set_target_properties(re PROPERTIES OUTPUT_NAME "re-static")
endif()
endif()


##############################################################################
#
# Packaging section
Expand All @@ -710,7 +717,8 @@ configure_file(packaging/libre.pc.in libre.pc @ONLY)
# Install section
#

install(TARGETS re-shared re

install(TARGETS ${RE_INSTALL_TARGETS}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Libraries
Expand All @@ -723,12 +731,14 @@ install(TARGETS re-shared re
COMPONENT Development
)

install(TARGETS re-shared
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
COMPONENT Development
)
if(LIBRE_BUILD_SHARED)
install(TARGETS re-shared
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
COMPONENT Development
)
endif()

install(FILES cmake/re-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/re
Expand Down