diff options
author | Tobias Kortkamp <tobik@FreeBSD.org> | 2018-04-10 11:00:00 +0200 |
---|---|---|
committer | Tobias Kortkamp <tobik@FreeBSD.org> | 2018-04-25 22:49:44 +0200 |
commit | e016be1bcd4a3ba37c73df21bec791671d5ae233 (patch) | |
tree | c7f86be6315b30c83c284d145531d0722662174e /cmake | |
parent | 9c62daa9c4c9a112cd1c1150eb4dfbaa616fc49d (diff) |
Fix find_soname when lld is the system linker
Signed-off-by: Tobias Kortkamp <tobik@FreeBSD.org>
Diffstat (limited to 'cmake')
-rw-r--r--[l---------] | cmake/scripts/freebsd/Macros.cmake | 96 |
1 files changed, 95 insertions, 1 deletions
diff --git a/cmake/scripts/freebsd/Macros.cmake b/cmake/scripts/freebsd/Macros.cmake index 2fdbb255f9..69edc9115d 120000..100644 --- a/cmake/scripts/freebsd/Macros.cmake +++ b/cmake/scripts/freebsd/Macros.cmake @@ -1 +1,95 @@ -../linux/Macros.cmake
\ No newline at end of file +function(core_link_library lib wraplib) + set(export -Wl,--unresolved-symbols=ignore-all + `cat ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/wrapper.def` + ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/dll-loader/exports/CMakeFiles/wrapper.dir/wrapper.c.o) + 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() + + # wrapper has to be adapted in order to support coverage. + if(CMAKE_BUILD_TYPE STREQUAL Coverage) + set(export "") + 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() + + string(REGEX REPLACE "[ ]+" ";" _flags "${CMAKE_SHARED_LINKER_FLAGS}") + get_filename_component(dir ${wraplib} DIRECTORY) + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX} + COMMAND ${CMAKE_COMMAND} -E make_directory ${dir} + COMMAND ${CMAKE_C_COMPILER} + ARGS ${_flags} -Wl,--whole-archive + "${link_lib}" ${extra_libs} + -Wl,--no-whole-archive -lm + -Wl,-soname,${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX} + -shared -o ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX} + ${export} + DEPENDS ${target} wrapper.def wrapper) + + get_filename_component(libname ${wraplib} NAME_WE) + add_custom_target(wrap_${libname} ALL DEPENDS ${CMAKE_BINARY_DIR}/${wraplib}-${ARCH}${CMAKE_SHARED_MODULE_SUFFIX}) + 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}${CMAKE_SHARED_MODULE_SUFFIX} 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() + if(IS_ABSOLUTE "${${lib}_LIBRARIES}") + set(link_lib "${${lib}_LIBRARIES}") + else() + set(link_lib -l${${lib}_LIBRARIES}) + endif() + endif() + execute_process(COMMAND ${CMAKE_C_COMPILER} -nostdlib -o /dev/null -Wl,-M ${link_lib} + COMMAND grep LOAD.*${liblow} + ERROR_QUIET + OUTPUT_VARIABLE ${lib}_FILENAME) + string(REPLACE "LOAD " "" ${lib}_FILENAME "${${lib}_FILENAME}") + string(STRIP "${${lib}_FILENAME}" ${lib}_FILENAME) + if(NOT ${lib}_FILENAME) + execute_process(COMMAND ${CMAKE_C_COMPILER} -nostdlib -o /dev/null -Wl,-t ${link_lib} + ERROR_QUIET + OUTPUT_VARIABLE _TMP_FILENAME) + string(REGEX MATCH ".*lib${liblow}.so" ${lib}_FILENAME ${_TMP_FILENAME}) + endif() + if(${lib}_FILENAME) + execute_process(COMMAND ${CMAKE_OBJDUMP} -p ${${lib}_FILENAME} + COMMAND grep SONAME.*${liblow} + ERROR_QUIET + OUTPUT_VARIABLE ${lib}_SONAME) + string(REPLACE "SONAME " "" ${lib}_SONAME ${${lib}_SONAME}) + string(STRIP ${${lib}_SONAME} ${lib}_SONAME) + if(VERBOSE) + message(STATUS "${lib} soname: ${${lib}_SONAME}") + endif() + set(${lib}_SONAME ${${lib}_SONAME} PARENT_SCOPE) + endif() + if(arg_REQUIRED AND NOT ${lib}_SONAME) + message(FATAL_ERROR "Could not find dynamically loadable library ${lib}") + endif() +endfunction() |