From 62ca28df01a87c493f00fb8cbae3ed23f05ff395 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 7 Jan 2025 12:19:37 +0100 Subject: [PATCH] Refactored openvino::utils cmake --- src/common/util/CMakeLists.txt | 52 ++++++++++++++-------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/src/common/util/CMakeLists.txt b/src/common/util/CMakeLists.txt index 9d3d83cb54c804..bec562114adbe6 100644 --- a/src/common/util/CMakeLists.txt +++ b/src/common/util/CMakeLists.txt @@ -37,46 +37,36 @@ add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS}) add_library(openvino::util ALIAS ${TARGET_NAME}) set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME util) -file( - WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp - "#include \nint main(int argc, char ** argv) {\n std::experimental::filesystem::path p(argv[0]);\n return p.string().length();\n}" - ) - try_compile( - STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR} - SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp - COMPILE_DEFINITIONS -std=c++11) - try_compile( - STD_FS_NEEDS_STDCXXFS ${CMAKE_CURRENT_BINARY_DIR} - SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp - COMPILE_DEFINITIONS -std=c++11 - LINK_LIBRARIES stdc++fs) - try_compile( - STD_FS_NEEDS_CXXFS ${CMAKE_CURRENT_BINARY_DIR} - SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp - COMPILE_DEFINITIONS -std=c++11 - LINK_LIBRARIES c++fs) - -if(MSVC) - message(INFO "MSVC - No explicit filesystem linker setting required.") - set(STD_FS_LIB "") +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp + "#include \nint main(int argc, char ** argv) {\n std::experimental::filesystem::path p(argv[0]);\n return p.string().length();\n}") + +try_compile(STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp + COMPILE_DEFINITIONS -std=c++11) +try_compile(STD_FS_NEEDS_STDCXXFS ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp + COMPILE_DEFINITIONS -std=c++11 + LINK_LIBRARIES stdc++fs) +try_compile(STD_FS_NEEDS_CXXFS ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp + COMPILE_DEFINITIONS -std=c++11 + LINK_LIBRARIES c++fs) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + message(STATUS "MSVC - No explicit filesystem linker setting required.") elseif(STD_FS_NEEDS_STDCXXFS) - message(INFO "STD_FS_NEEDS_STDCXXFS - Add explicit filesystem linker setting: 'stdc++fs'.") + message(STATUS "STD_FS_NEEDS_STDCXXFS - Add explicit filesystem linker setting: 'stdc++fs'.") set(STD_FS_LIB stdc++fs) elseif(STD_FS_NEEDS_CXXFS) - message(INFO "STD_FS_NEEDS_CXXFS - Add explicit filesystem linker setting: 'c++fs'.") + message(STATUS "STD_FS_NEEDS_CXXFS - Add explicit filesystem linker setting: 'c++fs'.") set(STD_FS_LIB c++fs) elseif(STD_FS_NO_LIB_NEEDED) - message(INFO "STD_FS_NO_LIB_NEEDED - No explicit filesystem linker setting required.") - set(STD_FS_LIB "") + message(STATUS "STD_FS_NO_LIB_NEEDED - No explicit filesystem linker setting required.") else() message(WARNING "Unknown C++ build setup - No explicit filesystem linker setting set") - set(STD_FS_LIB "") endif() -target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS} PUBLIC openvino::pugixml ${STD_FS_LIB} ) -if (WIN32) - target_link_libraries(${TARGET_NAME} PRIVATE Shlwapi) -endif() +target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS} PUBLIC openvino::pugixml $ ${STD_FS_LIB}) target_include_directories(${TARGET_NAME} PUBLIC $) ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})