Skip to content

Commit 844351c

Browse files
Green-Skyleejet
andauthored
feat: cmake improvements and simple ci (#9)
* move main and stb-libs to subfolder * cmake : general additions * ci : add simple building --------- Co-authored-by: leejet <31925346+leejet@users.noreply.github.com>
1 parent 8f34dd7 commit 844351c

File tree

7 files changed

+143
-8
lines changed

7 files changed

+143
-8
lines changed

.github/workflows/build.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths: ['.github/workflows/**', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu']
8+
pull_request:
9+
types: [opened, synchronize, reopened]
10+
paths: ['**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu']
11+
12+
jobs:
13+
ubuntu-latest-cmake:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Clone
18+
id: checkout
19+
uses: actions/checkout@v3
20+
with:
21+
submodules: recursive
22+
23+
24+
- name: Dependencies
25+
id: depends
26+
run: |
27+
sudo apt-get update
28+
sudo apt-get install build-essential
29+
30+
- name: Build
31+
id: cmake_build
32+
run: |
33+
mkdir build
34+
cd build
35+
cmake ..
36+
cmake --build . --config Release
37+
38+
#- name: Test
39+
#id: cmake_test
40+
#run: |
41+
#cd build
42+
#ctest --verbose --timeout 900
43+
44+
macOS-latest-cmake:
45+
runs-on: macos-latest
46+
47+
steps:
48+
- name: Clone
49+
id: checkout
50+
uses: actions/checkout@v3
51+
with:
52+
submodules: recursive
53+
54+
- name: Dependencies
55+
id: depends
56+
continue-on-error: true
57+
run: |
58+
brew update
59+
60+
- name: Build
61+
id: cmake_build
62+
run: |
63+
sysctl -a
64+
mkdir build
65+
cd build
66+
cmake ..
67+
cmake --build . --config Release
68+
69+
#- name: Test
70+
#id: cmake_test
71+
#run: |
72+
#cd build
73+
#ctest --verbose --timeout 900
74+
75+
windows-latest-cmake:
76+
runs-on: windows-latest
77+
78+
steps:
79+
- name: Clone
80+
id: checkout
81+
uses: actions/checkout@v3
82+
with:
83+
submodules: recursive
84+
85+
- name: Build
86+
id: cmake_build
87+
run: |
88+
mkdir build
89+
cd build
90+
cmake ..
91+
cmake --build . --config Release
92+
93+
#- name: Test
94+
#id: cmake_test
95+
#run: |
96+
#cd build
97+
#ctest -C Release --verbose --timeout 900
98+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build*/
22
test/
33

44
.cache/
5+
*.swp

CMakeLists.txt

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
11
cmake_minimum_required(VERSION 3.12)
2-
project(stable-diffusion)
2+
project("stable-diffusion")
3+
4+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5+
6+
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
7+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
8+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
9+
endif()
10+
11+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
12+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
13+
14+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
15+
set(SD_STANDALONE ON)
16+
else()
17+
set(SD_STANDALONE OFF)
18+
endif()
19+
20+
#
21+
# Option list
22+
#
23+
24+
# general
25+
#option(SD_BUILD_TESTS "sd: build tests" ${SD_STANDALONE})
26+
option(SD_BUILD_EXAMPLES "sd: build examples" ${SD_STANDALONE})
27+
#option(SD_BUILD_SERVER "sd: build server example" ON)
328

4-
set(SD_LIB stable-diffusion)
5-
set(SD_TARGET sd)
629

30+
# deps
731
add_subdirectory(ggml)
832

9-
add_library(${SD_LIB} stable-diffusion.h stable-diffusion.cpp)
10-
add_executable(${SD_TARGET} main.cpp stb_image.h stb_image_write.h)
33+
set(SD_LIB stable-diffusion)
1134

35+
add_library(${SD_LIB} stable-diffusion.h stable-diffusion.cpp)
1236
target_link_libraries(${SD_LIB} PUBLIC ggml)
13-
target_link_libraries(${SD_TARGET} ${SD_LIB})
14-
37+
target_include_directories(${SD_LIB} PUBLIC .)
1538
target_compile_features(${SD_LIB} PUBLIC cxx_std_11)
16-
target_compile_features(${SD_TARGET} PUBLIC cxx_std_11)
39+
40+
41+
if (SD_BUILD_EXAMPLES)
42+
add_subdirectory(examples)
43+
endif()
44+

examples/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# TODO: move into its own subdirectoy
2+
# TODO: make stb libs a target (maybe common)
3+
set(SD_TARGET sd)
4+
5+
add_executable(${SD_TARGET} main.cpp stb_image.h stb_image_write.h)
6+
install(TARGETS ${SD_TARGET} RUNTIME)
7+
target_link_libraries(${SD_TARGET} PRIVATE stable-diffusion ${CMAKE_THREAD_LIBS_INIT})
8+
target_compile_features(${SD_TARGET} PUBLIC cxx_std_11)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)