Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,38 @@ file(GLOB SD_LIB_SOURCES
"*.hpp"
)

find_program(GIT_EXE NAMES git git.exe NO_CMAKE_FIND_ROOT_PATH)
if(GIT_EXE)
execute_process(COMMAND ${GIT_EXE} describe --tags --abbrev=7 --dirty=+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE SDCPP_BUILD_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
execute_process(COMMAND ${GIT_EXE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE SDCPP_BUILD_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()

if(NOT SDCPP_BUILD_VERSION)
set(SDCPP_BUILD_VERSION unknown)
endif()
message(STATUS "stable-diffusion.cpp version ${SDCPP_BUILD_VERSION}")

if(NOT SDCPP_BUILD_COMMIT)
set(SDCPP_BUILD_COMMIT unknown)
endif()
message(STATUS "stable-diffusion.cpp commit ${SDCPP_BUILD_COMMIT}")

set_property(
SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp
APPEND PROPERTY COMPILE_DEFINITIONS
SDCPP_BUILD_COMMIT=${SDCPP_BUILD_COMMIT} SDCPP_BUILD_VERSION=${SDCPP_BUILD_VERSION}
)

if(SD_BUILD_SHARED_LIBS)
message("-- Build shared library")
message(${SD_LIB_SOURCES})
Expand Down
5 changes: 5 additions & 0 deletions examples/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,11 @@ void step_callback(int step, int frame_count, sd_image_t* image, bool is_noisy)
}

int main(int argc, const char* argv[]) {
for (int i = 1; i < argc; i++) {
if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--verbose") == 0) {
printf("stable-diffusion.cpp version %s, commit %s\n", sd_version(), sd_commit());
}
}
SDParams params;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm grabbing the -v like this just to make it easier to test, since parse_args aborts the program on error.

parse_args(argc, argv, params);
preview_path = params.preview_path;
Expand Down
4 changes: 4 additions & 0 deletions stable-diffusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ SD_API bool preprocess_canny(sd_image_t image,
float strong,
bool inverse);

SD_API const char * sd_commit(void);
SD_API const char * sd_version(void);


#ifdef __cplusplus
}
#endif
Expand Down
22 changes: 22 additions & 0 deletions version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "stable-diffusion.h"

#ifndef SDCPP_BUILD_COMMIT
#define SDCPP_BUILD_COMMIT unknown
#endif

#ifndef SDCPP_BUILD_VERSION
#define SDCPP_BUILD_VERSION unknown
#endif

#define STRINGIZE2(x) #x
#define STRINGIZE(x) STRINGIZE2(x)

const char * sd_commit(void) {
return STRINGIZE(SDCPP_BUILD_COMMIT);
}

const char * sd_version(void) {
return STRINGIZE(SDCPP_BUILD_VERSION);
}


Loading