forked from syoyo/safetensors-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
51 lines (37 loc) · 1.49 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
cmake_minimum_required(VERSION 3.16)
project(SAFETENSORS_CPP CXX C)
set(BUILD_TARGET_C "c-safetensors")
option(SAFETENSORS_CPP_BUILD_C_API "Build C API?" ON)
option(SAFETENSORS_CPP_BUILD_EXAMPLES "Build examples" ON)
# Disable C++ exception by default.
option(SAFETENSORS_CPP_CXX_EXCEPTIONS "Enable C++ exception(disable by default)" OFF)
set(SAFETENSORS_CPP_SOURCES
safetensors.cc)
# compile with c++ for libsafetensors-c.a
set(SAFETENSORS_C_SOURCES
safetensors-c.cc)
add_library(safetensors_cpp ${SAFETENSORS_CPP_SOURCES})
if (SAFETENSORS_CPP_BUILD_C_API)
add_library(safetensors_c ${SAFETENSORS_C_SOURCES})
endif()
if(NOT SAFETENSORS_CPP_CXX_EXCEPTIONS)
if(MSVC)
# TODO: disable exception reliably
#target_compile_options(safetensors_cpp PUBLIC /EHs-c-)
else()
target_compile_options(safetensors_cpp PUBLIC -fno-exceptions)
endif()
endif()
if (SAFETENSORS_CPP_BUILD_EXAMPLES)
add_executable(example example.cc)
target_compile_definitions(example PRIVATE "SAFETENSORS_CPP_NO_IMPLEMENTATION")
target_link_libraries(example safetensors_cpp)
add_executable(serialize_example serialize-example.cc)
target_compile_definitions(serialize_example PRIVATE "SAFETENSORS_CPP_NO_IMPLEMENTATION")
target_link_libraries(serialize_example safetensors_cpp)
if (SAFETENSORS_CPP_BUILD_C_API)
add_executable(example-c example-c.c)
target_compile_definitions(example-c PRIVATE "SAFETENSORS_C_NO_IMPLEMENTATION")
target_link_libraries(example-c safetensors_c)
endif ()
endif ()