-
Notifications
You must be signed in to change notification settings - Fork 12k
mtmd : drop _shared
from libmtmd
name, merge helpers into libmtmd (⚠️ breaking change)
#13917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It is recommended to merge them into a dynamic library such as libmtmd.dll to avoid the last submission where mtmd and mtmd_helper were separated, resulting in the library function not being able to find the MTMD_API function in mtmd_helper. |
Here is how I think it should build: diff --git a/tools/mtmd/CMakeLists.txt b/tools/mtmd/CMakeLists.txt
index edea27a63..382d82033 100644
--- a/tools/mtmd/CMakeLists.txt
+++ b/tools/mtmd/CMakeLists.txt
@@ -1,5 +1,7 @@
# mtmd
+find_package(Threads REQUIRED)
+
add_library(mtmd
mtmd.cpp
mtmd-audio.cpp
@@ -9,46 +11,50 @@ add_library(mtmd
clip-impl.h
)
-target_link_libraries(mtmd PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
-target_include_directories(mtmd PUBLIC .)
+target_link_libraries (mtmd PUBLIC ggml llama)
+target_link_libraries (mtmd PRIVATE Threads::Threads)
+target_include_directories(mtmd PUBLIC .)
target_include_directories(mtmd PRIVATE ../..)
-target_compile_features(mtmd PRIVATE cxx_std_17)
+target_compile_features (mtmd PRIVATE cxx_std_17)
+
+if (BUILD_SHARED_LIBS)
+ set_target_properties (mtmd PROPERTIES POSITION_INDEPENDENT_CODE ON)
+ target_compile_definitions(mtmd PRIVATE LLAMA_BUILD)
+ target_compile_definitions(mtmd PUBLIC LLAMA_SHARED)
+endif()
+
+set(MTMD_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/mtmd.h)
+
+set_target_properties(mtmd
+ PROPERTIES
+ PUBLIC_HEADER "${MTMD_PUBLIC_HEADERS}")
+
+install(TARGETS mtmd LIBRARY PUBLIC_HEADER)
# compile the helper separately, to avoid long compile times with miniaudio.h and stb_image.h
-add_library(mtmd_helper
+add_library(mtmd-helper STATIC
mtmd-helper.cpp
mtmd-helper.h
)
-target_link_libraries(mtmd_helper PRIVATE ggml llama mtmd ${CMAKE_THREAD_LIBS_INIT})
-target_include_directories(mtmd_helper PUBLIC .)
-target_include_directories(mtmd_helper PRIVATE ./vendor)
-target_include_directories(mtmd_helper PRIVATE ../..)
-target_compile_features(mtmd_helper PRIVATE cxx_std_17)
+target_link_libraries (mtmd-helper PRIVATE mtmd Threads::Threads)
+target_include_directories(mtmd-helper PUBLIC .)
+target_include_directories(mtmd-helper PRIVATE ../..)
+target_compile_features (mtmd-helper PRIVATE cxx_std_17)
if (BUILD_SHARED_LIBS)
- set_target_properties(mtmd PROPERTIES POSITION_INDEPENDENT_CODE ON)
- target_compile_definitions(mtmd PRIVATE LLAMA_SHARED LLAMA_BUILD)
- target_link_libraries(mtmd PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
- set_target_properties(mtmd PROPERTIES PUBLIC_HEADER "mtmd.h")
- install(TARGETS mtmd LIBRARY PUBLIC_HEADER)
-
- set_target_properties(mtmd_helper PROPERTIES POSITION_INDEPENDENT_CODE ON)
- target_compile_definitions(mtmd_helper PRIVATE LLAMA_SHARED LLAMA_BUILD)
- target_link_libraries(mtmd_helper PRIVATE ggml llama mtmd ${CMAKE_THREAD_LIBS_INIT})
- set_target_properties(mtmd_helper PROPERTIES PUBLIC_HEADER "mtmd-helper.h")
- install(TARGETS mtmd_helper LIBRARY PUBLIC_HEADER)
+ set_target_properties (mtmd-helper PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
if (NOT MSVC)
# for stb_image.h and miniaudio.h
- target_compile_options(mtmd_helper PRIVATE -Wno-cast-qual)
+ target_compile_options(mtmd-helper PRIVATE -Wno-cast-qual)
endif()
-if(TARGET BUILD_INFO)
- add_dependencies(mtmd BUILD_INFO)
- add_dependencies(mtmd_helper BUILD_INFO)
+if (TARGET BUILD_INFO)
+ add_dependencies(mtmd BUILD_INFO)
+ add_dependencies(mtmd-helper BUILD_INFO)
endif()
add_executable(llama-llava-cli deprecation-warning.cpp)
@@ -57,8 +63,8 @@ add_executable(llama-minicpmv-cli deprecation-warning.cpp)
add_executable(llama-qwen2vl-cli deprecation-warning.cpp)
set(TARGET llama-mtmd-cli)
-add_executable(${TARGET} mtmd-cli.cpp)
-set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama-mtmd-cli)
-install(TARGETS ${TARGET} RUNTIME)
-target_link_libraries(${TARGET} PRIVATE common mtmd mtmd_helper ${CMAKE_THREAD_LIBS_INIT})
+add_executable (${TARGET} mtmd-cli.cpp)
+set_target_properties (${TARGET} PROPERTIES OUTPUT_NAME llama-mtmd-cli)
+install (TARGETS ${TARGET} RUNTIME)
+target_link_libraries (${TARGET} PRIVATE common mtmd mtmd-helper Threads::Threads)
target_compile_features(${TARGET} PRIVATE cxx_std_17)
diff --git a/tools/server/CMakeLists.txt b/tools/server/CMakeLists.txt
index 08597145c..00fdcaca6 100644
--- a/tools/server/CMakeLists.txt
+++ b/tools/server/CMakeLists.txt
@@ -36,7 +36,7 @@ install(TARGETS ${TARGET} RUNTIME)
target_include_directories(${TARGET} PRIVATE ../llava)
target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR})
-target_link_libraries(${TARGET} PRIVATE common mtmd mtmd_helper ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(${TARGET} PRIVATE common mtmd mtmd-helper ${CMAKE_THREAD_LIBS_INIT})
if (LLAMA_SERVER_SSL)
find_package(OpenSSL REQUIRED)
You want |
The helper is supposed to be used by downstream projects. Without it, it would be quite difficult to convince developers to move to libmtmd. In other words, my idea is that helpers can be part of public API, but not part of the "stable" API. On second thought, I think it will be less confusing for developers if I ship everything in one single lib, while still separate them internally. I did that in ed4127c , does it looks good to you @ggerganov ? Also, I realized that my assumption was not correct:
Indeed, they are compiled as different objects:
So for example, if I change the code in |
_shared
prefix from libmtmd
name (⚠️ breaking change)
_shared
prefix from libmtmd
name (⚠️ breaking change)_shared
from libmtmd
name, merge helpers into libmtmd (⚠️ breaking change)
_shared
from libmtmd
name, merge helpers into libmtmd (⚠️ breaking change)_shared
from libmtmd
name, merge helpers into libmtmd (⚠️ breaking change)
Works perfectly from here. Thanks for the fix. Feel free to mark it as fixes 13902, I'll drop my pull. |
Supersede #13903
Small breaking changes:
libmtmd_shared.dll/so/dyblib
is now renamed tolibmtmd.dll/so/dyblib
, no more_shared
postfixlibmtmd
, revert the changes in mtmd : move helpers to dedicated library (⚠️ breaking change) #13866@65a This is made to closely resemble how
libllama
is compiled:_shared
prefixOBJECT
whenadd_library
STATIC
declarationSo you should be able to link it exactly the same way as
libllama
. But please lmk if there are other problems.@ggerganov I'm not very confident about cmake stuff, could you please take a look? Thanks.