this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement CMake function for circular shared library builds

+59
+59
cmake/darling_lib.cmake
··· 4 4 endif(COMMAND cmake_policy) 5 5 6 6 include(use_ld64) 7 + include(CMakeParseArguments) 7 8 8 9 FUNCTION(add_darling_library name) 9 10 foreach(f IN LISTS ARGN) ··· 36 37 COMPILE_FLAGS " -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ -arch i386 -arch x86_64") 37 38 ENDFUNCTION(make_fat) 38 39 40 + # add_circular(name ...) 41 + # 42 + # Creates a shared library with circular/mutual dependencies on other libraries. 43 + # 44 + # Typical use: circular dependencies between libs in /usr/lib/system 45 + # 46 + # Parameters: 47 + # * SOURCES: Sources to build the library from. This function will internally create an object library for them. 48 + # * OBJECTS: Object libraries to build the library from. (Because we cannot add object libraries into object libraries.) 49 + # * SIBLINGS: Which "circular" libraries we should link against in the final pass. 50 + # All specified libs must also be built with this function! 51 + # * STRONG_SIBLINGS: Which "circular" libraries we should link against in the 1st pass. 52 + # Only use for special cases, e.g. if this library reexports from this strong siblibg 53 + # and another sibling depends on this reexport's existence. 54 + # * DEPENDENCIES: Which standard libraries we should link against. 55 + # * LINK_FLAGS: Extra linker flags, e.g. an alias list 56 + FUNCTION(add_circular name) 57 + cmake_parse_arguments(CIRCULAR "FAT" "LINK_FLAGS" "SOURCES;OBJECTS;SIBLINGS;STRONG_SIBLINGS;DEPENDENCIES" ${ARGN}) 58 + #message(STATUS "${name} sources: ${CIRCULAR_SOURCES}") 59 + #message(STATUS "${name} siblings ${CIRCULAR_SIBLINGS}") 60 + #message(STATUS "${name} deps: ${CIRCULAR_DEPENDENCIES}") 61 + 62 + set(all_objects "${CIRCULAR_OBJECTS}") 63 + 64 + # First create an object library for all sources with the aim to avoid rebuild 65 + if (CIRCULAR_SOURCES) 66 + add_library("${name}_obj" OBJECT ${CIRCULAR_SOURCES}) 67 + if (CIRCULAR_FAT) 68 + make_fat("${name}_obj") 69 + endif (CIRCULAR_FAT) 70 + set(all_objects "${all_objects};$<TARGET_OBJECTS:${name}_obj>") 71 + endif (CIRCULAR_SOURCES) 72 + 73 + # Then create a shared Darling library, while ignoring all dependencies and using flat namespace 74 + add_darling_library("${name}_firstpass" SHARED ${all_objects})# $<TARGET_OBJECTS:${name}_obj> ${CIRCULAR_OBJECTS}) 75 + set_property(TARGET "${name}_firstpass" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS} -Wl,-flat_namespace -Wl,-undefined,suppress") 76 + 77 + foreach(dep ${CIRCULAR_STRONG_SIBLINGS}) 78 + target_link_libraries("${name}_firstpass" PRIVATE "${dep}_firstpass") 79 + endforeach(dep) 80 + 81 + if (CIRCULAR_FAT) 82 + make_fat("${name}_firstpass") 83 + endif (CIRCULAR_FAT) 84 + 85 + # Then build the final product while linking against firstpass libraries 86 + add_darling_library(${name} SHARED ${all_objects}) #$<TARGET_OBJECTS:${name}_obj> ${CIRCULAR_OBJECTS}) 87 + set_property(TARGET "${name}" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS}") 88 + 89 + foreach(dep ${CIRCULAR_SIBLINGS}) 90 + target_link_libraries("${name}" PRIVATE "${dep}_firstpass") 91 + endforeach(dep) 92 + target_link_libraries("${name}" PRIVATE ${CIRCULAR_DEPENDENCIES}) 93 + 94 + if (CIRCULAR_FAT) 95 + make_fat(${name}) 96 + endif (CIRCULAR_FAT) 97 + ENDFUNCTION(add_circular)