fix windows compile bug

This commit is contained in:
lyvette 2020-09-30 16:35:51 +08:00
parent b79b613acc
commit 6655b89fcf
3 changed files with 62 additions and 146 deletions

138
build.bat
View File

@ -15,121 +15,67 @@
@echo off
@title mindspore_build
SET BASEPATH=%CD%
SET BUILD_PATH=%BASEPATH%/build
find "const int ms_version_major =" mindspore\lite\include\version.h > version.txt
for /f "delims=\= tokens=2" %%a in ('findstr "const int ms_version_major = " version.txt') do (set x=%%a)
set VERSION_MAJOR=%x:~1,1%
find "const int ms_version_minor =" mindspore\lite\include\version.h > version.txt
for /f "delims=\= tokens=2" %%b in ('findstr "const int ms_versio/retestn_minor = " version.txt') do (set y=%%b)
set VERSION_MINOR=%y:~1,1%
find "const int ms_version_revision =" mindspore\lite\include\version.h > version.txt
for /f "delims=\= tokens=2" %%c in ('findstr "const int ms_version_revision = " version.txt') do (set z=%%c)
set VERSION_REVISION=%z:~1,1%
del version.txt
echo "======Start building MindSpore Lite %VERSION_MAJOR%.%VERSION_MINOR%.%VERSION_REVISION%======"
SET threads=6
IF NOT "%2%" == "" (
SET threads=%2%
)
SET BASE_PATH=%CD%
SET BUILD_PATH=%BASE_PATH%/build
IF NOT EXIST "%BUILD_PATH%" (
md "build"
)
cd %BUILD_PATH%
IF NOT EXIST "%BUILD_PATH%/mindspore" (
md "mindspore"
)
cd %CD%/mindspore
cd %BUILD_PATH%/mindspore
IF "%1%" == "lite" (
IF "%3%" == "" (
call :run_cmake
IF errorlevel 1 (
echo "cmake fail one time."
call :gene_protobuf
call :gene_flatbuffer
call :run_cmake
IF errorlevel 1 (
echo "cmake fail."
call :run_fail
)
) ELSE (
call :gene_protobuf
call :gene_flatbuffer
)
)
cd %BUILD_PATH%/mindspore
IF "%2%" == "" (
cmake --build . --target package -- -j6
) ELSE (
cmake --build . --target package -- -j%2%
)
IF errorlevel 1 (
echo "build fail."
call :run_fail
) ELSE (
cd %BASEPATH%/output
rd /s /q _CPack_Packages
)
cmake -DPLATFORM_ARM64=off -DPLATFORM_ARM32=off -DSUPPORT_TRAIN=off ^
-DENABLE_TOOLS=off -DENABLE_CONVERTER=on -DBUILD_TESTCASES=off -DUSE_GLOG=ON ^
-DCMAKE_BUILD_TYPE=Release -DSUPPORT_GPU=off -DBUILD_MINDDATA=off -DOFFLINE_COMPILE=off ^
-DMS_VERSION_MAJOR=%VERSION_MAJOR% -DMS_VERSION_MINOR=%VERSION_MINOR% -DMS_VERSION_REVISION=%VERSION_REVISION% ^
-G "CodeBlocks - MinGW Makefiles" "%BASE_PATH%/mindspore/lite"
) ELSE (
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CPU=ON -DENABLE_MINDDATA=ON -DUSE_GLOG=ON ^
-G "CodeBlocks - MinGW Makefiles" ../..
IF NOT %errorlevel% == 0 (
echo "cmake fail."
call :run_fail
)
IF "%1%" == "" (
cmake --build . --target package -- -j6
) ELSE (
cmake --build . --target package -- -j%1%
)
IF NOT %errorlevel% == 0 (
echo "build fail."
call :run_fail
)
)
IF NOT %errorlevel% == 0 (
echo "cmake fail."
call :run_fail
)
cd %BASEPATH%
cmake --build . --target package -- -j%threads%
IF NOT %errorlevel% == 0 (
echo "build fail."
call :run_fail
)
IF EXIST "%BASE_PATH%/output" (
cd %BASE_PATH%/output
rd /s /q _CPack_Packages
)
goto run_eof
:run_cmake
set VERSION_MAJOR=1
set VERSION_MINOR=0
set VERSION_REVISION=0
echo "============ Start building MindSpore Lite %VERSION_MAJOR%.%VERSION_MINOR%.%VERSION_REVISION% ============"
cd %BUILD_PATH%/mindspore
cmake -DBUILD_DEVICE=on -DENABLE_CONVERTER=on -DPLATFORM_ARM64=off -DSUPPORT_TRAIN=off ^
-DCMAKE_BUILD_TYPE=Release -DSUPPORT_GPU=off -DBUILD_MINDDATA=off -DOFFLINE_COMPILE=off ^
-DMS_VERSION_MAJOR=%VERSION_MAJOR% -DMS_VERSION_MINOR=%VERSION_MINOR% -DMS_VERSION_REVISION=%VERSION_REVISION% ^
-G "CodeBlocks - MinGW Makefiles" "%BASEPATH%/mindspore/lite"
GOTO:EOF
:gene_protobuf
IF NOT DEFINED MSLIBS_CACHE_PATH (
cd /d %BASEPATH%/build/mindspore/_deps/protobuf-src/_build
) ELSE (
cd /d %MSLIBS_CACHE_PATH%/protobuf_*/bin
)
SET PROTO_SRC_DIR=%BASEPATH%/mindspore/lite/tools/converter/parser/caffe
protoc "%PROTO_SRC_DIR%/*.proto" --proto_path="%PROTO_SRC_DIR%" --cpp_out="%PROTO_SRC_DIR%"
SET PROTO_SRC_DIR=%BASEPATH%/mindspore/lite/tools/converter/parser/onnx
protoc "%PROTO_SRC_DIR%/*.proto" --proto_path="%PROTO_SRC_DIR%" --cpp_out="%PROTO_SRC_DIR%"
cd /d %BUILD_PATH%/mindspore
GOTO:EOF
:gene_flatbuffer
IF NOT DEFINED MSLIBS_CACHE_PATH (
cd /d %BASEPATH%/build/mindspore/_deps/flatbuffers-src/_build
) ELSE (
cd /d %MSLIBS_CACHE_PATH%/flatbuffers_*/bin
)
SET FLAT_DIR=%BASEPATH%/mindspore/lite/schema
flatc -c -b -o "%FLAT_DIR%" "%FLAT_DIR%/*.fbs"
flatc -c -b --reflect-types --gen-mutable --reflect-names --gen-object-api -o "%FLAT_DIR%/inner" "%FLAT_DIR%/*.fbs"
SET FLAT_DIR=%BASEPATH%/mindspore/lite/tools/converter/parser/tflite
flatc -c -b --reflect-types --gen-mutable --reflect-names --gen-object-api -o "%FLAT_DIR%" "%FLAT_DIR%/*.fbs"
cd /d %BUILD_PATH%/mindspore
GOTO:EOF
:run_fail
cd %BASEPATH%
cd %BASE_PATH%
set errorlevel=1
EXIT
EXIT /b %errorlevel%
:run_eof
cd %BASE_PATH%

