Skip to content

Commit

Permalink
macOS: fix FFMPEG 7.1 host compiler lacks C11 support issue on macOS
Browse files Browse the repository at this point in the history
  FFMPEG 7.1 introduces a new issue where "Host C11" testing fails due
  due to configure not being able to find system support libraries.
  A similar/related issue was fixed previously where --extra-cflags
  and --extra-ldflags needed to be set to point configure to the
  system includes and libraries.

  To resolve this, the host-cflags and host-ldflags options must be
  set to the same values as --extra-cflags and --extra-ldflags. The
  --host-cppflags and --extra-cxxflags were added for completeness.

  An additional update included searching the compiler for either
  Xcode or CommandLineTools as the user may have selected one or
  the other with xcode-select -s. In either case, the correct path
  to the respective SDK's is stored in OSX_SDK_ROOT, so use that path
  vs. the previous hard code.
  • Loading branch information
jhoyt4 authored and linuxdude42 committed Jan 16, 2025
1 parent 5b3b019 commit 0d25f55
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions cmake/platform/DarwinCustomization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ if(DETECT_MACPORTS EQUAL 0)
include_directories(AFTER SYSTEM "${MACPORTS_PREFIX}/include")

# FFmpeg needs a little help in finding the mp3lame library.
list(APPEND FF_PLATFORM_ARGS "--extra-ldflags=-L${MACPORTS_PREFIX}/lib"
"--extra-cflags=-I${MACPORTS_PREFIX}/include")
list(APPEND FF_C_CXX_FLAGS "-I${MACPORTS_PREFIX}/include")
list(APPEND FF_LD_FLAGS "-L${MACPORTS_PREFIX}/lib")

# Qt6 builds need a little help finding the libraries.
set(_QT_BASE "${MACPORTS_PREFIX}/libexec/${QT_PKG_NAME_LC}")
Expand All @@ -60,8 +60,8 @@ elseif(DETECT_HOMEBREW EQUAL 0)
include_directories(AFTER SYSTEM "${HOMEBREW_PREFIX}/include")

# FFmpeg needs a little help in finding the mp3lame library.
list(APPEND FF_PLATFORM_ARGS "--extra-ldflags=-L${HOMEBREW_PREFIX}/lib"
"--extra-cflags=-I${HOMEBREW_PREFIX}/include")
list(APPEND FF_C_CXX_FLAGS "-I${HOMEBREW_PREFIX}/include")
list(APPEND FF_LD_FLAGS "-L${HOMEBREW_PREFIX}/lib")

# Qt6 builds need a little help finding the libraries.
set(_QT_BASE "${HOMEBREW_PREFIX}/opt/${QT_PKG_NAME_LC}")
Expand Down Expand Up @@ -108,18 +108,36 @@ list(APPEND CMAKE_MODULE_PATH "${_QT_BASE}/lib/cmake")
# missing include files. The include file warnings are solved by the
# extra -I argument below.
# ~~~
if("${CMAKE_C_COMPILER}" MATCHES "Xcode")
#
# depending on if commandline tools are installed, the developer root
# may be /Applications/Xcode or /Library/Developer/CommandLineTools
# check for a compiler match in either, then use CMAKE_OSX_SYSROOT to path the
# correct system indlude, sysroot, syslibroot, and library search paths
if("${CMAKE_C_COMPILER}" MATCHES "Xcode" OR "${CMAKE_C_COMPILER}" MATCHES "CommandLineTools")
if(${CMAKE_C_COMPILER_VERSION} VERSION_GREATER_EQUAL 13)
# depending on if commandline tools are installed, the developer root
# may be /Applications/Xcode or /Library/Developer/CommandLineTools
message(STATUS "Adding Apple Clang '-lSystem' hack")
list(
APPEND
FF_PLATFORM_ARGS
"--extra-ldflags=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
)
list(
APPEND
FF_PLATFORM_ARGS
"--extra-cflags=-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
)

list(APPEND FF_C_CXX_FLAGS "-I${CMAKE_OSX_SYSROOT}/usr/include"
"-isysroot${CMAKE_OSX_SYSROOT}")

list(APPEND FF_LD_FLAGS "-L${CMAKE_OSX_SYSROOT}/usr/lib"
"-Wl,-syslibroot,${CMAKE_OSX_SYSROOT}")
endif()
endif()

# Loop over the added C and CXX flags adding flags for both
# extra and host for c and cxx/cpp inputs
foreach(FLAG IN LISTS FF_C_CXX_FLAGS)
list(APPEND FF_PLATFORM_ARGS "--extra-cflags=${FLAG}"
"--host-cflags=${FLAG}"
"--extra-cxxflags=${FLAG}"
"--host-cppflags=${FLAG}")
endforeach()

# Loop over the added LDFLAGS adding flags for both extra and host
foreach(FLAG IN LISTS FF_LD_FLAGS)
list(APPEND FF_PLATFORM_ARGS "--extra-ldflags=${FLAG}"
"--host-ldflags=${FLAG}")
endforeach()

0 comments on commit 0d25f55

Please sign in to comment.