macOS: bundle and statically link external dependencies.

This fixes numerous linking issues where updated system libraries
on macOS cause errors on startup in newer OS versions.
pull/252/merge
whitequark 2018-07-12 11:10:25 +00:00
parent 03e479eb25
commit f37881a2e3
4 changed files with 52 additions and 58 deletions

View File

@ -99,22 +99,29 @@ if(ENABLE_SANITIZERS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}")
endif()
# dependencies
# common dependencies
if(APPLE)
set(CMAKE_FIND_FRAMEWORK LAST)
endif()
message(STATUS "Using in-tree libdxfrw")
add_subdirectory(extlib/libdxfrw)
if(WIN32)
if(WIN32 OR APPLE)
# On Win32 and macOS we use vendored packages, since there is little to no benefit
# to trying to find system versions. In particular, trying to link to libraries from
# Homebrew or macOS system libraries into the .app file is highly likely to result
# in incompatibilities after upgrades.
include(FindVendoredPackage)
include(AddVendoredSubdirectory)
find_vendored_package(Freetype freetype
WITH_ZLIB OFF
WITH_BZip2 OFF
WITH_PNG OFF
WITH_HarfBuzz OFF
FREETYPE_LIBRARY freetype
FREETYPE_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extlib/freetype/include)
if(APPLE)
set(FORCE_VENDORED_ZLIB ON)
set(FORCE_VENDORED_PNG ON)
set(FORCE_VENDORED_Freetype ON)
endif()
find_vendored_package(ZLIB zlib
ZLIB_LIBRARY zlibstatic
@ -127,6 +134,14 @@ if(WIN32)
PNG_PNG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/extlib/libpng)
list(APPEND PNG_PNG_INCLUDE_DIR ${CMAKE_BINARY_DIR}/extlib/libpng)
find_vendored_package(Freetype freetype
WITH_ZLIB OFF
WITH_BZip2 OFF
WITH_PNG OFF
WITH_HarfBuzz OFF
FREETYPE_LIBRARY freetype
FREETYPE_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extlib/freetype/include)
message(STATUS "Using in-tree pixman")
add_vendored_subdirectory(extlib/pixman)
set(PIXMAN_FOUND YES)
@ -140,8 +155,24 @@ if(WIN32)
set(CAIRO_LIBRARIES cairo)
set(CAIRO_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extlib/cairo/src)
list(APPEND CAIRO_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/extlib/cairo/src)
else()
# On Linux and BSDs we're a good citizen and link to system libraries.
if(ENABLE_GUI)
find_package(PkgConfig REQUIRED)
find_package(Backtrace)
find_package(SpaceWare)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
find_package(Freetype REQUIRED)
pkg_check_modules(CAIRO REQUIRED cairo)
endif()
# GUI dependencies
if(ENABLE_GUI)
if(WIN32)
if(OPENGL STREQUAL "3")
message(STATUS "Using in-tree ANGLE")
set(ANGLE_STATIC ON CACHE INTERNAL "")
@ -166,33 +197,10 @@ if(WIN32)
set(SPACEWARE_LIBRARIES
"${CMAKE_SOURCE_DIR}/extlib/si/siapp.lib")
endif()
endif()
elseif(APPLE)
set(CMAKE_FIND_FRAMEWORK LAST)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
find_package(Freetype REQUIRED)
find_library(CAIRO_LIBRARIES cairo REQUIRED)
find_path(CAIRO_INCLUDE_DIRS cairo.h PATH_SUFFIXES cairo)
if(ENABLE_GUI)
elseif(APPLE)
find_package(OpenGL REQUIRED)
find_library(APPKIT_LIBRARY AppKit REQUIRED)
endif()
else() # Linux and compatible systems
find_package(PkgConfig REQUIRED)
find_package(Backtrace)
find_package(SpaceWare)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
find_package(Freetype REQUIRED)
pkg_check_modules(CAIRO REQUIRED cairo)
if(ENABLE_GUI)
else()
find_package(OpenGL REQUIRED)
pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
pkg_check_modules(JSONC REQUIRED json-c)
@ -200,6 +208,8 @@ else() # Linux and compatible systems
endif()
endif()
# code coverage
if(ENABLE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
find_program(GCOV gcov)
@ -220,6 +230,8 @@ if(ENABLE_COVERAGE)
endif()
endif()
# translations
find_program(XGETTEXT xgettext)
find_program(MSGINIT msginit)
find_program(MSGMERGE msgmerge)
@ -294,7 +306,7 @@ if(ENABLE_COVERAGE)
set(COVERAGE_LIBRARY --coverage)
endif()
# components
# application components
add_subdirectory(res)
add_subdirectory(src)

View File

@ -14,7 +14,9 @@
include(DisableWarnings)
function(find_vendored_package PKG_NAME PKG_PATH)
find_package(${PKG_NAME})
if(NOT FORCE_VENDORED_${PKG_NAME})
find_package(${PKG_NAME})
endif()
set(cfg_name)
foreach(item ${ARGN})

@ -1 +1 @@
Subproject commit 5561dfc3f7e992454076ff3f10a0554c6b407e19
Subproject commit 127f1a7ad3eb88f7e74c83f89590fa8ee76853ae

View File

@ -118,10 +118,6 @@ elseif(APPLE)
platform/cocoamain.mm
render/rendergl.cpp
${gl_SOURCES})
set(platform_BUNDLED_LIBS
${PNG_LIBRARIES}
${FREETYPE_LIBRARIES})
else()
set(platform_SOURCES
platform/gtkmain.cpp
@ -398,22 +394,6 @@ if(APPLE)
COMMENT "Bundling executable solvespace-cli"
VERBATIM)
foreach(lib ${platform_BUNDLED_LIBS})
get_filename_component(name ${lib} NAME)
execute_process(COMMAND otool -D ${lib}
OUTPUT_VARIABLE canonical_lib OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "^.+:\n" "" canonical_lib ${canonical_lib})
add_custom_command(TARGET ${bundle} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${lib} ${bundle_bin}/${name}
COMMAND install_name_tool -change ${canonical_lib} @executable_path/${name}
$<TARGET_FILE:${bundle}>
COMMAND install_name_tool -change ${canonical_lib} @executable_path/${name}
$<TARGET_FILE:solvespace-cli>
COMMENT "Bundling shared library ${lib}"
VERBATIM)
endforeach()
add_custom_command(OUTPUT ${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg
COMMAND ${CMAKE_COMMAND} -E remove ${EXECUTABLE_OUTPUT_PATH}/${bundle}.dmg
COMMAND hdiutil create -srcfolder ${EXECUTABLE_OUTPUT_PATH}/${bundle}.app