diff --git a/src/Compiler/CMakeLists.txt b/src/Compiler/CMakeLists.txt index da29f06e78..1825d44062 100644 --- a/src/Compiler/CMakeLists.txt +++ b/src/Compiler/CMakeLists.txt @@ -87,6 +87,8 @@ if (DEFINED ONNX_MLIR_PRODUCT_VERSION) message(DEBUG "PRODUCT_VERSION_PATCH = ${PRODUCT_VERSION_PATCH}") message(DEBUG "PRODUCT_ID = ${PRODUCT_ID}") + list(APPEND DEFINITIONS "ONNX_MLIR_PRODUCT_VERSION=${ONNX_MLIR_PRODUCT_VERSION}") + # Major and product ID are mandatory, minor and patch are optional. if (("${PRODUCT_VERSION_MAJOR}" STREQUAL "") OR ("${PRODUCT_ID}" STREQUAL "")) message(STATUS "Product version : Invalid version ${ONNX_MLIR_PRODUCT_VERSION} ignored") @@ -113,6 +115,7 @@ list(APPEND DEFINITIONS "PRODUCT_VERSION_MAJOR=${PRODUCT_VERSION_MAJOR}") list(APPEND DEFINITIONS "PRODUCT_VERSION_MINOR=${PRODUCT_VERSION_MINOR}") list(APPEND DEFINITIONS "PRODUCT_VERSION_PATCH=${PRODUCT_VERSION_PATCH}") list(APPEND DEFINITIONS "PRODUCT_ID=\"${PRODUCT_ID}\"") +target_compile_definitions(OMVersion PUBLIC ${DEFINITIONS}) set_property(SOURCE CompilerUtils.cpp APPEND PROPERTY COMPILE_DEFINITIONS ${DEFINITIONS}) add_onnx_mlir_library(CompilerUtils @@ -128,7 +131,7 @@ add_onnx_mlir_library(CompilerUtils INCLUDE_DIRS PRIVATE ${FILE_GENERATE_DIR} - + INCLUDE_DIRS PUBLIC ${ONNX_MLIR_SRC_ROOT}/include @@ -166,7 +169,7 @@ add_onnx_mlir_library(OnnxMlirCompiler ${FILE_GENERATE_DIR} EXCLUDE_FROM_OM_LIBS - + LINK_LIBS PRIVATE CompilerUtils ) diff --git a/src/Version/CMakeLists.txt b/src/Version/CMakeLists.txt index 9528d36768..d05af9387c 100644 --- a/src/Version/CMakeLists.txt +++ b/src/Version/CMakeLists.txt @@ -73,7 +73,7 @@ else() list(APPEND DEFINITIONS "ONNX_VERSION=\"${ONNX_VERSION}\"") endif() if (ONNX_MLIR_VENDOR) - list(APPEND DEFINITIONS "ONNX_MLIR_VENDOR=\"${ONNX_MLIR_VENDOR }\"") + list(APPEND DEFINITIONS "ONNX_MLIR_VENDOR=\"${ONNX_MLIR_VENDOR}\"") endif() list(APPEND DEFINITIONS "LLVM_PACKAGE_VERSION=\"${LLVM_PACKAGE_VERSION}\"") target_compile_definitions(OMVersion PUBLIC ${DEFINITIONS}) diff --git a/src/Version/Version.cpp b/src/Version/Version.cpp index 1277ddb3a2..6a55a48317 100644 --- a/src/Version/Version.cpp +++ b/src/Version/Version.cpp @@ -80,9 +80,6 @@ std::string getLLVMFullRepositoryVersion() { std::string getOnnxMlirFullVersion(bool toIncludeLLVM) { std::string buf; llvm::raw_string_ostream os(buf); -#ifdef ONNX_MLIR_VENDOR - os << ONNX_MLIR_VENDOR; -#endif os << "onnx-mlir version " ONNX_MLIR_VERSION; #ifdef ONNX_VERSION os << ", onnx version " ONNX_VERSION; @@ -118,13 +115,18 @@ std::string getOnnxMlirFullVersion(bool toIncludeLLVM) { #endif void getVersionPrinter(llvm::raw_ostream &os) { +#if defined(ONNX_MLIR_VENDOR) && defined(ONNX_MLIR_PRODUCT_VERSION) + os << ONNX_MLIR_VENDOR << " " << PRODUCT_VERSION_MAJOR << '.'; + os << PRODUCT_VERSION_MINOR << '.'; + os << PRODUCT_VERSION_PATCH << '-' << PRODUCT_ID << '\n'; +#endif os << getOnnxMlirFullVersion(false) << "\n"; - os << " LLVM version " << LLVM_PACKAGE_VERSION << ' ' + os << "LLVM version " << LLVM_PACKAGE_VERSION << ' ' << getLLVMFullRepositoryVersion() << '\n'; #if ONNX_MLIR_IS_DEBUG_BUILD - os << " DEBUG build"; + os << "DEBUG build"; #else - os << " Optimized build"; + os << "Optimized build"; #endif #ifndef NDEBUG os << " with assertions"; @@ -133,8 +135,8 @@ void getVersionPrinter(llvm::raw_ostream &os) { if (CPU == "generic") CPU = "(unknown)"; os << ".\n"; - os << " Default target: " << llvm::sys::getDefaultTargetTriple() << '\n' - << " Host CPU: " << CPU << '\n'; + os << "Default target: " << llvm::sys::getDefaultTargetTriple() << '\n' + << "Host CPU: " << CPU << '\n'; } } // namespace onnx_mlir diff --git a/test/mlir/driver/version.mlir b/test/mlir/driver/version.mlir index 83e956479a..923b768af4 100644 --- a/test/mlir/driver/version.mlir +++ b/test/mlir/driver/version.mlir @@ -1,6 +1,6 @@ // RUN: onnx-mlir --version | FileCheck %s -// CHECK: onnx-mlir version {{[0-9]+}}.{{[0-9]+}}.{{[0-9]+}}, onnx version {{[0-9]+}}.{{[0-9]+}}.{{[0-9]+}} +// CHECK: onnx-mlir version {{[0-9]+}}.{{[0-9]+}}.{{[0-9]+}}, onnx version {{[0-9]+}}.{{[0-9]+}}.{{[0-9]+}} // CHECK: LLVM version {{[0-9]+}}.{{[0-9]+}}.{{[0-9]+}} // CHECK: {{[DEBUG|Optimized]}} build{{[ with assertions]*}} // CHECK: Default target: