Skip to content

Commit

Permalink
clean up CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberhan123 committed Nov 27, 2023
1 parent 8f33c11 commit 9216a2b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 95 deletions.
4 changes: 2 additions & 2 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 18 additions & 14 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 26 additions & 77 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
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()
endif ()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Expand All @@ -21,92 +21,41 @@ 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)



if (MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)

if (BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()
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)


set(GGML_AVX512 OFF)
set(GGML_AVX2 OFF)
set(GGML_AVX 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 (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
message(STATUS "ARM detected")
if (MSVC)
# TODO [llama.cpp]: arm msvc?
else()
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
add_compile_options(-mcpu=native)
endif()
# TODO [llama.cpp]: armv6,7,8 version specific flags
endif()
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$")
message(STATUS "x86 detected")
if (MSVC)
if (SD_AVX512)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX512>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX512>)
# MSVC has no compile-time flags enabling specific
# AVX512 extensions, neither it defines the
# macros corresponding to the extensions.
# Do it manually.
elseif (SD_AVX2)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX2>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX2>)
elseif (SD_AVX)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX>)
endif()
else()
add_compile_options(-mf16c)
if (SD_FMA)
add_compile_options(-mfma)
endif()
if (SD_AVX)
add_compile_options(-mavx)
endif()
if (SD_AVX2)
add_compile_options(-mavx2)
endif()
if (SD_AVX512)
add_compile_options(-mavx512f)
add_compile_options(-mavx512bw)
endif()
endif()
else()
# TODO [llama.cpp]: support PowerPC
message(STATUS "Unknown architecture")
endif()
# deps

include(sd)
include_directories(${sd_SOURCE_DIR})

if (APPLE AND NOT GGML_NO_ACCELERATE)
find_library(ACCELERATE_FRAMEWORK Accelerate)
if (ACCELERATE_FRAMEWORK)
message(STATUS "Accelerate framework found")

set(SD_EXTRA_LIBS ${SD_EXTRA_LIBS} ${ACCELERATE_FRAMEWORK})
set(SD_EXTRA_LIBS ${SD_EXTRA_LIBS} -DGGML_USE_ACCELERATE)
else()
message(WARNING "Accelerate framework not found")
endif()
endif()

set(SD_ABI sd-abi)

add_library(${SD_ABI} SHARED
stable-diffusion-abi.cpp
stable-diffusion-abi.h
base64.hpp)

target_include_directories(${SD_ABI} PUBLIC .)

set_target_properties(${SD_ABI} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(${SD_ABI} PRIVATE STABLE_DIFFUSION_SHARED STABLE_DIFFUSION_BUILD)
target_link_libraries(${SD_ABI} PUBLIC $<TARGET_OBJECTS:ggml> $<TARGET_OBJECTS:stable-diffusion> ${SD_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(${SD_ABI} PUBLIC .)
target_link_libraries(${SD_ABI} PRIVATE ggml stable-diffusion ${CMAKE_THREAD_LIBS_INIT})


4 changes: 2 additions & 2 deletions cmake/sd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ endif()

set(SD_GIT_TAG 1ac4ad2ba21c7f1c96c061f452bde129522a85c1)
set(SD_GIT_URL https://github.com/Cyberhan123/stable-diffusion.cpp)
set(BUILD_SHARED_LIBS OFF)

FetchContent_Declare(
sd
GIT_REPOSITORY ${SD_GIT_URL}
GIT_TAG ${SD_GIT_TAG}
)

FetchContent_MakeAvailable(sd)
FetchContent_MakeAvailable(sd)

0 comments on commit 9216a2b

Please sign in to comment.