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)
8 set(link_lib $<TARGET_FILE:${lib}>)
9 set(check_arg ${ARGV2})
10 set(data_arg ${ARGV3})
14 set(check_arg ${ARGV3})
15 set(data_arg ${ARGV4})
18 # wrapper has to be adapted in order to support coverage.
19 if(CMAKE_BUILD_TYPE STREQUAL Coverage)
23 if(check_arg STREQUAL export)
25 -Wl,--version-script=${ARGV3})
26 elseif(check_arg STREQUAL extras)
27 foreach(arg ${data_arg})
28 list(APPEND export ${arg})
30 elseif(check_arg STREQUAL archives)
31 set(extra_libs ${data_arg})
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}
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)
55 function(find_soname lib)
56 cmake_parse_arguments(arg "REQUIRED" "" "" ${ARGN})
58 string(TOLOWER ${lib} liblow)
60 set(link_lib "${${lib}_LDFLAGS}")
62 if(IS_ABSOLUTE "${${lib}_LIBRARIES}")
63 set(link_lib "${${lib}_LIBRARIES}")
65 set(link_lib -l${${lib}_LIBRARIES})
68 execute_process(COMMAND ${CMAKE_C_COMPILER} -nostdlib -o /dev/null -Wl,-M ${link_lib}
69 COMMAND grep LOAD.*${liblow}
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}
77 ERROR_VARIABLE _TMP_FILENAME)
78 string(REGEX MATCH ".*lib${liblow}.so" ${lib}_FILENAME ${_TMP_FILENAME})
81 execute_process(COMMAND ${CMAKE_OBJDUMP} -p ${${lib}_FILENAME}
82 COMMAND grep SONAME.*${liblow}
84 OUTPUT_VARIABLE ${lib}_SONAME)
85 string(REPLACE "SONAME " "" ${lib}_SONAME ${${lib}_SONAME})
86 string(STRIP ${${lib}_SONAME} ${lib}_SONAME)
88 message(STATUS "${lib} soname: ${${lib}_SONAME}")
90 set(${lib}_SONAME ${${lib}_SONAME} PARENT_SCOPE)
92 if(arg_REQUIRED AND NOT ${lib}_SONAME)
93 message(FATAL_ERROR "Could not find dynamically loadable library ${lib}")