cmake: cleanup and link crashpad on mac

This commit is contained in:
itsmattkc
2021-04-02 15:28:59 +11:00
parent e6b8848ad7
commit 3b4ce00741
2 changed files with 145 additions and 93 deletions
+74 -79
View File
@@ -22,13 +22,22 @@ set(OLIVE_SOURCES
main.cpp
)
# Include resource files for specific platforms
if (WIN32)
set(OLIVE_RESOURCES
${OLIVE_RESOURCES}
packaging/windows/resources.rc
)
elseif(APPLE)
set(OLIVE_ICON packaging/macos/olive.icns)
set(OLIVE_RESOURCES
${OLIVE_RESOURCES}
${OLIVE_ICON}
)
endif()
# Add subdirectories, which will populate the above variables
add_subdirectory(audio)
add_subdirectory(cli)
add_subdirectory(codec)
@@ -36,6 +45,7 @@ add_subdirectory(common)
add_subdirectory(config)
add_subdirectory(dialog)
add_subdirectory(node)
add_subdirectory(packaging)
add_subdirectory(panel)
add_subdirectory(project)
add_subdirectory(render)
@@ -50,15 +60,6 @@ add_subdirectory(undo)
add_subdirectory(widget)
add_subdirectory(window)
if(APPLE)
set(OLIVE_ICON packaging/macos/olive.icns)
set(OLIVE_RESOURCES
${OLIVE_RESOURCES}
${OLIVE_ICON}
)
endif()
# Add translations
qt5_add_translation(OLIVE_QM_FILES ${OLIVE_TS_FILES})
@@ -80,16 +81,18 @@ add_executable(olive-editor
${OLIVE_RESOURCES}
)
if(APPLE)
set_target_properties(olive-editor PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macos/MacOSXBundleInfo.plist.in
MACOSX_BUNDLE_GUI_IDENTIFIER org.olivevideoeditor.Olive
MACOSX_BUNDLE_ICON_FILE olive.icns
RESOURCE "${OLIVE_ICON}"
OUTPUT_NAME "Olive"
)
endif()
# Set global definitions
target_compile_definitions(olive-editor PRIVATE ${OLIVE_DEFINITIONS})
# Set include directories
target_include_directories(
olive-editor
PRIVATE
${FFMPEG_INCLUDE_DIRS}
${OCIO_INCLUDE_DIRS}
${OIIO_INCLUDE_DIRS}
${OPENEXR_INCLUDES}
)
# Set compiler options
if(MSVC)
@@ -120,29 +123,6 @@ else()
)
endif()
if(UNIX AND NOT APPLE)
target_link_options(
olive-editor
PRIVATE
-rdynamic
)
endif()
# Set include directories
target_include_directories(
olive-editor
PRIVATE
${FFMPEG_INCLUDE_DIRS}
${OCIO_INCLUDE_DIRS}
${OIIO_INCLUDE_DIRS}
${OPENEXR_INCLUDES}
# HACK: Brew on macOS separates OpenEXR and IlmBase into two folders even though they seem to
# expect to be in one. This includes the IlmBase files as if they were in the same folders
# as the OpenEXR headers.
${ILMBASE_INCLUDES}/OpenEXR
)
# Set link libraries
target_link_libraries(
olive-editor
@@ -166,23 +146,44 @@ target_link_libraries(
${OPENEXR_LIBRARIES}
)
if (WIN32)
target_link_libraries(
olive-editor
PRIVATE
DbgHelp
# Set Mac-specific properties for application
if (APPLE)
set_target_properties(olive-editor PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/packaging/macos/MacOSXBundleInfo.plist.in
MACOSX_BUNDLE_GUI_IDENTIFIER org.olivevideoeditor.Olive
MACOSX_BUNDLE_ICON_FILE olive.icns
RESOURCE "${OLIVE_ICON}"
OUTPUT_NAME "Olive"
)
elseif (APPLE)
# Enables use of special functions for slider dragging
if (NOT GoogleCrashpad_FOUND)
target_link_libraries(
olive-editor
PRIVATE
"-framework ApplicationServices"
)
endif()
# HACK: Brew on macOS separates OpenEXR and IlmBase into two folders even though they seem to
# expect to be in one. This includes the IlmBase files as if they were in the same folders
# as the OpenEXR headers. This would be better rolled into FindOpenEXR.cmake.
target_include_directories(
olive-editor
PRIVATE
${ILMBASE_INCLUDES}/OpenEXR
)
endif()
# Set Linux-specific properties for application
if(UNIX AND NOT APPLE)
install(TARGETS olive-editor RUNTIME DESTINATION bin)
endif()
# Enable OTIO if found
if (OpenTimelineIO_FOUND)
set(OLIVE_DEFINITIONS ${OLIVE_DEFINITIONS} USE_OTIO)
target_compile_definitions(olive-editor PRIVATE USE_OTIO)
target_include_directories(
olive-editor
@@ -197,55 +198,52 @@ if (OpenTimelineIO_FOUND)
)
endif()
if(UNIX AND NOT APPLE)
install(TARGETS olive-editor RUNTIME DESTINATION bin)
endif()
# Enable Crashpad if found
if (GoogleCrashpad_FOUND)
set(OLIVE_DEFINITIONS ${OLIVE_DEFINITIONS} USE_CRASHPAD)
# Signal code to use Crashpad
target_compile_definitions(
olive-editor
PRIVATE
USE_CRASHPAD
)
# Include Crashpad headers
target_include_directories(
olive-editor
PRIVATE
${CRASHPAD_INCLUDE_DIRS}
)
# Include Crashpad libs
target_link_libraries(
olive-editor
PRIVATE
${CRASHPAD_LIBRARIES}
)
set(OLIVE_CRASH_TARGET "olive-crashhandler")
set(OLIVE_CRASH_SOURCES
# Create crash handler executable
add_executable(
olive-crashhandler
dialog/crashhandler/crashhandler.h
dialog/crashhandler/crashhandler.cpp
dialog/crashhandler/crashhandlermain.cpp
)
if (WIN32)
add_executable(
${OLIVE_CRASH_TARGET}
WIN32
${OLIVE_CRASH_SOURCES}
# Disable console appearing on crash handler dialog
set_target_properties(olive-crashhandler PROPERTIES
WIN32_EXECUTABLE TRUE
)
else()
add_executable(
${OLIVE_CRASH_TARGET}
${OLIVE_CRASH_SOURCES}
)
endif()
# Set crash handler includes
target_include_directories(
${OLIVE_CRASH_TARGET}
olive-crashhandler
PRIVATE
${CRASHPAD_INCLUDE_DIRS}
)
# Set crash handler libs
target_link_libraries(
${OLIVE_CRASH_TARGET}
olive-crashhandler
PRIVATE
Qt5::Core
Qt5::Gui
@@ -254,32 +252,29 @@ if (GoogleCrashpad_FOUND)
${CRASHPAD_LIBRARIES}
)
target_compile_definitions(${OLIVE_CRASH_TARGET} PRIVATE ${OLIVE_DEFINITIONS})
# Set global Olive compiler definitions
target_compile_definitions(olive-crashhandler PRIVATE ${OLIVE_DEFINITIONS})
set(CRASHPAD_HANDLER "crashpad_handler${CMAKE_EXECUTABLE_SUFFIX}")
set(MINIDUMP_STACKWALK "minidump_stackwalk${CMAKE_EXECUTABLE_SUFFIX}")
if(UNIX AND NOT APPLE)
install(TARGETS ${OLIVE_CRASH_TARGET} RUNTIME DESTINATION bin)
install(TARGETS olive-crashhandler RUNTIME DESTINATION bin)
install(PROGRAMS ${CRASHPAD_LIBRARY_DIRS}/${CRASHPAD_HANDLER} DESTINATION bin)
install(PROGRAMS ${BREAKPAD_BIN_DIR}/${MINIDUMP_STACKWALK} DESTINATION bin)
endif()
if(APPLE)
# Move crash handler executables inside Mac app bundle
add_custom_command(TARGET ${OLIVE_CRASH_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OLIVE_CRASH_TARGET} $<TARGET_FILE_DIR:olive-editor>
add_custom_command(TARGET olive-crashhandler POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different olive-crashhandler $<TARGET_FILE_DIR:olive-editor>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CRASHPAD_LIBRARY_DIRS}/${CRASHPAD_HANDLER} $<TARGET_FILE_DIR:olive-editor>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BREAKPAD_BIN_DIR}/${MINIDUMP_STACKWALK} $<TARGET_FILE_DIR:olive-editor>
)
endif()
endif()
# Set compiler definitions
target_compile_definitions(olive-editor PRIVATE ${OLIVE_DEFINITIONS})
add_subdirectory(packaging)
# Create docs if doxygen was found
if(DOXYGEN_FOUND)
set(DOXYGEN_PROJECT_NAME "Olive")
set(DOXYGEN_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/docs")
+66 -9
View File
@@ -60,7 +60,6 @@ if (WIN32)
"out/Default"
)
elseif(UNIX)
# Assuming macOS works this way, don't actually know
find_path(CRASHPAD_LIBRARY_DIRS
obj/client/libclient.a
HINTS
@@ -77,8 +76,30 @@ set (_crashpad_components
client
util
third_party/mini_chromium/mini_chromium/base
compat
)
set (_crashpad_required
CRASHPAD_CLIENT_LIB
CRASHPAD_UTIL_LIB
CRASHPAD_BASE_LIB
BREAKPAD_BIN_DIR
CRASHPAD_BUILD_INCLUDE_DIR
CRASHPAD_CLIENT_INCLUDE_DIR
CRASHPAD_BASE_INCLUDE_DIR
)
if (WIN32 OR (UNIX AND NOT APPLE))
set (_crashpad_components
${_crashpad_components}
compat
)
set (_crashpad_required
${_crashpad_required}
CRASHPAD_COMPAT_LIB
)
endif()
foreach (COMPONENT ${_crashpad_components})
get_filename_component(SHORT_COMPONENT ${COMPONENT} NAME)
string(TOUPPER ${SHORT_COMPONENT} UPPER_COMPONENT)
@@ -92,6 +113,48 @@ foreach (COMPONENT ${_crashpad_components})
list(APPEND CRASHPAD_LIBRARIES ${CRASHPAD_${UPPER_COMPONENT}_LIB})
endforeach()
if (APPLE)
# macOS requires a bunch of extra loose object files that aren't made into static libraries
# See: https://groups.google.com/a/chromium.org/g/crashpad-dev/c/XVggc7kvlNs/m/msMjHS4KAQAJ
set (_crashpad_mach_loose_objects
child_portServer
#mach_excServer
child_portUser
#mach_excUser
excServer
notifyServer
excUser
notifyUser
)
foreach (COMPONENT ${_crashpad_mach_loose_objects})
string(TOUPPER ${COMPONENT} UPPER_COMPONENT)
set(LIB_NAME CRASHPAD_MACH_${UPPER_COMPONENT}_LIB)
find_file(${LIB_NAME}
NAMES
mig_output.${COMPONENT}.o
HINTS
"${CRASHPAD_LIBRARY_DIRS}/obj/out/Default/gen/util/mach"
)
set (_crashpad_required
${_crashpad_required}
${LIB_NAME}
)
list(APPEND CRASHPAD_LIBRARIES ${${LIB_NAME}})
endforeach()
list(APPEND CRASHPAD_LIBRARIES
bsm
"-framework IOKit"
"-framework Foundation"
"-framework Security"
"-framework CoreFoundation"
"-framework ApplicationServices"
)
endif()
# Find Breakpad's minidump_stackwalk
find_path(BREAKPAD_BIN_DIR
"minidump_stackwalk${CMAKE_EXECUTABLE_SUFFIX}"
@@ -105,13 +168,7 @@ PATH_SUFFIXES
find_package_handle_standard_args(GoogleCrashpad
REQUIRED_VARS
CRASHPAD_CLIENT_LIB
CRASHPAD_UTIL_LIB
CRASHPAD_BASE_LIB
BREAKPAD_BIN_DIR
CRASHPAD_BUILD_INCLUDE_DIR
CRASHPAD_CLIENT_INCLUDE_DIR
CRASHPAD_BASE_INCLUDE_DIR
${_crashpad_required}
)
if (UNIX AND NOT APPLE)