diff --git a/CMakeLists.txt b/CMakeLists.txt index cb0dad9f..52647130 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,18 @@ else() set(mi_defines "") endif() +# pass git revision as a define +if(EXISTS "${CMAKE_SOURCE_DIR}/.git/index") + find_package(Git) + if(GIT_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} "describe" OUTPUT_VARIABLE mi_git_describe RESULT_VARIABLE mi_git_res ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if(mi_git_res EQUAL "0") + list(APPEND mi_defines "MI_GIT_DESCRIBE=${mi_git_describe}") + list(APPEND CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/index") # add to dependencies so we rebuild if the git rev changes + endif() + endif() +endif() + # ----------------------------------------------------------------------------- # Convenience: set default build type and compiler depending on the build directory # ----------------------------------------------------------------------------- @@ -492,6 +504,7 @@ else() endif() endif() + # ----------------------------------------------------------------------------- # Install and output names # ----------------------------------------------------------------------------- @@ -522,6 +535,7 @@ if(MI_TRACK_ASAN) set(mi_libname "${mi_libname}-asan") endif() string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC) +list(APPEND mi_defines "MI_CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE_LC}") #todo: multi-config project needs $ ? if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$")) set(mi_libname "${mi_libname}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version endif() diff --git a/src/init.c b/src/init.c index 03201707..dd3666fb 100644 --- a/src/init.c +++ b/src/init.c @@ -625,14 +625,6 @@ void mi_process_init(void) mi_attr_noexcept { mi_detect_cpu_features(); _mi_os_init(); mi_heap_main_init(); - #if MI_DEBUG - _mi_verbose_message("debug level : %d\n", MI_DEBUG); - #endif - _mi_verbose_message("secure level: %d\n", MI_SECURE); - _mi_verbose_message("mem tracking: %s\n", MI_TRACK_TOOL); - #if MI_TSAN - _mi_verbose_message("thread santizer enabled\n"); - #endif mi_thread_init(); #if defined(_WIN32) diff --git a/src/options.c b/src/options.c index 69247367..33e2bbce 100644 --- a/src/options.c +++ b/src/options.c @@ -175,7 +175,7 @@ void _mi_options_init(void) { mi_add_stderr_output(); // now it safe to use stderr for output for(int i = 0; i < _mi_option_last; i++ ) { mi_option_t option = (mi_option_t)i; - mi_option_get(option); // initialize + long l = mi_option_get(option); MI_UNUSED(l); // initialize } mi_max_error_count = mi_option_get(mi_option_max_errors); mi_max_warning_count = mi_option_get(mi_option_max_warnings); @@ -190,24 +190,47 @@ void _mi_options_init(void) { mi_options_print(); } -void mi_options_print(void) mi_attr_noexcept +#define mi_stringifyx(str) #str // and stringify +#define mi_stringify(str) mi_stringifyx(str) // expand + +void mi_options_print(void) mi_attr_noexcept { // show version const int vermajor = MI_MALLOC_VERSION/100; const int verminor = (MI_MALLOC_VERSION%100)/10; const int verpatch = (MI_MALLOC_VERSION%10); - _mi_verbose_message("v%i.%i.%i (built on %s, %s)\n", vermajor, verminor, verpatch, __DATE__, __TIME__); + _mi_verbose_message("v%i.%i.%i%s%s (built on %s, %s)\n", vermajor, verminor, verpatch, + #if defined(MI_CMAKE_BUILD_TYPE) + ", " mi_stringify(MI_CMAKE_BUILD_TYPE) + #else + "" + #endif + , + #if defined(MI_GIT_DESCRIBE) + ", git " mi_stringify(MI_GIT_DESCRIBE) + #else + "" + #endif + , __DATE__, __TIME__); // show options for (int i = 0; i < _mi_option_last; i++) { mi_option_t option = (mi_option_t)i; - mi_option_get(option); + long l = mi_option_get(option); MI_UNUSED(l); // possibly initialize mi_option_desc_t* desc = &options[option]; _mi_verbose_message("option '%s': %ld %s\n", desc->name, desc->value, (mi_option_has_size_in_kib(option) ? "KiB" : "")); - } + } + + // show build configuration + _mi_verbose_message("debug level : %d\n", MI_DEBUG ); + _mi_verbose_message("secure level: %d\n", MI_SECURE ); + _mi_verbose_message("mem tracking: %s\n", MI_TRACK_TOOL); #if MI_GUARDED _mi_verbose_message("guarded build: %s\n", mi_option_get(mi_option_guarded_sample_rate) != 0 ? "enabled" : "disabled"); #endif + #if MI_TSAN + _mi_verbose_message("thread santizer enabled\n"); + #endif } long _mi_option_get_fast(mi_option_t option) {