[video] Fix bookmark thumbnails of rotated videos
[xbmc.git] / cmake / scripts / linux / Macros.cmake
blob37243a77cdbc6711ffa2a6d1c4d7a8df6f336877
1 function(core_link_library lib wraplib)
2   set(export -Wl,--unresolved-symbols=ignore-all
3              `cat ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/wrapper.def`
4              ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/CMakeFiles/wrapper.dir/wrapper.c.o)
5   set(check_arg "")
6   if(TARGET ${lib})
7     set(target ${lib})
8     set(link_lib $<TARGET_FILE:${lib}>)
9     set(check_arg ${ARGV2})
10     set(data_arg  ${ARGV3})
11   else()
12     set(target ${ARGV2})
13     set(link_lib ${lib})
14     set(check_arg ${ARGV3})
15     set(data_arg ${ARGV4})
16   endif()
18   # wrapper has to be adapted in order to support coverage.
19   if(CMAKE_BUILD_TYPE STREQUAL Coverage)
20     set(export "")
21   endif()
23   if(check_arg STREQUAL export)
24     set(export ${export}
25         -Wl,--version-script=${ARGV3})
26   elseif(check_arg STREQUAL extras)
27     foreach(arg ${data_arg})
28       list(APPEND export ${arg})
29     endforeach()
30   elseif(check_arg STREQUAL archives)
31     set(extra_libs ${data_arg})
32   endif()
34   string(REGEX REPLACE "[ ]+" ";" _flags "${CMAKE_SHARED_LINKER_FLAGS}")
35   get_filename_component(dir ${wraplib} DIRECTORY)
36   add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX}
37                      COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
38                      COMMAND ${CMAKE_C_COMPILER}
39                      ARGS    ${_flags} -Wl,--whole-archive
40                              "${link_lib}" ${extra_libs}
41                              -Wl,--no-whole-archive -lm
42                              -Wl,-soname,${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX}
43                              -shared -o ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX}
44                              ${export}
45                      DEPENDS ${target} wrapper.def wrapper)
47   get_filename_component(libname ${wraplib} NAME_WE)
48   add_custom_target(wrap_${libname} ALL DEPENDS ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX})
49   set_target_properties(wrap_${libname} PROPERTIES FOLDER lib/wrapped)
50   add_dependencies(${APP_NAME_LC}-libraries wrap_${libname})
52   set(LIBRARY_FILES ${LIBRARY_FILES} ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX} CACHE STRING "" FORCE)
53 endfunction()
55 function(find_soname lib)
56   cmake_parse_arguments(arg "REQUIRED" "" "" ${ARGN})
58   string(TOLOWER ${lib} liblow)
59   if(${lib}_LDFLAGS)
60     set(link_lib "${${lib}_LDFLAGS}")
61   else()
62     if(IS_ABSOLUTE "${${lib}_LIBRARIES}")
63       set(link_lib "${${lib}_LIBRARIES}")
64     else()
65       set(link_lib -l${${lib}_LIBRARIES})
66     endif()
67   endif()
68   execute_process(COMMAND ${CMAKE_C_COMPILER} -nostdlib -o /dev/null -Wl,-M ${link_lib}
69                   COMMAND grep LOAD.*${liblow}
70                   ERROR_QUIET
71                   OUTPUT_VARIABLE ${lib}_FILENAME)
72   string(REPLACE "LOAD " "" ${lib}_FILENAME "${${lib}_FILENAME}")
73   string(STRIP "${${lib}_FILENAME}" ${lib}_FILENAME)
74   if(NOT ${lib}_FILENAME)
75     execute_process(COMMAND ${CMAKE_C_COMPILER} -nostdlib -o /dev/null -Wl,-t ${link_lib}
76                     OUTPUT_QUIET
77                     ERROR_VARIABLE _TMP_FILENAME)
78     string(REGEX MATCH ".*lib${liblow}.so" ${lib}_FILENAME ${_TMP_FILENAME})
79   endif()
80   if(${lib}_FILENAME)
81     execute_process(COMMAND ${CMAKE_OBJDUMP} -p ${${lib}_FILENAME}
82                     COMMAND grep SONAME.*${liblow}
83                     ERROR_QUIET
84                     OUTPUT_VARIABLE ${lib}_SONAME)
85     string(REPLACE "SONAME " "" ${lib}_SONAME ${${lib}_SONAME})
86     string(STRIP ${${lib}_SONAME} ${lib}_SONAME)
87     if(VERBOSE)
88       message(STATUS "${lib} soname: ${${lib}_SONAME}")
89     endif()
90     set(${lib}_SONAME ${${lib}_SONAME} PARENT_SCOPE)
91   endif()
92   if(arg_REQUIRED AND NOT ${lib}_SONAME)
93     message(FATAL_ERROR "Could not find dynamically loadable library ${lib}")
94   endif()
95 endfunction()