Skip to content

Commit 7a56208

Browse files
65a65a
authored andcommitted
cmake: mtmd: install PUBLIC_HEADERs and allow static linking
Separates out header installation and performs it regardless of build shared libs or not. Adds mtmd STATIC objects, installing those if BUILD_SHARED_LIBS is off. This should allow for static linking without breaking build encapsulation or visibility, and install the headers as before for shared libs.
1 parent e83ba3e commit 7a56208

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tools/mtmd/CMakeLists.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ add_library(mtmd OBJECT
99
clip-impl.h
1010
)
1111

12+
set(MTMD_PUBLIC_HEADERS
13+
"mtmd.h"
14+
"clip.h")
15+
1216
target_link_libraries(mtmd PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
1317
target_include_directories(mtmd PUBLIC .)
1418
target_include_directories(mtmd PRIVATE ../..)
@@ -21,6 +25,9 @@ add_library(mtmd_helper OBJECT
2125
mtmd-helper.h
2226
)
2327

28+
set(MTMD_HELPER_PUBLIC_HEADERS
29+
"mtmd-helper.h")
30+
2431
target_link_libraries(mtmd_helper PRIVATE ggml llama mtmd ${CMAKE_THREAD_LIBS_INIT})
2532
target_include_directories(mtmd_helper PUBLIC .)
2633
target_include_directories(mtmd_helper PRIVATE ./vendor)
@@ -32,13 +39,22 @@ if (BUILD_SHARED_LIBS)
3239
target_compile_definitions(mtmd PRIVATE LLAMA_SHARED LLAMA_BUILD)
3340
add_library(mtmd_shared SHARED $<TARGET_OBJECTS:mtmd>)
3441
target_link_libraries(mtmd_shared PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
35-
install(TARGETS mtmd_shared LIBRARY)
42+
set_target_properties(mtmd_shared PROPERTIES PUBLIC_HEADER "${MTMD_PUBLIC_HEADERS}")
43+
install(TARGETS mtmd_shared LIBRARY PUBLIC_HEADER)
3644

3745
set_target_properties(mtmd_helper PROPERTIES POSITION_INDEPENDENT_CODE ON)
3846
target_compile_definitions(mtmd_helper PRIVATE LLAMA_SHARED LLAMA_BUILD)
3947
add_library(mtmd_helper_shared SHARED $<TARGET_OBJECTS:mtmd>)
4048
target_link_libraries(mtmd_helper_shared PRIVATE ggml llama mtmd ${CMAKE_THREAD_LIBS_INIT})
41-
install(TARGETS mtmd_helper_shared LIBRARY)
49+
set_target_properties(mtmd_helper_shared PROPERTIES PUBLIC_HEADER "${MTMD_HELPER_PUBLIC_HEADERS}")
50+
install(TARGETS mtmd_helper_shared LIBRARY PUBLIC_HEADER)
51+
else()
52+
add_library(mtmd_static STATIC $<TARGET_OBJECTS:mtmd>)
53+
set_target_properties(mtmd_static PROPERTIES PUBLIC_HEADER "${MTMD_PUBLIC_HEADERS}")
54+
add_library(mtmd_helper_static STATIC $<TARGET_OBJECTS:mtmd>)
55+
set_target_properties(mtmd_helper PROPERTIES PUBLIC_HEADER "${MTMD_HELPER_PUBLIC_HEADERS}")
56+
install(TARGETS mtmd LIBRARY PUBLIC_HEADER PUBLIC_HEADER)
57+
install(TARGETS mtmd_helper LIBRARY PUBLIC_HEADER)
4258
endif()
4359

4460
if (NOT MSVC)

0 commit comments

Comments
 (0)