Skip to content

Commit fd29e26

Browse files
[CMAKE] Fix to Api validator for older cmake versions (openvinotoolkit#28293)
### Details: - Required to merge openvinotoolkit/openvino.genai#1402 - For some reason we have recursion if we have 2 functions with name `ov_add_api_validator_post_build_step` and `_ov_add_api_validator_post_build_step`
1 parent 7318165 commit fd29e26

File tree

4 files changed

+31
-41
lines changed

4 files changed

+31
-41
lines changed

cmake/developer_package/api_validator/api_validator.cmake

+7-11
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ can't find Windows SDK version. Try to use vcvarsall.bat script")
2121
endif()
2222
endif()
2323

24+
# check that PROGRAMFILES_ENV is defined, because in case of cross-compilation for Windows we don't have such variable
2425
set(PROGRAMFILES_ENV "ProgramFiles\(X86\)")
25-
26-
# check that PROGRAMFILES_ENV is defined, because in case of cross-compilation for Windows
27-
# we don't have such variable
2826
if(DEFINED ENV{${PROGRAMFILES_ENV}})
2927
file(TO_CMAKE_PATH $ENV{${PROGRAMFILES_ENV}} PROGRAMFILES)
3028

3129
set(WDK_PATHS "${PROGRAMFILES}/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/x64"
3230
"${PROGRAMFILES}/Windows Kits/10/bin/x64")
31+
endif()
3332

33+
if(WDK_PATHS)
3434
message(STATUS "Trying to find apivalidator in: ")
3535
foreach(wdk_path IN LISTS WDK_PATHS)
3636
message(" * ${wdk_path}")
@@ -90,7 +90,10 @@ endfunction()
9090

9191
set(VALIDATED_TARGETS "" CACHE INTERNAL "")
9292

93-
function(_ov_add_api_validator_post_build_step)
93+
#
94+
# ov_add_api_validator_post_build_step(TARGET <name>)
95+
#
96+
function(ov_add_api_validator_post_build_step)
9497
if((NOT ONECORE_API_VALIDATOR) OR (WINDOWS_STORE OR WINDOWS_PHONE))
9598
return()
9699
endif()
@@ -212,10 +215,3 @@ function(_ov_add_api_validator_post_build_step)
212215
list(APPEND VALIDATED_TARGETS ${API_VALIDATOR_TARGETS})
213216
set(VALIDATED_TARGETS "${VALIDATED_TARGETS}" CACHE INTERNAL "" FORCE)
214217
endfunction()
215-
216-
#
217-
# ov_add_api_validator_post_build_step(TARGET <name>)
218-
#
219-
function(ov_add_api_validator_post_build_step)
220-
_ov_add_api_validator_post_build_step(${ARGN})
221-
endfunction()

cmake/developer_package/features.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ ov_option (ENABLE_THREAD_SANITIZER "enable checking data races via ThreadSanitiz
4242

4343
ov_dependent_option (ENABLE_COVERAGE "enable code coverage" OFF "CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG" OFF)
4444

45+
ov_dependent_option (ENABLE_API_VALIDATOR "Enables API Validator usage" ON "WIN32" OFF)
46+
4547
# Defines CPU capabilities
4648

4749
ov_dependent_option (ENABLE_SSE42 "Enable SSE4.2 optimizations" ON "X86_64 OR (X86 AND NOT EMSCRIPTEN)" OFF)

cmake/features.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ ov_dependent_option(ENABLE_JS "Enables JS API building" ${ENABLE_JS_DEFAULT} "NO
208208

209209
ov_option(ENABLE_OPENVINO_DEBUG "Enable output for OPENVINO_DEBUG statements" OFF)
210210

211-
ov_dependent_option (ENABLE_API_VALIDATOR "Enables API Validator usage" ON "WIN32" OFF)
212-
213211
if(NOT BUILD_SHARED_LIBS AND ENABLE_OV_TF_FRONTEND)
214212
set(FORCE_FRONTENDS_USE_PROTOBUF ON)
215213
else()

src/common/util/CMakeLists.txt

+22-28
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,40 @@ add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS})
3737
add_library(openvino::util ALIAS ${TARGET_NAME})
3838
set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME util)
3939

