OneCore toolchain (#3044)
authorIlya Lavrenov <ilya.lavrenov@intel.com>
Tue, 10 Nov 2020 13:29:37 +0000 (16:29 +0300)
committerGitHub <noreply@github.com>
Tue, 10 Nov 2020 13:29:37 +0000 (16:29 +0300)
* Added OneCoreUap toolchain file

* Intentation

* Updated OneCore toolchain

* Fixed linkage error with static runtime

* Link reader_api library

* Enable static runtime for ONNX part

* Allow to override flags

* Added flag for clDNN; plus refactoring

* Fix Includes

* Added toolchain check

* Added apivalidator for MYRIAD plugin

* Added commented apivalidator for CLDNN plugin

13 files changed:
cmake/api_validator/api_validator.cmake
cmake/api_validator/api_validator_run.cmake
cmake/onecoreuap.toolchain.cmake [new file with mode: 0644]
cmake/os_flags.cmake
cmake/uwp.toolchain.cmake
inference-engine/src/cldnn_engine/CMakeLists.txt
inference-engine/src/inference_engine/CMakeLists.txt
inference-engine/src/readers/CMakeLists.txt
inference-engine/src/readers/reader_api/ie_blob_stream.cpp [moved from inference-engine/src/inference_engine/ie_blob_stream.cpp with 100% similarity]
inference-engine/src/readers/reader_api/ie_blob_stream.hpp
inference-engine/src/vpu/myriad_plugin/CMakeLists.txt
ngraph/CMakeLists.txt
ngraph/cmake/external_protobuf.cmake

index 3502858..d165256 100644 (file)
@@ -107,6 +107,7 @@ function(_ie_add_api_validator_post_build_step)
                 -D UWP_API_VALIDATOR_APIS=${UWP_API_VALIDATOR_APIS}
                 -D UWP_API_VALIDATOR_EXCLUSION=${UWP_API_VALIDATOR_EXCLUSION}
                 -D UWP_API_VALIDATOR_OUTPUT=${output_file}
+                -D CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
                 -P "${OpenVINO_MAIN_SOURCE_DIR}/cmake/api_validator/api_validator_run.cmake"
             BYPRODUCTS ${output_file}
             COMMENT "[apiValidator] Check ${target_name} for OneCore compliance"
index c53f9dc..759feac 100644 (file)
@@ -6,7 +6,7 @@ cmake_policy(SET CMP0012 NEW)
 
 foreach(var UWP_API_VALIDATOR UWP_API_VALIDATOR_TARGET
             UWP_API_VALIDATOR_APIS UWP_API_VALIDATOR_EXCLUSION
-            UWP_API_VALIDATOR_OUTPUT)
+            UWP_API_VALIDATOR_OUTPUT CMAKE_TOOLCHAIN_FILE)
     if(NOT DEFINED ${var})
         message(FATAL_ERROR "Variable ${var} is not defined")
     endif()