View File

@ -85,8 +85,10 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
file(GLOB LIB_LIST ${CXX_DIR}/libstdc++-6.dll ${CXX_DIR}/libwinpthread-1.dll ${CXX_DIR}/libssp-0.dll ${CXX_DIR}/libgcc_s_seh-1.dll)
install(FILES ${LIB_LIST} DESTINATION ${TOP_DIR}/build/mindspore/package COMPONENT ${COMPONENT_NAME})
if (ENABLE_CONVERTER)
install(FILES ${TOP_DIR}/build/mindspore/tools/converter/converter_lite.exe DESTINATION ${TOP_DIR}/build/mindspore/package COMPONENT ${COMPONENT_NAME})
install(FILES ${TOP_DIR}/build/mindspore/tools/converter/libconverter_parser.a DESTINATION ${TOP_DIR}/build/mindspore/package COMPONENT ${PARSER_NAME})
install(TARGETS converter_lite RUNTIME DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME})
install(FILES ${LIB_LIST} DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME})
install(FILES ${TOP_DIR}/build/mindspore/tools/converter/mindspore_core/gvar/libmindspore_gvar.dll DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME})
install(FILES ${glog_LIBPATH}/../bin/libglog.dll DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME})
endif ()
install(FILES ${LIB_LIST} DESTINATION ${WIN_X86_BENCHMARK_DIR} COMPONENT ${WIN_RUN_X86_NAME})
install(DIRECTORY ${TOP_DIR}/mindspore/lite/include/ DESTINATION ${WIN_INC_DIR_RUN_X86} COMPONENT ${WIN_RUN_X86_NAME} FILES_MATCHING PATTERN "*.h")

