Skip to content

Commit

Permalink
Refactored openvino::utils cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Jan 7, 2025
1 parent 120ccae commit 62ca28d
Showing 1 changed file with 21 additions and 31 deletions.
52 changes: 21 additions & 31 deletions src/common/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <experimental/filesystem>\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 <experimental/filesystem>\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 $<WIN32:Shlwapi> ${STD_FS_LIB})
target_include_directories(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${UTIL_INCLUDE_DIR}>)

ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
Expand Down

0 comments on commit 62ca28d

Please sign in to comment.