Skip to content

Commit

Permalink
CMake: Fix MacOS GStreamer Linking
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Jan 16, 2025
1 parent 7c64ca3 commit 9b80812
Show file tree
Hide file tree
Showing 13 changed files with 751 additions and 65 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ elseif(MACOS)
set_target_properties(${PROJECT_NAME}
PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/deploy/mac/MacOSXBundleInfo.plist.in"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/deploy/macos/MacOSXBundleInfo.plist.in"
MACOSX_BUNDLE_BUNDLE_NAME "${CMAKE_PROJECT_NAME}"
MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "${QGC_APP_COPYRIGHT}"
Expand Down Expand Up @@ -541,8 +541,8 @@ install(
)

set(deploy_tool_options_arg "")
if(APPLE)
set(deploy_tool_options_arg -qmldir=${CMAKE_SOURCE_DIR}/src -hardened-runtime -timestamp -appstore-compliant)
if(MACOS)
set(deploy_tool_options_arg -qmldir=${CMAKE_SOURCE_DIR}/src -hardened-runtime -timestamp -appstore-compliant) # -dmg
endif()

qt_generate_deploy_qml_app_script(
Expand Down Expand Up @@ -595,6 +595,8 @@ if(LINUX)
elseif(WIN32)
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/CreateWinInstaller.cmake")
elseif(MACOS)
install(CODE "set(OSXRELOCATOR ${CMAKE_SOURCE_DIR}/deploy/macos/osxrelocator.py)")
install(CODE "set(TARGET_NAME ${QGC_APP_NAME})")
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/CreateMacDMG.cmake")
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/CreateCPackBundle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include(CreateCPackCommon)

set(CPACK_GENERATOR "BUNDLE")

set(QGC_INSTALLER_SOURCE "${CMAKE_SOURCE_DIR}/deploy/mac")
set(QGC_INSTALLER_SOURCE "${CMAKE_SOURCE_DIR}/deploy/macos")

set(CPACK_BUNDLE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_BUNDLE_PLIST "${QGC_INSTALLER_SOURCE}/MacOSXBundleInfo.plist.in")
Expand Down
2 changes: 1 addition & 1 deletion cmake/CreateCPackDMG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include(CreateCPackCommon)

set(CPACK_GENERATOR "DragNDrop")

set(QGC_INSTALLER_SOURCE "${CMAKE_SOURCE_DIR}/deploy/mac")
set(QGC_INSTALLER_SOURCE "${CMAKE_SOURCE_DIR}/deploy/macos")

set(CPACK_DMG_VOLUME_NAME ${CPACK_PACKAGE_FILE_NAME})
set(CPACK_DMG_FORMAT UDBZ)
Expand Down
146 changes: 110 additions & 36 deletions cmake/CreateMacDMG.cmake
Original file line number Diff line number Diff line change
@@ -1,48 +1,122 @@
include(CMakePrintHelpers)

message(STATUS "Creating Mac Bundle")

set(TARGET_NAME QGroundControl)
# set(TARGET_NAME QGroundControl)
set(BUNDLE_PATH ${CMAKE_BINARY_DIR}/staging/${TARGET_NAME}.app)
set(SYSTEM_FRAMEWORK_PATH /Library/Frameworks)
set(BUNDLE_FRAMEWORK_PATH staging/${TARGET_NAME}.app/Contents/Frameworks)

message(STATUS "Copy GStreamer framework into bundle")
file(COPY ${SYSTEM_FRAMEWORK_PATH}/GStreamer.framework DESTINATION ${BUNDLE_FRAMEWORK_PATH})
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/bin)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/etc)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/share)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/Headers)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/include)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/Commands)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/pkgconfig)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/glib-2.0)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/graphene-1.0)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gst-validate-launcher)
file(GLOB REMOVE_LIB_FILES ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/*.a)
file(REMOVE ${REMOVE_LIB_FILES})
file(GLOB REMOVE_LIB_FILES ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/*.la)
file(REMOVE ${REMOVE_LIB_FILES})
file(GLOB REMOVE_LIB_FILES ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/*.a)
file(REMOVE ${REMOVE_LIB_FILES})
file(GLOB REMOVE_LIB_FILES ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/*.la)
file(REMOVE ${REMOVE_LIB_FILES})
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/include)
file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/pkgconfig)
set(BUNDLE_FRAMEWORK_PATH ${BUNDLE_PATH}/Contents/Frameworks)

# execute_process(
# COMMAND ${CMAKE_SOURCE_DIR}/deploy/macos/prepare_gstreamer_framework.sh ${CMAKE_BINARY_DIR}/gstwork/ staging/${TARGET_NAME}.app ${TARGET_NAME}
# RESULT_VARIABLE GSTREAMER_FRAMEWORK_RESULT
# OUTPUT_VARIABLE GSTREAMER_FRAMEWORK_OUTPUT
# ERROR_VARIABLE GSTREAMER_FRAMEWORK_ERROR
# )

# cmake_print_variables(GSTREAMER_FRAMEWORK_RESULT GSTREAMER_FRAMEWORK_OUTPUT GSTREAMER_FRAMEWORK_ERROR)

# message(STATUS "Copy GStreamer framework into bundle")
# file(
# INSTALL "${SYSTEM_FRAMEWORK_PATH}/GStreamer.framework"
# DESTINATION "${BUNDLE_FRAMEWORK_PATH}"
# PATTERN "*.la" EXCLUDE
# PATTERN "*.a" EXCLUDE
# PATTERN "*/include" EXCLUDE
# PATTERN "*/Headers" EXCLUDE
# )
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/bin)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/etc)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/share)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/Headers)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/include)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/Commands)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/pkgconfig)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/glib-2.0)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/graphene-1.0)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gst-validate-launcher)
# file(GLOB REMOVE_LIB_FILES ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/*.a)
# file(REMOVE ${REMOVE_LIB_FILES})
# file(GLOB REMOVE_LIB_FILES ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/*.la)
# file(REMOVE ${REMOVE_LIB_FILES})
# file(GLOB REMOVE_LIB_FILES ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/*.a)
# file(REMOVE ${REMOVE_LIB_FILES})
# file(GLOB REMOVE_LIB_FILES ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/*.la)
# file(REMOVE ${REMOVE_LIB_FILES})
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/include)
# file(REMOVE_RECURSE ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0/pkgconfig)

