CMake: reading definitions from COMPILE_DEFINITIONS property (#24324)

Compilation in Conan fails if compiler=clang and libstd=libstdc++
because conan defines _GLIBCXX_USE_CXX11_ABI=0 but openvino autodetects
the value and overwrites it with _GLIBCXX_USE_CXX11_ABI=1.

These changes make it honor the compile definitions generated by Conan.

Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com>
This commit is contained in:
Egor Tyuvaev 2024-05-02 19:57:02 +02:00 committed by GitHub
parent e4670660a0
commit d1f9ab8389
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 1 deletions

View File

@ -122,8 +122,19 @@ function(ov_get_compiler_definition definition var)
message(FATAL_ERROR "Internal error: 'ov_get_definition' must be used only on Linux")
endif()
get_directory_property(_user_defines COMPILE_DEFINITIONS)
foreach(_user_define IN LISTS _user_defines)
# older cmake versions keep -D at the beginning, trim it
string(REPLACE "-D" "" _user_define "${_user_define}")
list(APPEND _ov_user_flags "-D${_user_define}")
endforeach()
string(REPLACE " " ";" _user_cxx_flags "${CMAKE_CXX_FLAGS}")
foreach(_user_flag IN LISTS _user_cxx_flags)
list(APPEND _ov_user_flags ${_user_flag})
endforeach()
execute_process(COMMAND echo "#include <string>"
COMMAND "${CMAKE_CXX_COMPILER}" -x c++ - -E -dM ${CMAKE_CXX_FLAGS}
COMMAND "${CMAKE_CXX_COMPILER}" ${_ov_user_flags} -x c++ - -E -dM
COMMAND grep -E "^#define ${definition} "
OUTPUT_VARIABLE output_value
ERROR_VARIABLE error_message