diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a79abb..659b510 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,16 +34,15 @@ else() endif() -set(ffmpegLibHint ${defFFmpegLibHint} CACHE PATH "directory with static ffmpeg libs") +set(ffmpegLibHint "${CMAKE_CURRENT_SOURCE_DIR}/${defFFmpegLibHint}" CACHE PATH "directory with static ffmpeg libs") set(libSuffix ${defLibSuffix} CACHE STRING "output library suffix") set(pluginDir ${defPluginDir} CACHE PATH "TS3 plugin directory (for file copy)") - -find_path(ffmpegIncludeDir libavcodec/avcodec.h HINTS ${ffmpegIncHint}) -find_library(avcodec avcodec HINTS ${ffmpegLibHint}) -find_library(avformat avformat HINTS ${ffmpegLibHint}) -find_library(avutil avutil HINTS ${ffmpegLibHint}) -find_library(swresample swresample HINTS ${ffmpegLibHint}) +find_path(ffmpegIncludeDir libavcodec/avcodec.h PATHS ${ffmpegIncHint} NO_DEFAULT_PATH) +find_library(avcodec avcodec PATHS ${ffmpegLibHint} NO_DEFAULT_PATH) +find_library(avformat avformat PATHS ${ffmpegLibHint} NO_DEFAULT_PATH) +find_library(avutil avutil PATHS ${ffmpegLibHint} NO_DEFAULT_PATH) +find_library(swresample swresample PATHS ${ffmpegLibHint} NO_DEFAULT_PATH) find_package(Qt5 COMPONENTS Core Widgets Gui Network REQUIRED) @@ -55,6 +54,9 @@ set(CMAKE_AUTORCC ON) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Turn fPIC on +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + # version advance script (generates version.h file) add_custom_command( OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/version/version.h" @@ -67,10 +69,12 @@ set_property(SOURCE "src/version/version.h" PROPERTY SKIP_AUTOGEN ON) # actual library definition add_library(rp_soundboard SHARED ${sources} "src/version/version.h") -target_link_libraries(rp_soundboard - Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Network - ${avcodec} ${avformat} ${avutil} ${swresample} -) +target_link_libraries(rp_soundboard Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Network) +if (WIN32) + # only link this way on Windows. Linux requires VERY special linker commands, see below + target_link_libraries(rp_soundboard ${avcodec} ${avformat} ${avutil} ${swresample}) +endif() + target_include_directories(rp_soundboard PUBLIC "pluginsdk/include" ${ffmpegIncludeDir}) set_target_properties(rp_soundboard PROPERTIES SUFFIX ${libSuffix} @@ -78,16 +82,27 @@ set_target_properties(rp_soundboard PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE release ) +# Special platform dependent compile options if (MSVC) target_sources(rp_soundboard PRIVATE "src/windows/resource.h" "src/windows/Resource.rc") target_link_libraries(rp_soundboard wsock32 ws2_32 secur32) # some windows stuff target_compile_options(rp_soundboard PRIVATE /MP) # multiprocessor compiling -elseif(APPLE) - target_compile_definitions(rp_soundboard PRIVATE "MACOS") else() - target_compile_definitions(rp_soundboard PRIVATE "LINUX") + if(APPLE) + target_compile_definitions(rp_soundboard PRIVATE "MACOS") + else() + target_compile_definitions(rp_soundboard PRIVATE "LINUX") + endif() + # Compile options that are required to NOT get the "recompile with -fPIC" + # error when linking the ffmpeg libs. Took me many hours to find this out... + set_target_properties(rp_soundboard PROPERTIES LINK_FLAGS + "-Wl,-Bsymbolic -Wl,--whole-archive \ + ${avcodec} ${avformat} ${avutil} ${swresample} \ + -Wl,--no-whole-archive" + ) endif() + # copy to teamspeak dir command stuff set(COPY_DLL_TO_TEAMSPEAK_DIR TRUE CACHE BOOL "Copy the soundboard DLL to teamspeaks directory") if (COPY_DLL_TO_TEAMSPEAK_DIR) diff --git a/ffmpeg/build-scripts/build_ffmpeg.sh b/ffmpeg/build-scripts/build_ffmpeg.sh index 527a7da..0f2afba 100755 --- a/ffmpeg/build-scripts/build_ffmpeg.sh +++ b/ffmpeg/build-scripts/build_ffmpeg.sh @@ -30,6 +30,7 @@ fi echo "Machine =" $machine $arch opts="\ +--enable-pic \ --disable-programs \ --disable-doc \ --disable-avdevice \ diff --git a/ffmpeg/build-scripts/copy_binaries.sh b/ffmpeg/build-scripts/copy_binaries.sh index f51a6f2..a85b255 100755 --- a/ffmpeg/build-scripts/copy_binaries.sh +++ b/ffmpeg/build-scripts/copy_binaries.sh @@ -4,12 +4,21 @@ os="$(uname -s)" case "$os" in - Linux*) prefix="lib_lin" - postfix="a" ;; - Darwin*) prefix="lib_mac" - postfix="a" ;; - *) prefix="lib_win" - postfix="lib" ;; + Linux*) + prefix="lib_lin" + postfix="a" + infix="lib" + ;; + Darwin*) + prefix="lib_mac" + postfix="a" + infix="lib" + ;; + *) + prefix="lib_win" + infix="" + postfix="lib" + ;; esac pushd .. @@ -17,14 +26,14 @@ pushd .. mkdir -p "${prefix}_x64" mkdir -p "${prefix}_x86" -cp ffmpeg/x64/lib/libavcodec.a ${prefix}_x64/avcodec.$postfix -cp ffmpeg/x64/lib/libavformat.a ${prefix}_x64/avformat.$postfix -cp ffmpeg/x64/lib/libavutil.a ${prefix}_x64/avutil.$postfix -cp ffmpeg/x64/lib/libswresample.a ${prefix}_x64/swresample.$postfix +cp ffmpeg/x64/lib/libavcodec.a ${prefix}_x64/${infix}avcodec.$postfix +cp ffmpeg/x64/lib/libavformat.a ${prefix}_x64/${infix}avformat.$postfix +cp ffmpeg/x64/lib/libavutil.a ${prefix}_x64/${infix}avutil.$postfix +cp ffmpeg/x64/lib/libswresample.a ${prefix}_x64/${infix}swresample.$postfix cp -R ffmpeg/x64/include ${prefix}_x64/include -cp ffmpeg/x86/lib/libavcodec.a ${prefix}_x86/avcodec.$postfix -cp ffmpeg/x86/lib/libavformat.a ${prefix}_x86/avformat.$postfix -cp ffmpeg/x86/lib/libavutil.a ${prefix}_x86/avutil.$postfix -cp ffmpeg/x86/lib/libswresample.a ${prefix}_x86/swresample.$postfix +cp ffmpeg/x86/lib/libavcodec.a ${prefix}_x86/${infix}avcodec.$postfix +cp ffmpeg/x86/lib/libavformat.a ${prefix}_x86/${infix}avformat.$postfix +cp ffmpeg/x86/lib/libavutil.a ${prefix}_x86/${infix}avutil.$postfix +cp ffmpeg/x86/lib/libswresample.a ${prefix}_x86/${infix}swresample.$postfix cp -R ffmpeg/x86/include ${prefix}_x86/include