summaryrefslogtreecommitdiffstats
path: root/cmake/scripts/osx
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/scripts/osx')
-rw-r--r--cmake/scripts/osx/ArchSetup.cmake56
-rw-r--r--cmake/scripts/osx/ExtraTargets.cmake3
-rw-r--r--cmake/scripts/osx/Install.cmake73
-rw-r--r--cmake/scripts/osx/Macros.cmake119
-rw-r--r--cmake/scripts/osx/PathSetup.cmake32
5 files changed, 283 insertions, 0 deletions
diff --git a/cmake/scripts/osx/ArchSetup.cmake b/cmake/scripts/osx/ArchSetup.cmake
new file mode 100644
index 0000000..17f8583
--- /dev/null
+++ b/cmake/scripts/osx/ArchSetup.cmake
@@ -0,0 +1,56 @@
+if(NOT CMAKE_TOOLCHAIN_FILE)
+ message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE required for osx. See ${CMAKE_SOURCE_DIR}/cmake/README.md")
+endif()
+
+list(APPEND CORE_MAIN_SOURCE ${CMAKE_SOURCE_DIR}/xbmc/platform/darwin/osx/XBMCApplication.h)
+
+set(ARCH_DEFINES -DTARGET_POSIX -DTARGET_DARWIN -DTARGET_DARWIN_OSX)
+list(APPEND SYSTEM_DEFINES -D_REENTRANT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
+ -D__STDC_CONSTANT_MACROS)
+set(PLATFORM_DIR platform/darwin)
+set(PLATFORMDEFS_DIR platform/posix)
+set(CMAKE_SYSTEM_NAME Darwin)
+if(WITH_ARCH)
+ set(ARCH ${WITH_ARCH})
+else()
+ if(CPU STREQUAL x86_64 OR CPU STREQUAL i386)
+ set(ARCH x86-osx)
+ set(NEON False)
+ elseif(CPU STREQUAL arm64)
+ set(ARCH aarch64)
+ else()
+ message(SEND_ERROR "Unknown CPU: ${CPU}")
+ endif()
+endif()
+
+# m1 macs can execute x86_64 code via rosetta
+if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" AND
+ CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
+ set(HOST_CAN_EXECUTE_TARGET TRUE)
+endif()
+
+set(CMAKE_OSX_ARCHITECTURES ${CPU})
+
+# Additional SYSTEM_DEFINES
+list(APPEND SYSTEM_DEFINES -DHAS_POSIX_NETWORK -DHAS_OSX_NETWORK -DHAS_ZEROCONF)
+
+list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${NATIVEPREFIX})
+
+list(APPEND DEPLIBS "-framework DiskArbitration" "-framework IOKit"
+ "-framework IOSurface" "-framework SystemConfiguration"
+ "-framework ApplicationServices" "-framework AppKit"
+ "-framework CoreAudio" "-framework AudioToolbox"
+ "-framework CoreGraphics" "-framework CoreMedia"
+ "-framework VideoToolbox" "-framework Security"
+ "-framework GameController" "-framework Speech"
+ "-framework AVFoundation")
+
+if(ARCH STREQUAL aarch64)
+ set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
+else()
+ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
+endif()
+set(CMAKE_XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME OFF)
+
+include(cmake/scripts/darwin/Macros.cmake)
+enable_arc()
diff --git a/cmake/scripts/osx/ExtraTargets.cmake b/cmake/scripts/osx/ExtraTargets.cmake
new file mode 100644
index 0000000..28c1e74
--- /dev/null
+++ b/cmake/scripts/osx/ExtraTargets.cmake
@@ -0,0 +1,3 @@
+# XBMCHelper
+add_subdirectory(${CMAKE_SOURCE_DIR}/tools/EventClients/Clients/OSXRemote build/XBMCHelper)
+add_dependencies(${APP_NAME_LC} XBMCHelper)
diff --git a/cmake/scripts/osx/Install.cmake b/cmake/scripts/osx/Install.cmake
new file mode 100644
index 0000000..b4c4cc8
--- /dev/null
+++ b/cmake/scripts/osx/Install.cmake
@@ -0,0 +1,73 @@
+# OSX packaging
+
+set(PACKAGE_OUTPUT_DIR ${CMAKE_BINARY_DIR}/build/${CORE_BUILD_CONFIG})
+
+configure_file(${CMAKE_SOURCE_DIR}/xbmc/platform/darwin/osx/Info.plist.in
+ ${CMAKE_BINARY_DIR}/xbmc/platform/darwin/osx/Info.plist @ONLY)
+execute_process(COMMAND perl -p -i -e "s/r####/${APP_SCMID}/" ${CMAKE_BINARY_DIR}/xbmc/platform/darwin/osx/Info.plist)
+
+# Create xcode target that allows to build binary-addons.
+if(CMAKE_GENERATOR MATCHES "Xcode")
+ if(ADDONS_TO_BUILD)
+ set(_addons "ADDONS=${ADDONS_TO_BUILD}")
+ endif()
+ add_custom_target(binary-addons
+ COMMAND $(MAKE) -C ${CMAKE_SOURCE_DIR}/tools/depends/target/binary-addons clean
+ COMMAND $(MAKE) -C ${CMAKE_SOURCE_DIR}/tools/depends/target/binary-addons VERBOSE=1 V=99
+ INSTALL_PREFIX="${CMAKE_BINARY_DIR}/addons" CROSS_COMPILING=yes ${_addons})
+ if(ENABLE_XCODE_ADDONBUILD)
+ add_dependencies(${APP_NAME_LC} binary-addons)
+ endif()
+ unset(_addons)
+endif()
+
+add_custom_target(bundle
+ COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${APP_NAME_LC}> ${PACKAGE_OUTPUT_DIR}/${APP_NAME}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/DllPaths_generated.h
+ ${CMAKE_BINARY_DIR}/xbmc/DllPaths_generated.h
+ COMMAND "ACTION=build"
+ "TARGET_BUILD_DIR=${PACKAGE_OUTPUT_DIR}"
+ "TARGET_NAME=${APP_NAME}.app"
+ "APP_NAME=${APP_NAME}"
+ "SRCROOT=${CMAKE_BINARY_DIR}"
+ ${CMAKE_SOURCE_DIR}/tools/darwin/Support/CopyRootFiles-osx.command
+ COMMAND "XBMC_DEPENDS=${DEPENDS_PATH}"
+ "TARGET_BUILD_DIR=${PACKAGE_OUTPUT_DIR}"
+ "TARGET_NAME=${APP_NAME}.app"
+ "APP_NAME=${APP_NAME}"
+ "FULL_PRODUCT_NAME=${APP_NAME}.app"
+ "SRCROOT=${CMAKE_BINARY_DIR}"
+ "PYTHON_VERSION=${PYTHON_VERSION}"
+ ${CMAKE_SOURCE_DIR}/tools/darwin/Support/copyframeworks-osx.command)
+set_target_properties(bundle PROPERTIES FOLDER "Build Utilities")
+add_dependencies(bundle ${APP_NAME_LC})
+
+configure_file(${CMAKE_SOURCE_DIR}/tools/darwin/packaging/osx/mkdmg-osx.sh.in
+ ${CMAKE_BINARY_DIR}/tools/darwin/packaging/osx/mkdmg-osx.sh @ONLY)
+
+string(TOLOWER ${CORE_BUILD_CONFIG} CORE_BUILD_CONFIG_LOWERCASED)
+if(${CORE_BUILD_CONFIG_LOWERCASED} STREQUAL "release")
+ set(ALLOW_DEBUGGER "false")
+else()
+ set(ALLOW_DEBUGGER "true")
+endif()
+configure_file(${CMAKE_SOURCE_DIR}/tools/darwin/packaging/osx/Kodi.entitlements.in
+ ${CMAKE_BINARY_DIR}/tools/darwin/packaging/osx/Kodi.entitlements @ONLY)
+
+add_custom_target(dmg
+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tools/darwin/packaging/osx/
+ ${CMAKE_BINARY_DIR}/tools/darwin/packaging/osx/
+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tools/darwin/packaging/media/osx/
+ ${CMAKE_BINARY_DIR}/tools/darwin/packaging/media/osx/
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tools/darwin/Support/Codesign.command
+ ${CMAKE_BINARY_DIR}/tools/darwin/packaging/osx/Codesign.command
+ COMMAND "CODESIGNING_FOLDER_PATH=${PACKAGE_OUTPUT_DIR}/${APP_NAME}.app"
+ "NOTARYTOOL_KEYCHAIN_PROFILE=${NOTARYTOOL_KEYCHAIN_PROFILE}"
+ "NOTARYTOOL_KEYCHAIN_PATH=${NOTARYTOOL_KEYCHAIN_PATH}"
+ "EXPANDED_CODE_SIGN_IDENTITY_NAME=${CODE_SIGN_IDENTITY}"
+ "PLATFORM_NAME=${PLATFORM}"
+ "XCODE_BUILDTYPE=${CMAKE_CFG_INTDIR}"
+ ./mkdmg-osx.sh ${CORE_BUILD_CONFIG_LOWERCASED}
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tools/darwin/packaging/osx)
+set_target_properties(dmg PROPERTIES FOLDER "Build Utilities")
+add_dependencies(dmg bundle)
diff --git a/cmake/scripts/osx/Macros.cmake b/cmake/scripts/osx/Macros.cmake
new file mode 100644
index 0000000..f81e218
--- /dev/null
+++ b/cmake/scripts/osx/Macros.cmake
@@ -0,0 +1,119 @@
+function(core_link_library lib wraplib)
+ if(CMAKE_GENERATOR MATCHES "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL Ninja)
+ set(wrapper_obj cores/dll-loader/exports/CMakeFiles/wrapper.dir/wrapper.c.o)
+ elseif(CMAKE_GENERATOR MATCHES "Xcode")
+ # CURRENT_VARIANT is an Xcode env var
+ # CPU is a project cmake var
+ # Xcode new build system (CMAKE_XCODE_BUILD_SYSTEM=12) requires the env var CURRENT_VARIANT to be passed WITHOUT brackets
+ # Xcode Legacy build system (CMAKE_XCODE_BUILD_SYSTEM=1) requires the env var CURRENT_VARIANT to be passed WITH brackets
+ if(CMAKE_XCODE_BUILD_SYSTEM STREQUAL 12)
+ set(wrapper_obj cores/dll-loader/exports/kodi.build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/wrapper.build/Objects-$CURRENT_VARIANT/${CPU}/wrapper.o)
+ else()
+ set(wrapper_obj cores/dll-loader/exports/kodi.build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/wrapper.build/Objects-$(CURRENT_VARIANT)/${CPU}/wrapper.o)
+ endif()
+ else()
+ message(FATAL_ERROR "Unsupported generator in core_link_library")
+ endif()
+
+ set(export -bundle -undefined dynamic_lookup -read_only_relocs suppress
+ -Wl,-alias_list,${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/wrapper.def
+ ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${wrapper_obj})
+ set(extension ${CMAKE_SHARED_MODULE_SUFFIX})
+ set(check_arg "")
+ if(TARGET ${lib})
+ set(target ${lib})
+ set(link_lib $<TARGET_FILE:${lib}>)
+ set(check_arg ${ARGV2})
+ set(data_arg ${ARGV3})
+
+ else()
+ set(target ${ARGV2})
+ set(link_lib ${lib})
+ set(check_arg ${ARGV3})
+ set(data_arg ${ARGV4})
+ endif()
+ if(check_arg STREQUAL export)
+ set(export ${export}
+ -Wl,--version-script=${ARGV3})
+ elseif(check_arg STREQUAL extras)
+ foreach(arg ${data_arg})
+ list(APPEND export ${arg})
+ endforeach()
+ elseif(check_arg STREQUAL archives)
+ set(extra_libs ${data_arg})
+ endif()
+ get_filename_component(dir ${wraplib} DIRECTORY)
+
+ # We can't simply pass the linker flags to the args section of the custom command
+ # because cmake will add quotes around it (and the linker will fail due to those).
+ # We need to do this handstand first ...
+ string(REPLACE " " ";" CUSTOM_COMMAND_ARGS_LDFLAGS ${CMAKE_SHARED_LINKER_FLAGS})
+
+ add_custom_command(OUTPUT ${wraplib}-${ARCH}${extension}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
+ COMMAND ${CMAKE_C_COMPILER}
+ ARGS ${CUSTOM_COMMAND_ARGS_LDFLAGS} ${export} -Wl,-force_load ${link_lib} ${extra_libs}
+ -o ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${extension}
+ DEPENDS ${target} wrapper.def wrapper)
+
+ get_filename_component(libname ${wraplib} NAME_WE)
+ add_custom_target(wrap_${libname} ALL DEPENDS ${wraplib}-${ARCH}${extension})
+ set_target_properties(wrap_${libname} PROPERTIES FOLDER lib/wrapped)
+ add_dependencies(${APP_NAME_LC}-libraries wrap_${libname})
+
+ set(LIBRARY_FILES ${LIBRARY_FILES} ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${extension} CACHE STRING "" FORCE)
+endfunction()
+
+function(find_soname lib)
+ cmake_parse_arguments(arg "REQUIRED" "" "" ${ARGN})
+
+ string(TOLOWER ${lib} liblow)
+ if(${lib}_LDFLAGS)
+ set(link_lib "${${lib}_LDFLAGS}")
+ else()
+ set(link_lib "${${lib}_LIBRARIES}")
+ endif()
+
+ execute_process(COMMAND ${CMAKE_C_COMPILER} -print-search-dirs
+ COMMAND fgrep libraries:
+ COMMAND sed "s/[^=]*=\\(.*\\)/\\1/"
+ COMMAND sed "s/:/ /g"
+ ERROR_QUIET
+ OUTPUT_VARIABLE cc_lib_path
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND echo ${link_lib}
+ COMMAND sed "s/-L[ ]*//g"
+ COMMAND sed "s/-l[^ ]*//g"
+ ERROR_QUIET
+ OUTPUT_VARIABLE env_lib_path
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ foreach(path ${cc_lib_path} ${env_lib_path})
+ if(IS_DIRECTORY ${path})
+ execute_process(COMMAND ls -- ${path}/lib${liblow}.dylib
+ ERROR_QUIET
+ OUTPUT_VARIABLE lib_file
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ else()
+ set(lib_file ${path})
+ endif()
+ if(lib_file)
+ # we want the path/name that is embedded in the dylib
+ execute_process(COMMAND otool -L ${lib_file}
+ COMMAND grep -v lib${liblow}.dylib
+ COMMAND grep ${liblow}
+ COMMAND awk "{V=1; print $V}"
+ ERROR_QUIET
+ OUTPUT_VARIABLE filename
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ get_filename_component(${lib}_SONAME "${filename}" NAME)
+ if(VERBOSE)
+ message(STATUS "${lib} soname: ${${lib}_SONAME}")
+ endif()
+ endif()
+ endforeach()
+ if(arg_REQUIRED AND NOT ${lib}_SONAME)
+ message(FATAL_ERROR "Could not find dynamically loadable library ${lib}")
+ endif()
+ set(${lib}_SONAME ${${lib}_SONAME} PARENT_SCOPE)
+endfunction()
diff --git a/cmake/scripts/osx/PathSetup.cmake b/cmake/scripts/osx/PathSetup.cmake
new file mode 100644
index 0000000..ddb4176
--- /dev/null
+++ b/cmake/scripts/osx/PathSetup.cmake
@@ -0,0 +1,32 @@
+if(NOT prefix)
+ set(prefix ${DEPENDS_PATH})
+endif()
+if(NOT exec_prefix)
+ set(exec_prefix ${prefix})
+endif()
+if(NOT libdir)
+ set(libdir ${prefix}/lib)
+endif()
+if(NOT bindir)
+ set(bindir ${prefix}/bin)
+endif()
+if(NOT includedir)
+ set(includedir ${prefix}/include)
+endif()
+if(NOT datarootdir)
+ set(datarootdir ${prefix}/share)
+endif()
+if(NOT datadir)
+ set(datadir ${datarootdir})
+endif()
+
+list(APPEND final_message "-- PATH config --")
+list(APPEND final_message "Prefix: ${prefix}")
+list(APPEND final_message "Libdir: ${libdir}")
+list(APPEND final_message "Bindir: ${bindir}")
+list(APPEND final_message "Includedir: ${includedir}")
+list(APPEND final_message "Datarootdir: ${datarootdir}")
+list(APPEND final_message "Datadir: ${datadir}")
+
+set(PATH_DEFINES -DBIN_INSTALL_PATH=\"${libdir}/${APP_NAME_LC}\"
+ -DINSTALL_PATH=\"${datarootdir}/${APP_NAME_LC}\")