diff --git a/CMakeLists.txt b/CMakeLists.txt index ffee1ccc..8b4264fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,58 @@ if (GGML_CUDA OR GGML_METAL) add_custom_target(create_empty_file ALL DEPENDS ${EMPTY_FILE_PATH}) endif() +# Project: stable_diffusion_cpp +project(stable_diffusion_cpp) + +option(STABLE_DIFFUSION_BUILD "Build stable-diffusion.cpp shared library and install alongside python package" ON) + +if (STABLE_DIFFUSION_BUILD) + set(BUILD_SHARED_LIBS "ON") + option(SD_BUILD_SHARED_LIBS "" "ON") + + # Building llama + if (APPLE AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") + # Need to disable these llama.cpp flags on Apple x86_64, + # otherwise users may encounter invalid instruction errors + set(GGML_AVX "Off" CACHE BOOL "ggml: enable AVX" FORCE) + set(GGML_AVX2 "Off" CACHE BOOL "ggml: enable AVX2" FORCE) + set(GGML_FMA "Off" CACHE BOOL "ggml: enable FMA" FORCE) + set(GGML_F16C "Off" CACHE BOOL "ggml: enable F16C" FORCE) + endif() + + add_subdirectory(dependency/stable-diffusion.cpp) + install( + TARGETS stable-diffusion + LIBRARY DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib + RUNTIME DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib + ARCHIVE DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib + FRAMEWORK DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib + RESOURCE DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib + ) + + message(STATUS "SKBUILD_PLATLIB_DIR: ${SKBUILD_PLATLIB_DIR}") + # Temporary fix for https://github.com/scikit-build/scikit-build-core/issues/374 + install( + TARGETS stable-diffusion + LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib + RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib + ARCHIVE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib + FRAMEWORK DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib + RESOURCE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib + ) + # Workaround for Windows + CUDA + if (WIN32) + install( + FILES $ + DESTINATION ${SKBUILD_PLATLIB_DIR}/nexa/gguf/lib + ) + install( + FILES $ + DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/nexa/gguf/lib + ) + endif() +endif() + # Project: llama_cpp project(llama_cpp) @@ -132,3 +184,4 @@ if (LLAMA_BUILD) endif() endif() endif() +