@@ -43,7 +43,11 @@ file(WRITE "${UWP_API_VALIDATOR_OUTPUT}" "${output_message}\n\n\n${error_message
 get_filename_component(name "${UWP_API_VALIDATOR_TARGET}" NAME)
 
 if(NOT UWP_HAS_BINARY_EXCLUSION)
-    set(exclusion_dlls "msvcp140.dll" "vcruntime140.dll")
+    if(CMAKE_TOOLCHAIN_FILE MATCHES "onecoreuap.toolchain.cmake$")
+        # empty since we compile with static MSVC runtime
+    else()
+        set(exclusion_dlls "msvcp140.dll" "vcruntime140.dll")
+    endif()
 
     # remove exclusions from error_message
 
diff --git a/cmake/onecoreuap.toolchain.cmake b/cmake/onecoreuap.toolchain.cmake
new file mode 100644 (file)
index 0000000..3c1ad25
--- /dev/null
@@ -0,0 +1,97 @@
+# Copyright (C) 2018-2020 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+#
+
+#
+# Define CMAKE_SYSTEM_VERSION if not defined
+#
+
+if(NOT DEFINED CMAKE_SYSTEM_VERSION)
+    # Sometimes CMAKE_HOST_SYSTEM_VERSION has form 10.x.y while we need
+    # form 10.x.y.z Adding .0 at the end fixes the issue
+    if(CMAKE_HOST_SYSTEM_VERSION MATCHES "^10\.0\.[0-9]+$")
+        set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}.0")
+    else()
+        set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
+    endif()
+endif()
+
+if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
+    set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
+endif()
+
+message(STATUS "Building for Windows OneCore compliance (using OneCoreUap.lib, ${CMAKE_SYSTEM_VERSION})")
+
+#
+# OneCore flags
+#
+
+set(_onecoreuap_arch "x64")
+if(CMAKE_GENERATOR_PLATFORM)
+    set(_onecoreuap_arch ${CMAKE_GENERATOR_PLATFORM})
+endif()
+
+if(_onecoreuap_arch STREQUAL "x64")
+    # Forcefull make VS search for C++ libreries in these folders prior to other c++ standard libraries localizations.
+    add_link_options("/LIBPATH:\"\$\(VC_LibraryPath_VC_x64_OneCore\)\"")
+
+    set(CMAKE_C_STANDARD_LIBRARIES "\$\(UCRTContentRoot\)lib/\$\(TargetUniversalCRTVersion\)/um/\$\(Platform\)/OneCoreUap.lib" CACHE STRING "" FORCE)
+    set(CMAKE_CXX_STANDARD_LIBRARIES "\$\(UCRTContentRoot\)lib/\$\(TargetUniversalCRTVersion\)/um/\$\(Platform\)/OneCoreUap.lib" CACHE STRING "" FORCE)
+elseif(_onecoreuap_arch STREQUAL "X86")
+    add_link_options("/LIBPATH:\"\$\(VCInstallDir\)lib/onecore\"")
+    add_link_options("/LIBPATH:\"\$\(VC_LibraryPath_VC_x86_OneCore\)\"")
+
+    set(CMAKE_C_STANDARD_LIBRARIES "\$\(UCRTContentRoot\)lib/\$\(TargetUniversalCRTVersion\)/um/x86/OneCoreUap.lib" CACHE STRING "" FORCE)
+    set(CMAKE_CXX_STANDARD_LIBRARIES "\$\(UCRTContentRoot\)lib/\$\(TargetUniversalCRTVersion\)/um/x86/OneCoreUap.lib" CACHE STRING "" FORCE)
+else()
+    message(FATAL_ERROR "Unsupported architecture ${_onecoreuap_arch}. Only X86 or X86_64 are supported")
+endif()
+
+unset(_onecoreuap_arch)
+
+# compile flags
+
+set(includes "/I\"\$\(UniversalCRT_IncludePath\)\"")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${includes}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${includes}")
+unset(includes)
+
+# linker flags
+
+foreach(lib kernel32 user32 advapi32 ole32 mscoree combase)
+    set(linker_flags "/NODEFAULTLIB:${lib}.lib ${linker_flags}")
+endforeach()
+
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${linker_flags}")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${linker_flags}")
+unset(linker_flags)
+
+#
+# Flags for 3rd party projects
+#
+
+set(use_static_runtime ON)
+
+if(use_static_runtime)
+    foreach(lang C CXX)
+        foreach(build_type "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
+            set(flag_var "CMAKE_${lang}_FLAGS${build_type}")
+            string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+        endforeach()
+    endforeach()
+endif()
+
+function(onecoreuap_set_runtime var)
+    set(${var} ${use_static_runtime} CACHE BOOL "" FORCE)
+endfunction()
+
+# ONNX
+onecoreuap_set_runtime(ONNX_USE_MSVC_STATIC_RUNTIME)
+# pugixml
+onecoreuap_set_runtime(STATIC_CRT)
+# protobuf
+onecoreuap_set_runtime(protobuf_MSVC_STATIC_RUNTIME)
+# clDNN
+onecoreuap_set_runtime(CLDNN__COMPILE_LINK_USE_STATIC_RUNTIME)
+
+unset(use_static_runtime)
index 78d0eb4..49f0c8b 100644 (file)
@@ -186,13 +186,12 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
 endif()
 
 if(ENABLE_COVERAGE)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
+    ie_add_compiler_flags(--coverage)
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
 endif()
 
-if(NOT MSVC)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char")
+if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+    ie_add_compiler_flags(-fsigned-char)
 endif()
 
 set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
index f595fd9..3e9f6b6 100644 (file)
@@ -4,10 +4,14 @@
 
 set(CMAKE_SYSTEM_NAME WindowsStore)
 
+#
+# Define CMAKE_SYSTEM_VERSION if not defined
+#
+
 if(NOT DEFINED CMAKE_SYSTEM_VERSION)
     # Sometimes CMAKE_HOST_SYSTEM_VERSION has form 10.x.y while we need
     # form 10.x.y.z Adding .0 at the end fixes the issue
-    if(CMAKE_HOST_SYSTEM_VERSION MATCHES "^10\.0.[0-9]+$")
+    if(CMAKE_HOST_SYSTEM_VERSION MATCHES "^10\.0\.[0-9]+$")
         set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}.0")
     else()
         set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
