From 9d50c7d56534183f872797d1f1e900c9e1b655fd Mon Sep 17 00:00:00 2001 From: Jesper Stemann Andersen Date: Sun, 26 Jan 2025 12:16:48 +0100 Subject: [PATCH] Added support for building for MinGW, in addition to MSVC --- faiss/CMakeLists.txt | 4 ++++ faiss/impl/platform_macros.h | 9 ++++++--- faiss/invlists/InvertedListsIOHook.cpp | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/faiss/CMakeLists.txt b/faiss/CMakeLists.txt index d8bf74acc9..1bf0aeca13 100644 --- a/faiss/CMakeLists.txt +++ b/faiss/CMakeLists.txt @@ -341,6 +341,10 @@ if(WIN32) target_compile_definitions(faiss_sve PRIVATE FAISS_MAIN_LIB) endif() +if(WIN32) + set_target_properties(faiss PROPERTIES LINK_FLAGS "-Wl,--export-all-symbols") +endif() + string(FIND "${CMAKE_CXX_FLAGS}" "FINTEGER" finteger_idx) if (${finteger_idx} EQUAL -1) target_compile_definitions(faiss PRIVATE FINTEGER=int) diff --git a/faiss/impl/platform_macros.h b/faiss/impl/platform_macros.h index 8d069995b3..54bc19e7da 100644 --- a/faiss/impl/platform_macros.h +++ b/faiss/impl/platform_macros.h @@ -11,7 +11,7 @@ #include #include -#ifdef _MSC_VER +#ifdef _WIN32 /******************************************************* * Windows specific macros @@ -23,11 +23,11 @@ #define FAISS_API __declspec(dllimport) #endif // FAISS_MAIN_LIB -#ifdef _MSC_VER #define strtok_r strtok_s -#endif // _MSC_VER +#ifdef _MSC_VER #define __PRETTY_FUNCTION__ __FUNCSIG__ +#endif // _MSC_VER #define posix_memalign(p, a, s) \ (((*(p)) = _aligned_malloc((s), (a))), *(p) ? 0 : errno) @@ -37,6 +37,7 @@ #define ALIGNED(x) __declspec(align(x)) // redefine the GCC intrinsics with Windows equivalents +#ifdef _MSC_VER #include #include @@ -101,6 +102,8 @@ inline int __builtin_clzll(uint64_t x) { #define __F16C__ 1 #endif +#endif // _MSC_VER + #define FAISS_ALWAYS_INLINE __forceinline #else diff --git a/faiss/invlists/InvertedListsIOHook.cpp b/faiss/invlists/InvertedListsIOHook.cpp index 0534a11907..13d8490a8d 100644 --- a/faiss/invlists/InvertedListsIOHook.cpp +++ b/faiss/invlists/InvertedListsIOHook.cpp @@ -13,9 +13,9 @@ #include -#ifndef _MSC_VER +#ifndef _WIN32 #include -#endif // !_MSC_VER +#endif // !_WIN32 namespace faiss { @@ -33,7 +33,7 @@ namespace { /// std::vector that deletes its contents struct IOHookTable : std::vector { IOHookTable() { -#ifndef _MSC_VER +#ifndef _WIN32 push_back(new OnDiskInvertedListsIOHook()); #endif push_back(new BlockInvertedListsIOHook());