Skip to content

Commit ad072fc

Browse files
authored
Generate library with CMake (ggml-org#430)
* Generate library with CMake BUILD_SHARED_LIBS to allow llama library to be generated. * Turn ON PIC when BUILD_SHARED_LIBS is ON
1 parent ea10d3d commit ad072fc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ add_library(utils OBJECT
218218
target_include_directories(utils PUBLIC .)
219219
target_compile_features(utils PUBLIC cxx_std_11) # don't bump
220220
target_link_libraries(utils PRIVATE ${LLAMA_EXTRA_LIBS})
221+
if (BUILD_SHARED_LIBS)
222+
set_target_properties(utils PROPERTIES POSITION_INDEPENDENT_CODE ON)
223+
endif()
221224

222225
add_library(ggml OBJECT
223226
ggml.c
@@ -226,6 +229,9 @@ add_library(ggml OBJECT
226229
target_include_directories(ggml PUBLIC .)
227230
target_compile_features(ggml PUBLIC c_std_11) # don't bump
228231
target_link_libraries(ggml PRIVATE Threads::Threads ${LLAMA_EXTRA_LIBS})
232+
if (BUILD_SHARED_LIBS)
233+
set_target_properties(ggml PROPERTIES POSITION_INDEPENDENT_CODE ON)
234+
endif()
229235

230236
add_library(llama
231237
llama.cpp
@@ -234,6 +240,10 @@ add_library(llama
234240
target_include_directories(llama PUBLIC .)
235241
target_compile_features(llama PUBLIC cxx_std_11) # don't bump
236242
target_link_libraries(llama PRIVATE utils ggml ${LLAMA_EXTRA_LIBS})
243+
if (BUILD_SHARED_LIBS)
244+
set_target_properties(llama PROPERTIES POSITION_INDEPENDENT_CODE ON)
245+
target_compile_definitions(llama PRIVATE LLAMA_SHARED LLAMA_BUILD)
246+
endif()
237247

238248
#
239249
# Executables

0 commit comments

Comments
 (0)