Skip to content

Commit 6f9e9c6

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. Returns mtmd objects to STATIC, 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 2b13162 commit 6f9e9c6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tools/mtmd/CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mtmd
22

3-
add_library(mtmd OBJECT
3+
add_library(mtmd STATIC
44
mtmd.cpp
55
mtmd-audio.cpp
66
mtmd.h
@@ -9,23 +9,32 @@ 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 ../..)
1519
target_compile_features(mtmd PRIVATE cxx_std_17)
20+
set_target_properties(mtmd PROPERTIES PUBLIC_HEADER "${MTMD_PUBLIC_HEADERS}")
1621

1722
# compile the helper separately, to avoid long compile times with miniaudio.h and stb_image.h
1823

19-
add_library(mtmd_helper OBJECT
24+
add_library(mtmd_helper STATIC
2025
mtmd-helper.cpp
2126
mtmd-helper.h
2227
)
2328

29+
set(MTMD_HELPER_PUBLIC_HEADERS
30+
"mtmd-helper.h")
31+
2432
target_link_libraries(mtmd_helper PRIVATE ggml llama mtmd ${CMAKE_THREAD_LIBS_INIT})
2533
target_include_directories(mtmd_helper PUBLIC .)
2634
target_include_directories(mtmd_helper PRIVATE ./vendor)
2735
target_include_directories(mtmd_helper PRIVATE ../..)
2836
target_compile_features(mtmd_helper PRIVATE cxx_std_17)
37+
set_target_properties(mtmd_helper PROPERTIES PUBLIC_HEADER "${MTMD_HELPER_PUBLIC_HEADERS}")
2938

3039
if (BUILD_SHARED_LIBS)
3140
set_target_properties(mtmd PROPERTIES POSITION_INDEPENDENT_CODE ON)
@@ -39,7 +48,12 @@ if (BUILD_SHARED_LIBS)
3948
add_library(mtmd_helper_shared SHARED $<TARGET_OBJECTS:mtmd>)
4049
target_link_libraries(mtmd_helper_shared PRIVATE ggml llama mtmd ${CMAKE_THREAD_LIBS_INIT})
4150
install(TARGETS mtmd_helper_shared LIBRARY)
51+
else()
52+
install(TARGETS mtmd LIBRARY)
53+
install(TARGETS mtmd_helper LIBRARY)
4254
endif()
55+
install(TARGETS mtmd PUBLIC_HEADER)
56+
install(TARGETS mtmd_helper PUBLIC_HEADER)
4357

4458
if (NOT MSVC)
4559
# for stb_image.h and miniaudio.h

0 commit comments

Comments
 (0)