# execute_process(COMMAND otool -L ${SYSTEM_FRAMEWORK_PATH}/GStreamer.framework/GStreamer)

# Fix up library paths to point into bundle
execute_process(COMMAND ln -sf ${BUNDLE_FRAMEWORK_PATH} ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/libexec/Frameworks)
execute_process(COMMAND install_name_tool -change ${SYSTEM_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/GStreamer @executable_path/../Frameworks/GStreamer.framework/Versions/1.0/lib/GStreamer staging/${TARGET_NAME}.app/Contents/MacOS/${TARGET_NAME})
# execute_process(
# COMMAND ln -sf ${BUNDLE_FRAMEWORK_PATH} ${BUNDLE_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/libexec
# )
# execute_process(
# COMMAND install_name_tool -id @executable_path/../Frameworks/GStreamer.framework/Versions/1.0/lib/GStreamer ${BUNDLE_PATH}/Contents/Frameworks/GStreamer.framework/Versions/1.0/GStreamer
# RESULT_VARIABLE GSTREAMER_FRAMEWORK_RESULT
# OUTPUT_VARIABLE GSTREAMER_FRAMEWORK_OUTPUT
# ERROR_VARIABLE GSTREAMER_FRAMEWORK_ERROR
# )
# execute_process(
# COMMAND install_name_tool -change ${SYSTEM_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/GStreamer @executable_path/../Frameworks/GStreamer.framework/Versions/1.0/lib/GStreamer ${BUNDLE_PATH}/Contents/MacOS/${TARGET_NAME}
# RESULT_VARIABLE GSTREAMER_FRAMEWORK_RESULT
# OUTPUT_VARIABLE GSTREAMER_FRAMEWORK_OUTPUT
# ERROR_VARIABLE GSTREAMER_FRAMEWORK_ERROR
# )

find_package(Python3 REQUIRED)
# set(OSXRELOCATOR ${CMAKE_SOURCE_DIR}/deploy/macos/osxrelocator.py)

execute_process(
COMMAND ${Python3_EXECUTABLE} ${OSXRELOCATOR} ${BUNDLE_PATH}/Contents/Frameworks/GStreamer.framework/Versions/Current/lib /Library/Frameworks/GStreamer.framework/ @executable_path/../Frameworks/GStreamer.framework/ -r
RESULT_VARIABLE PYTHON_RESULT
OUTPUT_VARIABLE PYTHON_OUTPUT
ERROR_VARIABLE PYTHON_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
cmake_print_variables(PYTHON_RESULT PYTHON_OUTPUT PYTHON_ERROR)

execute_process(
COMMAND ${Python3_EXECUTABLE} ${OSXRELOCATOR} ${BUNDLE_PATH}/Contents/Frameworks/GStreamer.framework/Versions/Current/libexec /Library/Frameworks/GStreamer.framework/ @executable_path/../../../../../GStreamer.framework/ -r
RESULT_VARIABLE PYTHON_RESULT
OUTPUT_VARIABLE PYTHON_OUTPUT
ERROR_VARIABLE PYTHON_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
cmake_print_variables(PYTHON_RESULT PYTHON_OUTPUT PYTHON_ERROR)

execute_process(
COMMAND ${Python3_EXECUTABLE} ${OSXRELOCATOR} ${BUNDLE_PATH}/Contents/Frameworks/GStreamer.framework/Versions/Current/bin /Library/Frameworks/GStreamer.framework/ @executable_path/../../../../GStreamer.framework/ -r
RESULT_VARIABLE PYTHON_RESULT
OUTPUT_VARIABLE PYTHON_OUTPUT
ERROR_VARIABLE PYTHON_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
cmake_print_variables(PYTHON_RESULT PYTHON_OUTPUT PYTHON_ERROR)

execute_process(
COMMAND ${Python3_EXECUTABLE} ${OSXRELOCATOR} ${BUNDLE_PATH}/Contents/MacOS /Library/Frameworks/GStreamer.framework/ @executable_path/../Frameworks/GStreamer.framework/ -r
RESULT_VARIABLE PYTHON_RESULT
OUTPUT_VARIABLE PYTHON_OUTPUT
ERROR_VARIABLE PYTHON_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
cmake_print_variables(PYTHON_RESULT PYTHON_OUTPUT PYTHON_ERROR)

execute_process(COMMAND otool -L ${BUNDLE_PATH}/Contents/MacOS/${TARGET_NAME})

# include(BundleUtilities)
# include(CMakePrintHelpers)

# fixup_bundle("${CMAKE_BINARY_DIR}/staging/${TARGET_NAME}.app" "" "${SYSTEM_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/GStreamer")
# verify_app("${CMAKE_BINARY_DIR}/staging/${TARGET_NAME}.app")
# verify_bundle_prerequisites("${CMAKE_BINARY_DIR}/staging/${TARGET_NAME}.app" VERIFY_BUNDLE_PREREQS_RESULT VERIFY_BUNDLE_PREREQS_INFO)
# fixup_bundle("${BUNDLE_PATH}" "" "${SYSTEM_FRAMEWORK_PATH}/GStreamer.framework/Versions/1.0/lib/GStreamer")
# verify_app("${BUNDLE_PATH}")
# verify_bundle_prerequisites("${BUNDLE_PATH}" VERIFY_BUNDLE_PREREQS_RESULT VERIFY_BUNDLE_PREREQS_INFO)
# cmake_print_variables(VERIFY_BUNDLE_PREREQS_RESULT VERIFY_BUNDLE_PREREQS_INFO)
# verify_bundle_symlinks("${CMAKE_BINARY_DIR}/staging/${TARGET_NAME}.app" VERIFY_BUNDLE_SYMLINKS_RESULT VERIFY_BUNDLE_SYMLINKS_INFO)
# verify_bundle_symlinks("${BUNDLE_PATH}" VERIFY_BUNDLE_SYMLINKS_RESULT VERIFY_BUNDLE_SYMLINKS_INFO)
# cmake_print_variables(VERIFY_BUNDLE_SYMLINKS_RESULT VERIFY_BUNDLE_SYMLINKS_INFO)

message(STATUS "Creating Mac DMG")
file(REMOVE_RECURSE package)
file(MAKE_DIRECTORY package)
file(COPY staging/${TARGET_NAME}.app DESTINATION package)
execute_process(COMMAND create-dmg --volname "${TARGET_NAME} Installer" "${TARGET_NAME}.dmg" "package/")
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/package)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/package)
file(COPY ${BUNDLE_PATH} DESTINATION ${CMAKE_BINARY_DIR}/package)
execute_process(COMMAND create-dmg --volname "${TARGET_NAME}" "${TARGET_NAME}.dmg" "${CMAKE_BINARY_DIR}/package/")
9 changes: 2 additions & 7 deletions cmake/CustomOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ option(QGC_UTM_ADAPTER "Enable UTM Adapter" OFF)
option(QGC_VIEWER3D "Enable Viewer3D" ON) # Qt6Quick3D_FOUND

option(QGC_ENABLE_UVC "Enable UVC Devices" ON) # Qt6Multimedia_FOUND
if(APPLE AND NOT IOS)
# Still haven't figured out how to package GStreamer with the app.
option(QGC_ENABLE_GST_VIDEOSTREAMING "Enable GStreamer Video Backend" OFF)
else()
option(QGC_ENABLE_GST_VIDEOSTREAMING "Enable GStreamer Video Backend" ON)
endif()
option(QGC_ENABLE_GST_VIDEOSTREAMING "Enable GStreamer Video Backend" ON)
option(QGC_ENABLE_QT_VIDEOSTREAMING "Enable QtMultimedia Video Backend" OFF) # Qt6Multimedia_FOUND

set(QGC_MAVLINK_GIT_REPO "https://github.com/mavlink/c_library_v2.git" CACHE STRING "URL to MAVLink Git Repo")
Expand All @@ -38,7 +33,7 @@ set(QGC_ANDROID_PACKAGE_NAME "org.mavlink.qgroundcontrol" CACHE STRING "Android

# MacOS
set(QGC_BUNDLE_ID "org.qgroundcontrol.QGroundControl" CACHE STRING "MacOS Bundle ID") # MACOS
set(QGC_MACOS_ICON_PATH "${CMAKE_SOURCE_DIR}/deploy/mac" CACHE PATH "MacOS Icon Path") # MACOS
set(QGC_MACOS_ICON_PATH "${CMAKE_SOURCE_DIR}/deploy/macos" CACHE PATH "MacOS Icon Path") # MACOS

# APM
option(QGC_DISABLE_APM_MAVLINK "Disable APM Dialect" OFF)
Expand Down
7 changes: 6 additions & 1 deletion cmake/find-modules/FindGStreamer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ if(WIN32)
)
elseif(MACOS)
list(APPEND CMAKE_FRAMEWORK_PATH "/Library/Frameworks")
set(GSTREAMER_PREFIX "/Library/Frameworks/GStreamer.framework/Versions/1.0")
set(GSTREAMER_FRAMEWORK_PATH "/Library/Frameworks/GStreamer.framework" CACHE PATH "GStreamer Framework Path")
set(GSTREAMER_PREFIX "${GSTREAMER_FRAMEWORK_PATH}/Versions/1.0")
find_program(PKG_CONFIG_PROGRAM pkg-config PATHS ${GSTREAMER_PREFIX}/bin NO_DEFAULT_PATH)
if(PKG_CONFIG_PROGRAM)
set(PKG_CONFIG_EXECUTABLE ${PKG_CONFIG_PROGRAM})
Expand Down Expand Up @@ -668,6 +669,10 @@ target_include_directories(GStreamer::GStreamer

target_link_directories(GStreamer::GStreamer INTERFACE ${GSTREAMER_LIB_PATH})

if(MACOS AND EXISTS ${GSTREAMER_FRAMEWORK_PATH})
target_link_libraries(GStreamer::GStreamer INTERFACE "-F /Library/Frameworks -framework GStreamer")
endif()

################################################################################

# TODO: https://gstreamer.freedesktop.org/documentation/qt6d3d11/index.html#qml6d3d11sink-page
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9b80812

Please sign in to comment.