summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/osx/Macros.cmake
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2016-11-24 21:27:41 +0100
committermanuel <manuel@mausz.at>2016-11-24 21:27:41 +0100
commit8cdf8dec703d882b46ca50a769fabb95ffc48e2c (patch)
treef7fe8233508f79d3dc94f8f445ce6342e7dfbdbb /project/cmake/scripts/osx/Macros.cmake
parent5823b05feb29a59510c32a9c28ca18b50b9b6399 (diff)
downloadkodi-pvr-build-8cdf8dec703d882b46ca50a769fabb95ffc48e2c.tar.gz
kodi-pvr-build-8cdf8dec703d882b46ca50a769fabb95ffc48e2c.tar.bz2
kodi-pvr-build-8cdf8dec703d882b46ca50a769fabb95ffc48e2c.zip
sync with upstream
Diffstat (limited to 'project/cmake/scripts/osx/Macros.cmake')
-rw-r--r--project/cmake/scripts/osx/Macros.cmake111
1 files changed, 111 insertions, 0 deletions
diff --git a/project/cmake/scripts/osx/Macros.cmake b/project/cmake/scripts/osx/Macros.cmake
new file mode 100644
index 0000000..0d04439
--- /dev/null
+++ b/project/cmake/scripts/osx/Macros.cmake
@@ -0,0 +1,111 @@
1function(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)/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 -read_only_relocs suppress
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 else()
21 set(target ${ARGV2})
22 set(link_lib ${lib})
23 set(check_arg ${ARGV3})
24 set(data_arg ${ARGV4})
25 endif()
26 if(check_arg STREQUAL export)
27 set(export ${export}
28 -Wl,--version-script=${ARGV3})
29 elseif(check_arg STREQUAL extras)
30 foreach(arg ${data_arg})
31 list(APPEND export ${arg})
32 endforeach()
33 elseif(check_arg STREQUAL archives)
34 set(extra_libs ${data_arg})
35 endif()
36 get_filename_component(dir ${wraplib} DIRECTORY)
37
38 # We can't simply pass the linker flags to the args section of the custom command
39 # because cmake will add quotes around it (and the linker will fail due to those).
40 # We need to do this handstand first ...
41 string(REPLACE " " ";" CUSTOM_COMMAND_ARGS_LDFLAGS ${CMAKE_SHARED_LINKER_FLAGS})
42
43 add_custom_command(OUTPUT ${wraplib}-${ARCH}${extension}
44 COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
45 COMMAND ${CMAKE_C_COMPILER}
46 ARGS ${CUSTOM_COMMAND_ARGS_LDFLAGS} ${export} -Wl,-force_load ${link_lib} ${extra_libs}
47 -o ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${extension}
48 DEPENDS ${target} wrapper.def wrapper
49 VERBATIM)
50
51 get_filename_component(libname ${wraplib} NAME_WE)
52 add_custom_target(wrap_${libname} ALL DEPENDS ${wraplib}-${ARCH}${extension})
53 set_target_properties(wrap_${libname} PROPERTIES FOLDER lib/wrapped)
54 add_dependencies(${APP_NAME_LC}-libraries wrap_${libname})
55
56 set(LIBRARY_FILES ${LIBRARY_FILES} ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${extension} CACHE STRING "" FORCE)
57endfunction()
58
59function(find_soname lib)
60 cmake_parse_arguments(arg "REQUIRED" "" "" ${ARGN})
61
62 string(TOLOWER ${lib} liblow)
63 if(${lib}_LDFLAGS)
64 set(link_lib "${${lib}_LDFLAGS}")
65 else()
66 set(link_lib "${${lib}_LIBRARIES}")
67 endif()
68
69 execute_process(COMMAND ${CMAKE_C_COMPILER} -print-search-dirs
70 COMMAND fgrep libraries:
71 COMMAND sed "s/[^=]*=\\(.*\\)/\\1/"
72 COMMAND sed "s/:/ /g"
73 ERROR_QUIET
74 OUTPUT_VARIABLE cc_lib_path
75 OUTPUT_STRIP_TRAILING_WHITESPACE)
76 execute_process(COMMAND echo ${link_lib}
77 COMMAND sed "s/-L[ ]*//g"
78 COMMAND sed "s/-l[^ ]*//g"
79 ERROR_QUIET
80 OUTPUT_VARIABLE env_lib_path
81 OUTPUT_STRIP_TRAILING_WHITESPACE)
82
83 foreach(path ${cc_lib_path} ${env_lib_path})
84 if(IS_DIRECTORY ${path})
85 execute_process(COMMAND ls -- ${path}/lib${liblow}.dylib
86 ERROR_QUIET
87 OUTPUT_VARIABLE lib_file
88 OUTPUT_STRIP_TRAILING_WHITESPACE)
89 else()
90 set(lib_file ${path})
91 endif()
92 if(lib_file)
93 # we want the path/name that is embedded in the dylib
94 execute_process(COMMAND otool -L ${lib_file}
95 COMMAND grep -v lib${liblow}.dylib
96 COMMAND grep ${liblow}
97 COMMAND awk "{V=1; print $V}"
98 ERROR_QUIET
99 OUTPUT_VARIABLE filename
100 OUTPUT_STRIP_TRAILING_WHITESPACE)
101 get_filename_component(${lib}_SONAME "${filename}" NAME)
102 if(VERBOSE)
103 message(STATUS "${lib} soname: ${${lib}_SONAME}")
104 endif()
105 endif()
106 endforeach()
107 if(arg_REQUIRED AND NOT ${lib}_SONAME)
108 message(FATAL_ERROR "Could not find dynamically loadable library ${lib}")
109 endif()
110 set(${lib}_SONAME ${${lib}_SONAME} PARENT_SCOPE)
111endfunction()