-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
76 lines (62 loc) · 2.42 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
cmake_minimum_required(VERSION 3.12)
project("stable-diffusion-build")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED true)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
# Instruction set specific
option(SD_AVX "sd: enable AVX" ON)
option(SD_AVX2 "sd: enable AVX2" ON)
option(SD_AVX512 "sd: enable AVX512" OFF)
option(SD_FMA "sd: enable FMA" ON)
option(SD_CUBLAS "sd: cuda backend" OFF)
if (SD_AVX512)
set(GGML_AVX512 ON)
elseif (SD_AVX2)
set(GGML_AVX2 ON)
elseif (SD_AVX)
set(GGML_AVX ON)
endif ()
if (SD_FMA)
set(GGML_FMA ON)
endif ()
if(SD_CUBLAS)
message("Use CUBLAS as backend stable-diffusion")
set(GGML_CUBLAS ON)
add_definitions(-DSD_USE_CUBLAS)
endif()
include(sd)
include_directories(${sd_SOURCE_DIR})
set(SD_ABI sd-abi)
add_library(${SD_ABI} SHARED
stable-diffusion-abi.cpp
stable-diffusion-abi.h
${sd_SOURCE_DIR}/stable-diffusion.h
${sd_SOURCE_DIR}/stable-diffusion.cpp
${sd_SOURCE_DIR}/util.cpp
${sd_SOURCE_DIR}/upscaler.cpp
)
target_include_directories(${SD_ABI} PUBLIC .)
target_include_directories(${SD_ABI} PUBLIC ${sd_SOURCE_DIR} .)
set_target_properties(zip PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(ggml PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(stable-diffusion PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(${SD_ABI} PUBLIC SD_BUILD_SHARED_LIB)
target_compile_definitions(${SD_ABI} PRIVATE SD_BUILD_DLL)
set_target_properties(${SD_ABI} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(${SD_ABI} PUBLIC STABLE_DIFFUSION_SHARED STABLE_DIFFUSION_BUILD)
target_compile_definitions(${SD_ABI} PRIVATE STABLE_DIFFUSION_BUILD)
target_link_libraries(${SD_ABI} PUBLIC stable-diffusion)