Skip to content

Commit a68991a

Browse files
committed
Add strings with UMF version and all UMF CMake variables
Add strings with UMF version and all CMake variables that contain the "UMF" string in the name and do not contain the '#' character in the value. Preprocessor definitions containing '#' cannot be passed on to the compiler command line because many compilers do not support it. It can be grepped in the following way: $ strings libumf.so | grep "@(#)" @(#) Intel(R) UMF version: 0.11.0-dev.git66.g89e3831d @(#) Intel(R) UMF CMake variables: "UMF_VERSION_REVISION:0,..." Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 3dc6734 commit a68991a

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

src/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@ set(UMF_CUDA_INCLUDE_DIR
1111
""
1212
CACHE PATH "Directory containing the CUDA headers")
1313

14+
# Compose the UMF_ALL_CMAKE_VARIABLES variable containing all the CMake
15+
# variables that contain the "UMF" string in the name and do not contain the '#'
16+
# character in the value. Preprocessor definitions containing '#' cannot be
17+
# passed on the compiler command line because many compilers do not support it.
18+
get_cmake_property(_variableNames VARIABLES)
19+
foreach(_variableName ${_variableNames})
20+
if(("${_variableName}" MATCHES "UMF") AND (NOT "${${_variableName}}" MATCHES
21+
"#"))
22+
set(UMF_ALL_CMAKE_VARIABLES
23+
"${_variableName}:${${_variableName}},${UMF_ALL_CMAKE_VARIABLES}")
24+
endif()
25+
endforeach()
26+
1427
# Compile definitions for UMF library.
1528
#
1629
# TODO: Cleanup the compile definitions across all the CMake files
17-
set(UMF_COMMON_COMPILE_DEFINITIONS UMF_VERSION=${UMF_VERSION})
30+
set(UMF_COMMON_COMPILE_DEFINITIONS
31+
UMF_VERSION=${UMF_VERSION}
32+
UMF_ALL_CMAKE_VARIABLES="${UMF_ALL_CMAKE_VARIABLES}")
1833

1934
set(BA_SOURCES
2035
${CMAKE_CURRENT_SOURCE_DIR}/base_alloc/base_alloc.c

src/utils/utils_log.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@
3232
#include "utils_common.h"
3333
#include "utils_log.h"
3434

35+
#define UMF_VERSION_MAGIC_STR "\x00@(#) "
36+
#define UMF_VERSION_PREF_STR "Intel(R) "
37+
#define UMF_VERSION_PREFIX UMF_VERSION_MAGIC_STR UMF_VERSION_PREF_STR
38+
39+
// convert a define to a C string
40+
#define STR_(X) #X
41+
#define STR(X) STR_(X)
42+
43+
#ifdef UMF_VERSION
44+
#define STR_UMF_VERSION "UMF version: " STR(UMF_VERSION)
45+
#define LOG_STR_UMF_VERSION STR_UMF_VERSION ", "
46+
char const __umf_str_2_version[] = UMF_VERSION_PREFIX STR_UMF_VERSION;
47+
#else /* !UMF_VERSION */
48+
#error "UMF_VERSION not defined!"
49+
#endif /* !UMF_VERSION */
50+
51+
#ifdef UMF_ALL_CMAKE_VARIABLES
52+
char const __umf_str_1__all_cmake_vars[] =
53+
UMF_VERSION_PREFIX "UMF CMake variables: " STR(UMF_ALL_CMAKE_VARIABLES);
54+
#else /* !UMF_ALL_CMAKE_VARIABLES */
55+
#error "UMF_ALL_CMAKE_VARIABLES not defined!"
56+
#endif /* !UMF_ALL_CMAKE_VARIABLES */
57+
3558
#define LOG_MAX 8192
3659
#define LOG_HEADER 256
3760
#define MAX_FILE_PATH 256
@@ -305,17 +328,8 @@ void utils_log_init(void) {
305328
loggerConfig.flushLevel = LOG_FATAL;
306329
}
307330

308-
#ifdef UMF_VERSION
309-
// convert a define to a C string
310-
#define STR_(X) #X
311-
#define STR(X) STR_(X)
312-
#define STR_UMF_VERSION "UMF version: " STR(UMF_VERSION) ", "
313-
#else /* !UMF_VERSION */
314-
#error "UMF_VERSION not defined!"
315-
#endif /* !UMF_VERSION */
316-
317331
LOG_INFO(
318-
"Logger enabled (" STR_UMF_VERSION
332+
"Logger enabled (" LOG_STR_UMF_VERSION
319333
"level: %s, flush: %s, pid: %s, timestamp: %s)",
320334
level_to_str(loggerConfig.level), level_to_str(loggerConfig.flushLevel),
321335
bool_to_str(loggerConfig.pid), bool_to_str(loggerConfig.timestamp));

test/utils/utils_log.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ const char *env_variable = "";
110110
#ifndef UMF_VERSION
111111
#define UMF_VERSION "test version"
112112
#endif
113+
#ifndef UMF_ALL_CMAKE_VARIABLES
114+
#define UMF_ALL_CMAKE_VARIABLES "test UMF_ALL_CMAKE_VARIABLES"
115+
#endif
113116
#include "utils/utils_log.c"
114117
#undef utils_env_var
115118
#undef fopen

0 commit comments

Comments
 (0)