@@ -34,16 +34,15 @@ else()
3434endif ()
3535
3636
37- set (ffmpegLibHint ${ defFFmpegLibHint} CACHE PATH "directory with static ffmpeg libs" )
37+ set (ffmpegLibHint " ${CMAKE_CURRENT_SOURCE_DIR} / ${ defFFmpegLibHint}" CACHE PATH "directory with static ffmpeg libs" )
3838set (libSuffix ${defLibSuffix} CACHE STRING "output library suffix" )
3939set (pluginDir ${defPluginDir} CACHE PATH "TS3 plugin directory (for file copy)" )
4040
41-
42- find_path (ffmpegIncludeDir libavcodec/avcodec.h HINTS ${ffmpegIncHint} )
43- find_library (avcodec avcodec HINTS ${ffmpegLibHint} )
44- find_library (avformat avformat HINTS ${ffmpegLibHint} )
45- find_library (avutil avutil HINTS ${ffmpegLibHint} )
46- find_library (swresample swresample HINTS ${ffmpegLibHint} )
41+ find_path (ffmpegIncludeDir libavcodec/avcodec.h PATHS ${ffmpegIncHint} NO_DEFAULT_PATH)
42+ find_library (avcodec avcodec PATHS ${ffmpegLibHint} NO_DEFAULT_PATH)
43+ find_library (avformat avformat PATHS ${ffmpegLibHint} NO_DEFAULT_PATH)
44+ find_library (avutil avutil PATHS ${ffmpegLibHint} NO_DEFAULT_PATH)
45+ find_library (swresample swresample PATHS ${ffmpegLibHint} NO_DEFAULT_PATH)
4746
4847find_package (Qt5 COMPONENTS Core Widgets Gui Network REQUIRED)
4948
@@ -55,6 +54,9 @@ set(CMAKE_AUTORCC ON)
5554# Find includes in corresponding build directories
5655set (CMAKE_INCLUDE_CURRENT_DIR ON )
5756
57+ # Turn fPIC on
58+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
59+
5860# version advance script (generates version.h file)
5961add_custom_command (
6062 OUTPUT "${CMAKE_CURRENT_SOURCE_DIR} /src/version/version.h"
@@ -67,27 +69,40 @@ set_property(SOURCE "src/version/version.h" PROPERTY SKIP_AUTOGEN ON)
6769
6870# actual library definition
6971add_library (rp_soundboard SHARED ${sources} "src/version/version.h" )
70- target_link_libraries (rp_soundboard
71- Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Network
72- ${avcodec} ${avformat} ${avutil} ${swresample}
73- )
72+ target_link_libraries (rp_soundboard Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Network)
73+ if (WIN32 )
74+ # only link this way on Windows. Linux requires VERY special linker commands, see below
75+ target_link_libraries (rp_soundboard ${avcodec} ${avformat} ${avutil} ${swresample} )
76+ endif ()
77+
7478target_include_directories (rp_soundboard PUBLIC "pluginsdk/include" ${ffmpegIncludeDir} )
7579set_target_properties (rp_soundboard PROPERTIES
7680 SUFFIX ${libSuffix}
7781 RUNTIME_OUTPUT_DIRECTORY_DEBUG debug
7882 RUNTIME_OUTPUT_DIRECTORY_RELEASE release
7983)
8084
85+ # Special platform dependent compile options
8186if (MSVC )
8287 target_sources (rp_soundboard PRIVATE "src/windows/resource.h" "src/windows/Resource.rc" )
8388 target_link_libraries (rp_soundboard wsock32 ws2_32 secur32) # some windows stuff
8489 target_compile_options (rp_soundboard PRIVATE /MP) # multiprocessor compiling
85- elseif (APPLE )
86- target_compile_definitions (rp_soundboard PRIVATE "MACOS" )
8790else ()
88- target_compile_definitions (rp_soundboard PRIVATE "LINUX" )
91+ if (APPLE )
92+ target_compile_definitions (rp_soundboard PRIVATE "MACOS" )
93+ else ()
94+ target_compile_definitions (rp_soundboard PRIVATE "LINUX" )
95+ endif ()
96+ # Compile options that are required to NOT get the "recompile with -fPIC"
97+ # error when linking the ffmpeg libs. Took me many hours to find this out...
98+ set_target_properties (rp_soundboard PROPERTIES LINK_FLAGS
99+ "-Wl,-Bsymbolic -Wl,--whole-archive \
100+ ${avcodec} ${avformat} ${avutil} ${swresample} \
101+ -Wl,--no-whole-archive"
102+ )
89103endif ()
90104
105+
91106# copy to teamspeak dir command stuff
92107set (COPY_DLL_TO_TEAMSPEAK_DIR TRUE CACHE BOOL "Copy the soundboard DLL to teamspeaks directory" )
93108if (COPY_DLL_TO_TEAMSPEAK_DIR)
0 commit comments