Skip to content

Commit 7257ae1

Browse files
committed
Enable by default PIC for the static library build
Can be disabled via AV_ENABLE_STATIC_PIC=Off
1 parent acd343e commit 7257ae1

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
1414
set(FFMPEG_PKG_CONFIG_SUFFIX "" CACHE STRING "This suffix uses for FFmpeg component names searches by pkg-config")
1515
set(AV_ENABLE_STATIC On CACHE BOOL "Enable static library build (On)")
1616
set(AV_ENABLE_SHARED On CACHE BOOL "Enable shared library build (On)")
17+
set(AV_ENABLE_STATIC_PIC On CACHE BOOL "Enable Position Independent Code build for the statis library")
1718
set(AV_BUILD_EXAMPLES On CACHE BOOL "Build example applications (On)")
1819
set(AV_BUILD_TESTS On CACHE BOOL "Build tests (On)")
1920
option(AV_DISABLE_AVFORMAT "Disable libavformat usage. Also turns off: AVFILTER, AVDEVICE" Off)

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ foreach(TARGET ${AV_TARGETS})
4141

4242
add_library(${TARGET} ${TYPE} ${AV_SOURCES} ${AV_HEADERS})
4343

44+
# allow use static library to build shared one
45+
if (AV_ENABLE_STATIC_PIC AND ${TYPE} MATCHES "STATIC")
46+
message(STATUS "Enable POSITION_INDEPENDENT_CODE (-fPIC) build for static library")
47+
set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
48+
endif()
49+
4450
target_compile_options(${TARGET} PRIVATE ${AVCPP_WARNING_OPTIONS})
4551
target_compile_definitions(${TARGET} PUBLIC __STDC_CONSTANT_MACROS)
4652
target_link_libraries(${TARGET} PRIVATE Threads::Threads PUBLIC FFmpeg::FFmpeg)

0 commit comments

Comments
 (0)