From 28ff6cef3b084c59f41b7b536938ffbb43868a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mielicki?= Date: Wed, 14 Feb 2024 21:16:33 +0100 Subject: [PATCH] Respect target type in ov_add_version_defines (#22805) ### Details: Make ov_add_version_defines macro respect the original library type (instead of implicit assumption based on BUILD_SHARED_LIBS). Note adding objects into a library with $ does not work when mixing STATIC and OBJECT targets. Co-authored-by: Ilya Lavrenov --- cmake/developer_package/version.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmake/developer_package/version.cmake b/cmake/developer_package/version.cmake index f6114ab58c304d..adcd36f22646bb 100644 --- a/cmake/developer_package/version.cmake +++ b/cmake/developer_package/version.cmake @@ -160,13 +160,18 @@ macro (ov_add_version_defines FILE TARGET) if(NOT EXISTS ${__version_file}) message(FATAL_ERROR "${FILE} does not exists in current source directory") endif() + if (NOT TARGET ${TARGET}) + message(FATAL_ERROR "Invalid target ${TARGET}") + endif() _remove_source_from_target(${TARGET} ${FILE}) _remove_source_from_target(${TARGET} ${__version_file}) - if (BUILD_SHARED_LIBS) - add_library(${TARGET}_version OBJECT ${__version_file}) + get_target_property(__target_type ${TARGET} TYPE) + if (__target_type STREQUAL "STATIC_LIBRARY") + set(__lib_type STATIC) else() - add_library(${TARGET}_version STATIC ${__version_file}) + set(__lib_type OBJECT) endif() + add_library(${TARGET}_version ${__lib_type} ${__version_file}) if(SUGGEST_OVERRIDE_SUPPORTED) set_source_files_properties(${__version_file} PROPERTIES COMPILE_OPTIONS -Wno-suggest-override)