From 7a1ccde200333b1e9a0cf95a0ef5d42918b03423 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 16 Aug 2023 21:55:28 +0200 Subject: [PATCH 1/4] move main and stb-libs to subfolder --- CMakeLists.txt | 15 +++++++-------- examples/CMakeLists.txt | 8 ++++++++ main.cpp => examples/main.cpp | 0 stb_image.h => examples/stb_image.h | 0 stb_image_write.h => examples/stb_image_write.h | 0 5 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 examples/CMakeLists.txt rename main.cpp => examples/main.cpp (100%) rename stb_image.h => examples/stb_image.h (100%) rename stb_image_write.h => examples/stb_image_write.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 158eeede9..05ce47164 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,15 @@ cmake_minimum_required(VERSION 3.12) project(stable-diffusion) -set(SD_LIB stable-diffusion) -set(SD_TARGET sd) - +# deps add_subdirectory(ggml) -add_library(${SD_LIB} stable-diffusion.h stable-diffusion.cpp) -add_executable(${SD_TARGET} main.cpp stb_image.h stb_image_write.h) +set(SD_LIB stable-diffusion) +add_library(${SD_LIB} stable-diffusion.h stable-diffusion.cpp) target_link_libraries(${SD_LIB} PUBLIC ggml) -target_link_libraries(${SD_TARGET} ${SD_LIB}) - +target_include_directories(${SD_LIB} PUBLIC .) target_compile_features(${SD_LIB} PUBLIC cxx_std_11) -target_compile_features(${SD_TARGET} PUBLIC cxx_std_11) + +# examples +add_subdirectory(examples) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000..f539c441a --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,8 @@ +#TODO: move into its own subdirectoy +#TODO: make stb libs a target (maybe common) +set(SD_TARGET sd) + +add_executable(${SD_TARGET} main.cpp stb_image.h stb_image_write.h) +install(TARGETS ${SD_TARGET} RUNTIME) +target_link_libraries(${SD_TARGET} PRIVATE stable-diffusion ${CMAKE_THREAD_LIBS_INIT}) +target_compile_features(${SD_TARGET} PUBLIC cxx_std_11) diff --git a/main.cpp b/examples/main.cpp similarity index 100% rename from main.cpp rename to examples/main.cpp diff --git a/stb_image.h b/examples/stb_image.h similarity index 100% rename from stb_image.h rename to examples/stb_image.h diff --git a/stb_image_write.h b/examples/stb_image_write.h similarity index 100% rename from stb_image_write.h rename to examples/stb_image_write.h From 5f2d0e2116b75f5e64a07661b8cd74228513cf22 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 16 Aug 2023 22:18:42 +0200 Subject: [PATCH 2/4] cmake : general additions --- .gitignore | 1 + CMakeLists.txt | 35 ++++++++++++++++++++++++++++++++--- examples/CMakeLists.txt | 4 ++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index db0a93f48..59a8a2cab 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build*/ test/ .cache/ +*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt index 05ce47164..6f1930775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,31 @@ cmake_minimum_required(VERSION 3.12) -project(stable-diffusion) +project("stable-diffusion") + +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() + +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(SD_STANDALONE ON) +else() + set(SD_STANDALONE OFF) +endif() + +# +# Option list +# + +# general +#option(SD_BUILD_TESTS "sd: build tests" ${SD_STANDALONE}) +option(SD_BUILD_EXAMPLES "sd: build examples" ${SD_STANDALONE}) +#option(SD_BUILD_SERVER "sd: build server example" ON) + # deps add_subdirectory(ggml) @@ -11,5 +37,8 @@ target_link_libraries(${SD_LIB} PUBLIC ggml) target_include_directories(${SD_LIB} PUBLIC .) target_compile_features(${SD_LIB} PUBLIC cxx_std_11) -# examples -add_subdirectory(examples) + +if (SD_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f539c441a..a55396e20 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ -#TODO: move into its own subdirectoy -#TODO: make stb libs a target (maybe common) +# TODO: move into its own subdirectoy +# TODO: make stb libs a target (maybe common) set(SD_TARGET sd) add_executable(${SD_TARGET} main.cpp stb_image.h stb_image_write.h) From cfc90571eae250d6a8e67b8149949429c7ba058f Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 16 Aug 2023 22:30:18 +0200 Subject: [PATCH 3/4] ci : add simple building --- .github/workflows/build.yml | 98 +++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..d3feeaa12 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,98 @@ +name: CI + +on: + push: + branches: + - master + paths: ['.github/workflows/**', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu'] + pull_request: + types: [opened, synchronize, reopened] + paths: ['**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu'] + +jobs: + ubuntu-latest-cmake: + runs-on: ubuntu-latest + + steps: + - name: Clone + id: checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + + - name: Dependencies + id: depends + run: | + sudo apt-get update + sudo apt-get install build-essential + + - name: Build + id: cmake_build + run: | + mkdir build + cd build + cmake .. + cmake --build . --config Release + + #- name: Test + #id: cmake_test + #run: | + #cd build + #ctest --verbose --timeout 900 + + macOS-latest-cmake: + runs-on: macos-latest + + steps: + - name: Clone + id: checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Dependencies + id: depends + continue-on-error: true + run: | + brew update + + - name: Build + id: cmake_build + run: | + sysctl -a + mkdir build + cd build + cmake -DLLAMA_AVX2=OFF -DLLAMA_FMA=OFF .. + cmake --build . --config Release + + #- name: Test + #id: cmake_test + #run: | + #cd build + #ctest --verbose --timeout 900 + + windows-latest-cmake: + runs-on: windows-latest + + steps: + - name: Clone + id: checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Build + id: cmake_build + run: | + mkdir build + cd build + cmake .. + cmake --build . --config Release + + #- name: Test + #id: cmake_test + #run: | + #cd build + #ctest -C Release --verbose --timeout 900 + From c54b9e1c9a2292806e8e86782ece27030f1783d6 Mon Sep 17 00:00:00 2001 From: leejet <31925346+leejet@users.noreply.github.com> Date: Thu, 17 Aug 2023 21:02:40 +0800 Subject: [PATCH 4/4] fix: removing redundant parameters. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d3feeaa12..0fe28119b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,7 +63,7 @@ jobs: sysctl -a mkdir build cd build - cmake -DLLAMA_AVX2=OFF -DLLAMA_FMA=OFF .. + cmake .. cmake --build . --config Release #- name: Test