40-
file(
41-
WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
42-
"#include <experimental/filesystem>\nint main(int argc, char ** argv) {\n std::experimental::filesystem::path p(argv[0]);\n return p.string().length();\n}"
43-
)
44-
try_compile(
45-
STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR}
46-
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
47-
COMPILE_DEFINITIONS -std=c++11)
48-
try_compile(
49-
STD_FS_NEEDS_STDCXXFS ${CMAKE_CURRENT_BINARY_DIR}
50-
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
51-
COMPILE_DEFINITIONS -std=c++11
52-
LINK_LIBRARIES stdc++fs)
53-
try_compile(
54-
STD_FS_NEEDS_CXXFS ${CMAKE_CURRENT_BINARY_DIR}
55-
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
56-
COMPILE_DEFINITIONS -std=c++11
57-
LINK_LIBRARIES c++fs)
58-
59-
if(MSVC)
60-
message(INFO "MSVC - No explicit filesystem linker setting required.")
61-
set(STD_FS_LIB "")
40+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
41+
"#include <experimental/filesystem>\nint main(int argc, char ** argv) {\n std::experimental::filesystem::path p(argv[0]);\n return p.string().length();\n}")
42+
43+
try_compile(STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR}
44+
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
45+
COMPILE_DEFINITIONS -std=c++11)
46+
try_compile(STD_FS_NEEDS_STDCXXFS ${CMAKE_CURRENT_BINARY_DIR}
47+
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
48+
COMPILE_DEFINITIONS -std=c++11
49+
LINK_LIBRARIES stdc++fs)
50+
try_compile(STD_FS_NEEDS_CXXFS ${CMAKE_CURRENT_BINARY_DIR}
51+
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
52+
COMPILE_DEFINITIONS -std=c++11
53+
LINK_LIBRARIES c++fs)
54+
55+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
56+
message(STATUS "MSVC - No explicit filesystem linker setting required.")
6257
elseif(STD_FS_NEEDS_STDCXXFS)
63-
message(INFO "STD_FS_NEEDS_STDCXXFS - Add explicit filesystem linker setting: 'stdc++fs'.")
58+
message(STATUS "STD_FS_NEEDS_STDCXXFS - Add explicit filesystem linker setting: 'stdc++fs'.")
6459
set(STD_FS_LIB stdc++fs)
6560
elseif(STD_FS_NEEDS_CXXFS)
66-
message(INFO "STD_FS_NEEDS_CXXFS - Add explicit filesystem linker setting: 'c++fs'.")
61+
message(STATUS "STD_FS_NEEDS_CXXFS - Add explicit filesystem linker setting: 'c++fs'.")
6762
set(STD_FS_LIB c++fs)
6863
elseif(STD_FS_NO_LIB_NEEDED)
69-
message(INFO "STD_FS_NO_LIB_NEEDED - No explicit filesystem linker setting required.")
70-
set(STD_FS_LIB "")
64+
message(STATUS "STD_FS_NO_LIB_NEEDED - No explicit filesystem linker setting required.")
7165
else()
7266
message(WARNING "Unknown C++ build setup - No explicit filesystem linker setting set")
73-
set(STD_FS_LIB "")
7467
endif()
7568

76-
target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS} PUBLIC openvino::pugixml ${STD_FS_LIB} )
69+
target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS} PUBLIC openvino::pugixml ${STD_FS_LIB})
7770
if (WIN32)
7871
target_link_libraries(${TARGET_NAME} PRIVATE Shlwapi)
7972
endif()
73+
8074
target_include_directories(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${UTIL_INCLUDE_DIR}>)
8175

8276
ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})

0 commit comments

Comments
 (0)