cmake-bare
Advanced tools
+17
-7
@@ -310,2 +310,10 @@ include_guard() | ||
| if(APPLE) | ||
| set(${target}_rpath "@loader_path/${name}") | ||
| elseif(LINUX OR ANDROID) | ||
| set(${target}_rpath "$ORIGIN/${name}") | ||
| else() | ||
| set(${target}_rpath "") | ||
| endif() | ||
| set_target_properties( | ||
@@ -326,8 +334,10 @@ ${target}_module | ||
| # Remove the runtime search path for ELF binaries and directory portion of | ||
| # the install name for Mach-O binaries. This ensures that the addon is | ||
| # identified by the linker only by its logical name. | ||
| INSTALL_RPATH "" | ||
| # Set the runpath of the addon to support loading of runtime dependencies | ||
| # located in a named directory next to the addon prebuilds. | ||
| INSTALL_RPATH "${${target}_rpath}" | ||
| BUILD_WITH_INSTALL_RPATH ON | ||
| # Remove the directory portion of the install name for Mach-O binaries. This | ||
| # ensures that the addon is identified by the linker only by its logical name. | ||
| INSTALL_NAME_DIR "" | ||
| BUILD_WITH_INSTALL_RPATH ON | ||
| BUILD_WITH_INSTALL_NAME_DIR ON | ||
@@ -438,7 +448,7 @@ | ||
| list(POP_FRONT ARGV_INSTALL type target) | ||
| list(POP_FRONT ARGV_INSTALL type value) | ||
| if(type MATCHES "TARGET") | ||
| install( | ||
| FILES $<TARGET_FILE:${target}> | ||
| FILES $<TARGET_FILE:${value}> | ||
| DESTINATION ${host}/${name} | ||
@@ -445,0 +455,0 @@ ) |
+1
-1
| { | ||
| "name": "cmake-bare", | ||
| "version": "1.7.1", | ||
| "version": "1.7.2", | ||
| "description": "Bare utilities for CMake", | ||
@@ -5,0 +5,0 @@ "files": [ |
+59
-11
| // Delay loader implementation for Windows. This is used to support loading | ||
| // native addons from binaries that don't declare themselves as "bare.exe" as | ||
| // well as loading dynamically linked native addons. | ||
| // well as loading dynamically linked native addons and their dependencies. | ||
| // | ||
@@ -19,2 +19,32 @@ // See https://learn.microsoft.com/en-us/cpp/build/reference/understanding-the-helper-function | ||
| static inline int | ||
| bare__string_equals(LPCSTR a, LPCSTR b) { | ||
| return _stricmp(a, b) == 0; | ||
| } | ||
| static inline int | ||
| bare__string_ends_with(LPCSTR a, LPCSTR b) { | ||
| size_t a_len = strlen(a); | ||
| size_t b_len = strlen(b); | ||
| if (b_len > a_len) return 0; | ||
| return bare__string_equals(a + a_len - b_len, b); | ||
| } | ||
| static inline int | ||
| bare__string_last_index_of(LPCSTR string, CHAR c) { | ||
| size_t len = strlen(string); | ||
| if (len == 0) return -1; | ||
| for (size_t i = len; i-- > 0;) { | ||
| if (string[i] == c) return i; | ||
| } | ||
| return -1; | ||
| } | ||
| static HMODULE bare__module_self = NULL; | ||
| static inline HMODULE | ||
@@ -46,15 +76,22 @@ bare__module_main(void) { | ||
| static inline int | ||
| bare__string_equals(LPCSTR a, LPCSTR b) { | ||
| return _stricmp(a, b) == 0; | ||
| } | ||
| static inline HMODULE | ||
| bare__module_load(const char *dll) { | ||
| if (bare__module_self == NULL) return NULL; | ||
| static inline int | ||
| bare__string_ends_with(LPCSTR a, LPCSTR b) { | ||
| size_t a_len = strlen(a); | ||
| size_t b_len = strlen(b); | ||
| CHAR path[MAX_PATH]; | ||
| if (b_len > a_len) return 0; | ||
| DWORD len = GetModuleFileNameA(bare__module_self, path, MAX_PATH); | ||
| return bare__string_equals(a + a_len - b_len, b); | ||
| if (bare__string_ends_with(path, ".bare")) { | ||
| path[len - 5] = L'\0'; | ||
| } else { | ||
| int i = bare__string_last_index_of(path, '\\'); | ||
| if (i != -1) path[i] = L'\0'; | ||
| } | ||
| strcat_s(path, MAX_PATH, "\\"); | ||
| strcat_s(path, MAX_PATH, dll); | ||
| return LoadLibraryA(path); | ||
| } | ||
@@ -76,2 +113,6 @@ | ||
| if (bare__string_ends_with(dll, ".dll")) { | ||
| return (FARPROC) bare__module_load(dll); | ||
| } | ||
| return NULL; | ||
@@ -88,1 +129,8 @@ } | ||
| const PfnDliHook __pfnDliFailureHook2 = bare__delay_load; | ||
| BOOL WINAPI | ||
| DllMain(HINSTANCE handle, DWORD reason, LPVOID reserved) { | ||
| if (reason == DLL_PROCESS_ATTACH) bare__module_self = handle; | ||
| return TRUE; | ||
| } |
31792
4.29%