@@ -18,6 +22,10 @@ if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
     set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
 endif()
 
+#
+# Compilation flags
+#
+
 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/src/uwp.hpp"
     "#ifdef WINAPI_FAMILY\n"
     "#undef WINAPI_FAMILY\n"
index 510859b..e7cace7 100644 (file)
@@ -40,6 +40,9 @@ target_include_directories(${TARGET_NAME} PRIVATE
 
 set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
 
+# Failed because of OpenCL
+# ie_add_api_validator_post_build_step(TARGET ${TARGET_NAME})
+
 # install
 
 install(FILES "${clDNN_SOURCE_DIR}/kernel_selector/core/cache/cache.json"
index b4e56b0..d5170fa 100644 (file)
@@ -110,9 +110,10 @@ target_include_directories(${TARGET_NAME}_obj PRIVATE "${CMAKE_CURRENT_SOURCE_DI
                                                       "${IE_MAIN_SOURCE_DIR}/src/readers/ir_reader" # for ie_ir_version.hpp
                                                       $<TARGET_PROPERTY:${TARGET_NAME}_legacy,INTERFACE_INCLUDE_DIRECTORIES>
                                                       $<TARGET_PROPERTY:${TARGET_NAME}_transformations,INTERFACE_INCLUDE_DIRECTORIES>
-                                                      $<TARGET_PROPERTY:${TARGET_NAME}_reader_api,INTERFACE_INCLUDE_DIRECTORIES>
                                                       $<TARGET_PROPERTY:${TARGET_NAME}_plugin_api,INTERFACE_INCLUDE_DIRECTORIES>)
 
+target_link_libraries(${TARGET_NAME}_obj PRIVATE ${TARGET_NAME}_reader_api)
+
 if(ENABLE_MKL_DNN)
     target_include_directories(${TARGET_NAME}_obj SYSTEM PRIVATE "${IE_MAIN_SOURCE_DIR}/thirdparty/mkl-dnn/src/cpu/xbyak")
 endif()
index 8043d29..d0e8b07 100644 (file)
@@ -10,10 +10,12 @@ target_include_directories(${TARGET_NAME} INTERFACE
     "${CMAKE_CURRENT_SOURCE_DIR}/reader_api"
     $<TARGET_PROPERTY:inference_engine,INTERFACE_INCLUDE_DIRECTORIES>)
 
-file(GLOB_RECURSE reader_api_src "${CMAKE_CURRENT_SOURCE_DIR}/reader_api/*.hpp"
-                                 "${CMAKE_CURRENT_SOURCE_DIR}/reader_api/*.h")
+file(GLOB_RECURSE reader_api_hpp "${CMAKE_CURRENT_SOURCE_DIR}/reader_api/*.hpp")
+file(GLOB_RECURSE reader_api_src "${CMAKE_CURRENT_SOURCE_DIR}/reader_api/*.cpp")
 
-add_cpplint_target(${TARGET_NAME}_cpplint FOR_SOURCES ${reader_api_src})
+set_target_properties(${TARGET_NAME} PROPERTIES INTERFACE_SOURCES ${reader_api_src})
+
+add_cpplint_target(${TARGET_NAME}_cpplint FOR_SOURCES ${reader_api_hpp} ${reader_api_src})
 
 add_subdirectory(ir_reader)
 add_subdirectory(ir_reader_v7)
index f4a3e5e..371cb23 100644 (file)
@@ -10,7 +10,7 @@
 namespace InferenceEngine {
 namespace details {
 
-class INFERENCE_ENGINE_API_CLASS(BlobStream): public std::istream {
+class BlobStream: public std::istream {
 private:
     class BlobBuffer: public std::streambuf {
     public:
index cffb5f1..889f2e6 100644 (file)
@@ -41,6 +41,8 @@ target_link_libraries(${TARGET_NAME}
     PRIVATE
         mvnc inference_engine inference_engine_legacy vpu_graph_transformer)
 
+ie_add_api_validator_post_build_step(TARGET ${TARGET_NAME})
+
 # LTO
 
 set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
index 2763bb1..99f32a6 100644 (file)
@@ -460,9 +460,14 @@ if (NGRAPH_ONNX_IMPORT_ENABLE)
     if (MSVC)
         # When we build dll libraries. These flags make sure onnx and protobuf build with /MD, not /MT.
         # These two options can't be mixed, because they requires link two imcompatiable runtime.
-        set(ONNX_USE_MSVC_STATIC_RUNTIME OFF)
         set(protobuf_WITH_ZLIB  OFF CACHE BOOL "" FORCE)
-        set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link protobuf to static runtime libraries" FORCE)
+
+        if(NOT DEFINED ONNX_USE_MSVC_STATIC_RUNTIME)
+            set(ONNX_USE_MSVC_STATIC_RUNTIME OFF)
+        endif()
+        if(NOT DEFINED protobuf_MSVC_STATIC_RUNTIME)
+            set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link protobuf to static runtime libraries" FORCE)
+        endif()
     endif()
     if (NOT NGRAPH_USE_SYSTEM_PROTOBUF)
         include(cmake/external_protobuf.cmake)
index 7140689..94ddd15 100644 (file)
@@ -107,20 +107,20 @@ else()
         # Use the interface of FindProtobuf.cmake
         # -----------------------------------------------------------------------------
         if (NOT TARGET protobuf::libprotobuf)
-        add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
-        set_target_properties(protobuf::libprotobuf PROPERTIES
-            INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}"
-            IMPORTED_LOCATION "${Protobuf_LIBRARY}")
-        add_dependencies(protobuf::libprotobuf ext_protobuf)
+            add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
+            set_target_properties(protobuf::libprotobuf PROPERTIES
+                INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}"
+                IMPORTED_LOCATION "${Protobuf_LIBRARY}")
+            add_dependencies(protobuf::libprotobuf ext_protobuf)
         endif()
         set(Protobuf_LIBRARIES protobuf::libprotobuf)
 
         if (NOT TARGET protobuf::protoc)
-        add_executable(protobuf::protoc IMPORTED)
-        set_target_properties(protobuf::protoc PROPERTIES
-            INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Protobuf_PROTOC_EXECUTABLE}"
-            IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}")
-        add_dependencies(protobuf::protoc ext_protobuf)
+            add_executable(protobuf::protoc IMPORTED)
+            set_target_properties(protobuf::protoc PROPERTIES
+                INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Protobuf_PROTOC_EXECUTABLE}"
+                IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}")
+            add_dependencies(protobuf::protoc ext_protobuf)
         endif()
 
         set(Protobuf_FOUND TRUE)