diff options
Diffstat (limited to 'cmake/scripts/darwin_embedded/Macros.cmake')
| -rw-r--r-- | cmake/scripts/darwin_embedded/Macros.cmake | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/cmake/scripts/darwin_embedded/Macros.cmake b/cmake/scripts/darwin_embedded/Macros.cmake new file mode 100644 index 0000000..91f2d86 --- /dev/null +++ b/cmake/scripts/darwin_embedded/Macros.cmake | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | function(core_link_library lib wraplib) | ||
| 2 | if(CMAKE_GENERATOR MATCHES "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL Ninja) | ||
| 3 | set(wrapper_obj cores/dll-loader/exports/CMakeFiles/wrapper.dir/wrapper.c.o) | ||
| 4 | elseif(CMAKE_GENERATOR MATCHES "Xcode") | ||
| 5 | set(wrapper_obj cores/dll-loader/exports/kodi.build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/wrapper.build/Objects-$(CURRENT_VARIANT)/$(CURRENT_ARCH)/wrapper.o) | ||
| 6 | else() | ||
| 7 | message(FATAL_ERROR "Unsupported generator in core_link_library") | ||
| 8 | endif() | ||
| 9 | |||
| 10 | set(export -bundle -undefined dynamic_lookup | ||
| 11 | -Wl,-alias_list,${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/wrapper.def | ||
| 12 | ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${wrapper_obj}) | ||
| 13 | set(extension ${CMAKE_SHARED_MODULE_SUFFIX}) | ||
| 14 | set(check_arg "") | ||
| 15 | if(TARGET ${lib}) | ||
| 16 | set(target ${lib}) | ||
| 17 | set(link_lib $<TARGET_FILE:${lib}>) | ||
| 18 | set(check_arg ${ARGV2}) | ||
| 19 | set(data_arg ${ARGV3}) | ||
| 20 | |||
| 21 | # iOS: EFFECTIVE_PLATFORM_NAME is not resolved | ||
| 22 | # http://public.kitware.com/pipermail/cmake/2016-March/063049.html | ||
| 23 | if(CORE_SYSTEM_NAME STREQUAL darwin_embedded) | ||
| 24 | get_target_property(dir ${lib} BINARY_DIR) | ||
| 25 | set(link_lib ${dir}/${CORE_BUILD_CONFIG}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}) | ||
| 26 | endif() | ||
| 27 | else() | ||
| 28 | set(target ${ARGV2}) | ||
| 29 | set(link_lib ${lib}) | ||
| 30 | set(check_arg ${ARGV3}) | ||
| 31 | set(data_arg ${ARGV4}) | ||
| 32 | endif() | ||
| 33 | if(check_arg STREQUAL export) | ||
| 34 | set(export ${export} | ||
| 35 | -Wl,--version-script=${ARGV3}) | ||
| 36 | elseif(check_arg STREQUAL extras) | ||
| 37 | foreach(arg ${data_arg}) | ||
| 38 | list(APPEND export ${arg}) | ||
| 39 | endforeach() | ||
| 40 | elseif(check_arg STREQUAL archives) | ||
| 41 | set(extra_libs ${data_arg}) | ||
| 42 | endif() | ||
| 43 | get_filename_component(dir ${wraplib} DIRECTORY) | ||
| 44 | |||
| 45 | # We can't simply pass the linker flags to the args section of the custom command | ||
| 46 | # because cmake will add quotes around it (and the linker will fail due to those). | ||
| 47 | # We need to do this handstand first ... | ||
| 48 | string(REPLACE " " ";" CUSTOM_COMMAND_ARGS_LDFLAGS ${CMAKE_SHARED_LINKER_FLAGS}) | ||
| 49 | |||
| 50 | add_custom_command(OUTPUT ${wraplib}-${ARCH}${extension} | ||
| 51 | COMMAND ${CMAKE_COMMAND} -E make_directory ${dir} | ||
| 52 | COMMAND ${CMAKE_C_COMPILER} | ||
| 53 | ARGS ${CUSTOM_COMMAND_ARGS_LDFLAGS} ${export} -Wl,-force_load ${link_lib} ${extra_libs} | ||
| 54 | -o ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${extension} | ||
| 55 | DEPENDS ${target} wrapper.def wrapper | ||
| 56 | VERBATIM) | ||
| 57 | |||
| 58 | get_filename_component(libname ${wraplib} NAME_WE) | ||
| 59 | add_custom_target(wrap_${libname} ALL DEPENDS ${wraplib}-${ARCH}${extension}) | ||
| 60 | set_target_properties(wrap_${libname} PROPERTIES FOLDER lib/wrapped) | ||
| 61 | add_dependencies(${APP_NAME_LC}-libraries wrap_${libname}) | ||
| 62 | |||
| 63 | set(LIBRARY_FILES ${LIBRARY_FILES} ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${extension} CACHE STRING "" FORCE) | ||
| 64 | endfunction() | ||
| 65 | |||
| 66 | function(find_soname lib) | ||
| 67 | cmake_parse_arguments(arg "REQUIRED" "" "" ${ARGN}) | ||
| 68 | |||
| 69 | string(TOLOWER ${lib} liblow) | ||
| 70 | if(${lib}_LDFLAGS) | ||
| 71 | set(link_lib "${${lib}_LDFLAGS}") | ||
| 72 | else() | ||
| 73 | set(link_lib "${${lib}_LIBRARIES}") | ||
| 74 | endif() | ||
| 75 | |||
| 76 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-search-dirs | ||
| 77 | COMMAND fgrep libraries: | ||
| 78 | COMMAND sed "s/[^=]*=\\(.*\\)/\\1/" | ||
| 79 | COMMAND sed "s/:/ /g" | ||
| 80 | ERROR_QUIET | ||
| 81 | OUTPUT_VARIABLE cc_lib_path | ||
| 82 | OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
| 83 | execute_process(COMMAND echo ${link_lib} | ||
| 84 | COMMAND sed "s/-L[ ]*//g" | ||
| 85 | COMMAND sed "s/-l[^ ]*//g" | ||
| 86 | ERROR_QUIET | ||
| 87 | OUTPUT_VARIABLE env_lib_path | ||
| 88 | OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
| 89 | |||
| 90 | foreach(path ${cc_lib_path} ${env_lib_path}) | ||
| 91 | if(IS_DIRECTORY ${path}) | ||
| 92 | execute_process(COMMAND ls -- ${path}/lib${liblow}.dylib | ||
| 93 | ERROR_QUIET | ||
| 94 | OUTPUT_VARIABLE lib_file | ||
| 95 | OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
| 96 | else() | ||
| 97 | set(lib_file ${path}) | ||
| 98 | endif() | ||
| 99 | if(lib_file) | ||
| 100 | # we want the path/name that is embedded in the dylib | ||
| 101 | execute_process(COMMAND otool -L ${lib_file} | ||
| 102 | COMMAND grep -v lib${liblow}.dylib | ||
| 103 | COMMAND grep ${liblow} | ||
| 104 | COMMAND awk "{V=1; print $V}" | ||
| 105 | ERROR_QUIET | ||
| 106 | OUTPUT_VARIABLE filename | ||
| 107 | OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
| 108 | get_filename_component(${lib}_SONAME "${filename}" NAME) | ||
| 109 | if(VERBOSE) | ||
| 110 | message(STATUS "${lib} soname: ${${lib}_SONAME}") | ||
| 111 | endif() | ||
| 112 | endif() | ||
| 113 | endforeach() | ||
| 114 | if(arg_REQUIRED AND NOT ${lib}_SONAME) | ||
| 115 | message(FATAL_ERROR "Could not find dynamically loadable library ${lib}") | ||
| 116 | endif() | ||
| 117 | set(${lib}_SONAME ${${lib}_SONAME} PARENT_SCOPE) | ||
| 118 | endfunction() | ||
