this repo has no description
at fixPythonPipStalling 190 lines 8.7 kB view raw
1if(COMMAND cmake_policy) 2 cmake_policy(SET CMP0003 NEW) 3 cmake_policy(SET CMP0011 NEW) 4endif(COMMAND cmake_policy) 5 6include(use_ld64) 7include(CMakeParseArguments) 8include(dsym) 9 10FUNCTION(add_darling_library name) 11 foreach(f IN LISTS ARGN) 12 set(files ${files} ${f}) 13 endforeach(f) 14 15 set(CMAKE_SKIP_RPATH TRUE) 16 add_library(${name} SHARED ${files}) 17 18 # Link using Apple's ld64 19 set_target_properties(${name} PROPERTIES 20 SUFFIX ".dylib" 21 NO_SONAME TRUE) 22 23 set_target_properties(${name} PROPERTIES PREFIX "lib") 24 25 set_property(TARGET ${name} APPEND_STRING PROPERTY 26 LINK_FLAGS " ${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") 27 28 if (DYLIB_INSTALL_NAME) 29 set_property(TARGET ${name} APPEND_STRING PROPERTY 30 LINK_FLAGS " -Wl,-dylib_install_name,${DYLIB_INSTALL_NAME} ") 31 endif (DYLIB_INSTALL_NAME) 32 if (DYLIB_COMPAT_VERSION) 33 set_property(TARGET ${name} APPEND_STRING PROPERTY 34 LINK_FLAGS " -Wl,-compatibility_version,${DYLIB_COMPAT_VERSION} ") 35 else (DYLIB_COMPAT_VERSION) 36 set_property(TARGET ${name} APPEND_STRING PROPERTY 37 LINK_FLAGS " -Wl,-compatibility_version,1.0.0 ") 38 endif (DYLIB_COMPAT_VERSION) 39 if (DYLIB_CURRENT_VERSION) 40 set_property(TARGET ${name} APPEND_STRING PROPERTY 41 LINK_FLAGS " -Wl,-current_version,${DYLIB_CURRENT_VERSION} ") 42 endif (DYLIB_CURRENT_VERSION) 43 44 set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/") 45 add_dependencies(${name} lipo) 46 47 if (BUILD_TARGET_64BIT AND NOT DARLING_LIB_32BIT_ONLY) 48 set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " -arch ${APPLE_ARCH_64BIT}") 49 set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -arch ${APPLE_ARCH_64BIT}") 50 endif (BUILD_TARGET_64BIT AND NOT DARLING_LIB_32BIT_ONLY) 51 if (BUILD_TARGET_32BIT AND NOT DARLING_LIB_64BIT_ONLY) 52 set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " -arch ${APPLE_ARCH_32BIT}") 53 set_property(TARGET ${name} APPEND_STRING PROPERTY LINK_FLAGS " -arch ${APPLE_ARCH_32BIT}") 54 endif (BUILD_TARGET_32BIT AND NOT DARLING_LIB_64BIT_ONLY) 55 56 use_ld64(${name}) 57 58 if ((NOT NO_DSYM) AND (NOT ${name}_NO_DSYM)) 59 dsym(${name}) 60 endif ((NOT NO_DSYM) AND (NOT ${name}_NO_DSYM)) 61ENDFUNCTION(add_darling_library) 62 63FUNCTION(make_fat) 64 if (BUILD_TARGET_32BIT AND BUILD_TARGET_64BIT) 65 set_property(TARGET ${ARGV} APPEND_STRING PROPERTY 66 COMPILE_FLAGS " -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ -arch ${APPLE_ARCH_32BIT} -arch ${APPLE_ARCH_64BIT}") 67 set_property(TARGET ${ARGV} APPEND_STRING PROPERTY 68 LINK_FLAGS " -arch ${APPLE_ARCH_32BIT} -arch ${APPLE_ARCH_64BIT}") 69 foreach(tgt ${ARGV}) 70 add_dependencies(${tgt} lipo) 71 endforeach(tgt) 72 elseif (BUILD_TARGET_32BIT) 73 set_property(TARGET ${ARGV} APPEND_STRING PROPERTY 74 COMPILE_FLAGS " -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ -arch ${APPLE_ARCH_32BIT}") 75 set_property(TARGET ${ARGV} APPEND_STRING PROPERTY 76 LINK_FLAGS " -arch ${APPLE_ARCH_32BIT}") 77 foreach(tgt ${ARGV}) 78 add_dependencies(${tgt} lipo) 79 endforeach(tgt) 80 elseif (BUILD_TARGET_64BIT) 81 set_property(TARGET ${ARGV} APPEND_STRING PROPERTY 82 COMPILE_FLAGS " -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/ -arch ${APPLE_ARCH_64BIT}") 83 set_property(TARGET ${ARGV} APPEND_STRING PROPERTY 84 LINK_FLAGS " -arch ${APPLE_ARCH_64BIT}") 85 foreach(tgt ${ARGV}) 86 add_dependencies(${tgt} lipo) 87 endforeach(tgt) 88 endif (BUILD_TARGET_32BIT AND BUILD_TARGET_64BIT) 89ENDFUNCTION(make_fat) 90 91# add_circular(name ...) 92# 93# Creates a shared library with circular/mutual dependencies on other libraries. 94# 95# Typical use: circular dependencies between libs in /usr/lib/system 96# 97# Parameters: 98# * SOURCES: Sources to build the library from. This function will internally create an object library for them. 99# * OBJECTS: Object libraries to build the library from. (Because we cannot add object libraries into object libraries.) 100# * SIBLINGS: Which "circular" libraries we should link against in the final pass. 101# All specified libs must also be built with this function! 102# * STRONG_SIBLINGS: Which "circular" libraries we should link against in the 1st pass. 103# Only use for special cases, e.g. if this library reexports from this strong siblibg 104# and another sibling depends on this reexport's existence. 105# * DEPENDENCIES: Which standard libraries we should link against. 106# * LINK_FLAGS: Extra linker flags, e.g. an alias list 107# * UPWARD: Add an upward dependency. This affects initialization order. The specified dependency will only be 108# loaded and initialized after the current library is fully loaded. This is needed to break 109# certain dependency issues, esp. if a libSystem sublibrary depends on a library that depends on libSystem 110# and has initializers. dyld bails out unless this dependency is upward. 111# * STRONG_DEPENDENCIES: Which regular dependencies we should link against in the firstpass. 112# Just like STRONG_SIBLINGS, this should only be used in special cases. The intended use case is when 113# another sibling depends on symbols linked into this sibling from dependencies (usually static libraries). 114# Current use case is for Security to link to its static libraries in the firstpass, 115# because coretls_cfhelpers depends on them. 116FUNCTION(add_circular name) 117 cmake_parse_arguments(CIRCULAR "FAT" "LINK_FLAGS" "SOURCES;OBJECTS;SIBLINGS;STRONG_SIBLINGS;DEPENDENCIES;UPWARD;STRONG_DEPENDENCIES" ${ARGN}) 118 #message(STATUS "${name} sources: ${CIRCULAR_SOURCES}") 119 #message(STATUS "${name} siblings ${CIRCULAR_SIBLINGS}") 120 #message(STATUS "${name} deps: ${CIRCULAR_DEPENDENCIES}") 121 122 set(all_objects "${CIRCULAR_OBJECTS}") 123 124 # First create an object library for all sources with the aim to avoid rebuild 125 if (CIRCULAR_SOURCES) 126 add_library("${name}_obj" OBJECT ${CIRCULAR_SOURCES}) 127 if (CIRCULAR_FAT) 128 make_fat("${name}_obj") 129 endif (CIRCULAR_FAT) 130 set(all_objects "${all_objects};$<TARGET_OBJECTS:${name}_obj>") 131 endif (CIRCULAR_SOURCES) 132 133 # Then create a shared Darling library, while ignoring all dependencies and using flat namespace 134 add_darling_library("${name}_firstpass" SHARED ${all_objects}) 135 set_property(TARGET "${name}_firstpass" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS} -Wl,-flat_namespace -Wl,-undefined,suppress") 136 137 foreach(dep ${CIRCULAR_STRONG_SIBLINGS}) 138 target_link_libraries("${name}_firstpass" PRIVATE "${dep}_firstpass") 139 endforeach(dep) 140 141 # strong dependencies are linked in the firstpass 142 target_link_libraries("${name}_firstpass" PRIVATE ${CIRCULAR_STRONG_DEPENDENCIES}) 143 144 if (CIRCULAR_FAT) 145 make_fat("${name}_firstpass") 146 endif (CIRCULAR_FAT) 147 148 # Then build the final product while linking against firstpass libraries 149 add_darling_library(${name} SHARED ${all_objects}) 150 151 foreach(dep ${CIRCULAR_SIBLINGS}) 152 target_link_libraries("${name}" PRIVATE "${dep}_firstpass") 153 endforeach(dep) 154 foreach(dep ${CIRCULAR_UPWARD}) 155 #get_property(lib_location TARGET ${dep} PROPERTY LOCATION_${CMAKE_BUILD_TYPE}) 156 #set_property(TARGET "${name}" APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-upward_library,${lib_location}") 157 target_link_libraries("${name}" PRIVATE -Wl,-upward_library,$<TARGET_FILE:${dep}_firstpass>) 158 add_dependencies("${name}" "${dep}_firstpass") 159 endforeach(dep) 160 161 get_property(dylib_files GLOBAL PROPERTY FIRSTPASS_MAP) 162 set_property(TARGET "${name}" APPEND_STRING PROPERTY LINK_FLAGS " ${CIRCULAR_LINK_FLAGS}") 163 164 target_link_libraries("${name}" PRIVATE ${CIRCULAR_DEPENDENCIES}) 165 166 # strong dependencies are linked again in the finalpass 167 target_link_libraries("${name}" PRIVATE ${CIRCULAR_STRONG_DEPENDENCIES}) 168 169 if (CIRCULAR_FAT) 170 make_fat(${name}) 171 endif (CIRCULAR_FAT) 172ENDFUNCTION(add_circular) 173 174function(add_darling_object_library name) 175 cmake_parse_arguments(OBJECT_LIB "32BIT_ONLY;64BIT_ONLY" "" "" ${ARGN}) 176 foreach(f IN LISTS OBJECT_LIB_UNPARSED_ARGUMENTS) 177 set(files ${files} ${f}) 178 endforeach(f) 179 180 add_library(${name} OBJECT ${files}) 181 add_dependencies(${name} lipo) 182 set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " -B ${CMAKE_BINARY_DIR}/src/external/cctools-port/cctools/misc/") 183 184 if (BUILD_TARGET_32BIT AND NOT OBJECT_LIB_64BIT_ONLY) 185 set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " -arch ${APPLE_ARCH_32BIT}") 186 endif (BUILD_TARGET_32BIT AND NOT OBJECT_LIB_64BIT_ONLY) 187 if (BUILD_TARGET_64BIT AND NOT OBJECT_LIB_32BIT_ONLY) 188 set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " -arch ${APPLE_ARCH_64BIT}") 189 endif (BUILD_TARGET_64BIT AND NOT OBJECT_LIB_32BIT_ONLY) 190endfunction(add_darling_object_library)