Skip to content

Commit e95d1cc

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 e83ba3e commit e95d1cc

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tools/mtmd/CMakeLists.txt

Lines changed: 18 additions & 4 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,36 +9,50 @@ 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)
3241
target_compile_definitions(mtmd PRIVATE LLAMA_SHARED LLAMA_BUILD)
3342
add_library(mtmd_shared SHARED $<TARGET_OBJECTS:mtmd>)
3443
target_link_libraries(mtmd_shared PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
35-
install(TARGETS mtmd_shared LIBRARY)
44+
set_target_properties(mtmd_shared PROPERTIES PUBLIC_HEADER "${MTMD_PUBLIC_HEADERS}")
45+
install(TARGETS mtmd_shared LIBRARY PUBLIC_HEADER)
3646

3747
set_target_properties(mtmd_helper PROPERTIES POSITION_INDEPENDENT_CODE ON)
3848
target_compile_definitions(mtmd_helper PRIVATE LLAMA_SHARED LLAMA_BUILD)
3949
add_library(mtmd_helper_shared SHARED $<TARGET_OBJECTS:mtmd>)
4050
target_link_libraries(mtmd_helper_shared PRIVATE ggml llama mtmd ${CMAKE_THREAD_LIBS_INIT})
41-
install(TARGETS mtmd_helper_shared LIBRARY)
51+
set_target_properties(mtmd_helper_shared PROPERTIES PUBLIC_HEADER "${MTMD_HELPER_PUBLIC_HEADERS}")
52+
install(TARGETS mtmd_helper_shared LIBRARY PUBLIC_HEADER)
53+
else()
54+
install(TARGETS mtmd LIBRARY PUBLIC_HEADER PUBLIC_HEADER)
55+
install(TARGETS mtmd_helper LIBRARY PUBLIC_HEADER)
4256
endif()
4357

4458
if (NOT MSVC)

0 commit comments

Comments
 (0)