View File

@ -8,27 +8,6 @@ set(CCSRC_SRC
)
include(${TOP_DIR}/cmake/external_libs/glog.cmake)
if (WIN32)
set(LITE_SRC
#src
${CMAKE_CURRENT_SOURCE_DIR}/../../src/tensor.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/model.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/lite_session.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/inner_context.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/kernel_registry.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/graph_util.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/string_util.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/runtime_api.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/thread_pool.c
${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/workspace_pool.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/allocator.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/executor.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/scheduler.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../src/lite_kernel.cc
${CMAKE_CURRENT_SOURCE_DIR}../../nnacl/pack.c
${CMAKE_CURRENT_SOURCE_DIR}/../../src/populate_parameter.cc
)
endif()
file(GLOB_RECURSE OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/*.cc)
@ -144,28 +123,6 @@ add_executable(converter_lite
add_dependencies(converter_lite tflite_fbs_src)
add_dependencies(converter_lite fbs_inner_src)
if (WIN32)
add_library(converter_mid OBJECT
${CCSRC_SRC}
${CONVERTER_SRC}
${OPS_SRC}
${KERNEL_SRC}
${LITE_SRC}
${PROTO_SRCS}
)
add_library(converter_parser STATIC
$<TARGET_OBJECTS:tflite_parser_mid>
$<TARGET_OBJECTS:caffe_parser_mid>
$<TARGET_OBJECTS:onnx_parser_mid>
$<TARGET_OBJECTS:anf_importer_mid>
$<TARGET_OBJECTS:anf_exporter_mid>
$<TARGET_OBJECTS:graph_pass_mid>
$<TARGET_OBJECTS:fusion_mid>
$<TARGET_OBJECTS:quantizer_mid>
$<TARGET_OBJECTS:converter_mid>
)
endif()
target_link_libraries(converter_lite PRIVATE
tflite_parser_mid
caffe_parser_mid
@ -189,8 +146,19 @@ target_link_libraries(converter_lite PRIVATE
if (NOT PLATFORM_ARM64 AND NOT PLATFORM_ARM32)
install(TARGETS converter_lite
RUNTIME DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME})
install(FILES ${TOP_DIR}/mindspore/lite/build/tools/converter/mindspore_core/gvar/libmindspore_gvar.so
DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/lib COMPONENT ${COMPONENT_NAME})
install(FILES ${glog_LIBPATH}/libglog.so.0.4.0
DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/third_party/glog/lib RENAME libglog.so.0 COMPONENT ${COMPONENT_NAME})
endif ()
if (WIN32)
get_filename_component(CXX_DIR ${CMAKE_CXX_COMPILER} PATH)
file(GLOB LIB_LIST ${CXX_DIR}/libstdc++-6.dll ${CXX_DIR}/libwinpthread-1.dll ${CXX_DIR}/libssp-0.dll ${CXX_DIR}/libgcc_s_seh-1.dll)
install(FILES ${LIB_LIST} DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME})
install(FILES ${TOP_DIR}/build/mindspore/tools/converter/mindspore_core/gvar/libmindspore_gvar.dll
DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME})
install(FILES ${glog_LIBPATH}/../bin/libglog.dll
DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/converter COMPONENT ${COMPONENT_NAME})
else()
install(FILES ${TOP_DIR}/mindspore/lite/build/tools/converter/mindspore_core/gvar/libmindspore_gvar.so
DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/lib COMPONENT ${COMPONENT_NAME})
install(FILES ${glog_LIBPATH}/libglog.so.0.4.0
DESTINATION ${MAIN_DIR}-${COMPONENT_NAME}/third_party/glog/lib RENAME libglog.so.0 COMPONENT ${COMPONENT_NAME})
endif ()
endif()