diff --git a/CMakeLists.txt b/CMakeLists.txt index ca45178b..04a74ccf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ if (NOT MSVC) install(FILES "${CMAKE_BINARY_DIR}/sentencepiece.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() -include_directories(${CMAKE_SOURCE_DIR} ${PROJECT_BINARY_DIR}) +include_directories("." ${CMAKE_SOURCE_DIR} ${PROJECT_BINARY_DIR}) if (SPM_BUILD_TEST) enable_testing() diff --git a/CMakeLists_minexport.txt b/CMakeLists_minexport.txt new file mode 100644 index 00000000..bd1fecfd --- /dev/null +++ b/CMakeLists_minexport.txt @@ -0,0 +1,112 @@ +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.! + +# This can be used as a replacement to the existing CMakeLists.txt for +# the purposes of building a shared sentencepiece dll with MSVC machines. +# The default shared library build for MSVC exports all of the standard +# library symbols, making it unlinkable for most purposes in practice. + +# To build on Windows with MSVC, rename CMakeLists_minexport.txt in +# both the root dir and the src dir to CMakeLists.txt and run test_minexport.bat. +# Note that this only builds the new target, sentencepiece_export.dll|lib +# correctly. I have not tested the other build targets. + +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +file(STRINGS "VERSION" SPM_VERSION) +message(STATUS "VERSION: ${SPM_VERSION}") +project(sentencepiece VERSION ${SPM_VERSION} LANGUAGES CXX) + +option(SPM_ENABLE_NFKC_COMPILE "Enables NFKC compile" OFF) +option(SPM_ENABLE_SHARED "Builds shared libaries in addition to static libraries." ON) +option(SPM_ENABLE_SHARED_MINEXPORT "Builds dll lib with minimal exports for windows." OFF) +option(SPM_BUILD_TEST "Builds test binaries." OFF) +option(SPM_COVERAGE "Runs gcov to test coverage." OFF) +option(SPM_ENABLE_TENSORFLOW_SHARED "Makes a tensorflow compatible shared file." OFF) +option(SPM_ENABLE_TCMALLOC "Enable TCMalloc if available." ON) +option(SPM_TCMALLOC_STATIC "Link static library of TCMALLOC." OFF) +option(SPM_NO_THREADLOCAL "Disable thread_local operator" OFF) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + + +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix "\${prefix}") +set(libdir "\${exec_prefix}/lib") +set(includedir "\${prefix}/include") +set(GNUCXX_STD_SUPPORT_VERSION "4.3") + +if(MSVC) + #string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) + #string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL}) + #string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) + #string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_FLAGS_REALEASE} /MD") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_FLAGS_REALEASE} /MD") + add_definitions("/wd4267 /wd4244 /wd4305 /Zc:strictStrings /utf-8") +endif(MSVC) + +if (APPLE) + set(CMAKE_MACOSX_RPATH ON) + set(CMAKE_SKIP_BUILD_RPATH FALSE) + set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) + if ("${isSystemDir}" STREQUAL "-1") + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") + endif() +endif() + +if (NOT DEFINED CMAKE_INSTALL_BINDIR) + set(CMAKE_INSTALL_BINDIR bin) +endif() + +if (NOT DEFINED CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR lib) +endif() + +if (NOT DEFINED CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR lib) +endif() + +if (NOT DEFINED CMAKE_INSTALL_INCDIR) + set(CMAKE_INSTALL_INCDIR include) +endif() + +configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "config.h") +configure_file("${PROJECT_SOURCE_DIR}/sentencepiece.pc.in" "sentencepiece.pc" @ONLY) + +if (NOT MSVC) + install(FILES "${CMAKE_BINARY_DIR}/sentencepiece.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endif() + +include_directories("." ${CMAKE_SOURCE_DIR} ${PROJECT_BINARY_DIR}) + +if (SPM_BUILD_TEST) + enable_testing() +endif() + +add_subdirectory(src) + +set(CPACK_SOURCE_GENERATOR "TXZ") +set(CPACK_GENERATOR "7Z") +set(CPACK_PACKAGE_VERSION "${SPM_VERSION}") +set(CPACK_STRIP_FILES TRUE) +set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md") +set(CPACK_PACKAGE_CONTACT "taku@google.com") +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Taku Kudo") +set(CPACK_SOURCE_IGNORE_FILES "/build/;/.git/;/dist/;/sdist/;~$;${CPACK_SOURCE_IGNORE_FILES}") +include(CPack) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ebfcaa64..0afc0bd5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -178,7 +178,7 @@ if (NOT MSVC) endif() set_source_files_properties( sentencepiece.pb.cc sentencepiece_model.pb.cc - PROPERTIES COMPILE_FLAGS "-Wno-misleading-indentation") + PROPERTIES COMPILE_FLAGS "-Wno-misleading-indentation -Wno-unused-variable") set_source_files_properties(${SPM_TEST_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") if (SPM_ENABLE_SHARED) diff --git a/src/CMakeLists_minexport.txt b/src/CMakeLists_minexport.txt new file mode 100644 index 00000000..7ca5d91a --- /dev/null +++ b/src/CMakeLists_minexport.txt @@ -0,0 +1,279 @@ +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.! + +# This can be used as a replacement to the existing CMakeLists.txt for +# the purposes of building a shared sentencepiece dll with MSVC machines. +# The default shared library build for MSVC exports all of the standard +# library symbols, making it unlinkable for most purposes in practice. + +# To build on Windows with MSVC, rename CMakeLists_minexport.txt in +# both the root dir and the src dir to CMakeLists.txt and run test_minexport.bat. +# Note that this only builds the new target, sentencepiece_export.dll|lib +# correctly. I have not tested the other build targets. + +include(GenerateExportHeader) +find_package(Protobuf REQUIRED) +include_directories(${Protobuf_INCLUDE_DIRS}) +protobuf_generate_cpp(SPM_PROTO_SRCS SPM_PROTO_HDRS sentencepiece.proto) +protobuf_generate_cpp(SPM_MODEL_PROTO_SRCS SPM_MODEL_PROTO_HDRS sentencepiece_model.proto) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${PROTOBUF_INCLUDE_DIR}) + +set(SPM_SRCS + ${SPM_PROTO_HDRS} + ${SPM_PROTO_SRCS} + ${SPM_MODEL_PROTO_HDRS} + ${SPM_MODEL_PROTO_SRCS} + bpe_model.h + common.h + normalizer.h + util.h + freelist.h + filesystem.h + flags.h + sentencepiece_processor.h + word_model.h + model_factory.h + char_model.h + model_interface.h + testharness.h + unigram_model.h + bpe_model.cc + char_model.cc + error.cc + filesystem.cc + flags.cc + model_factory.cc + model_interface.cc + normalizer.cc + sentencepiece_processor.cc + unigram_model.cc + util.cc + word_model.cc + ../third_party/absl/strings/string_view.cc) + +set(SPM_TRAIN_SRCS + ${SPM_PROTO_HDRS} + ${SPM_MODEL_PROTO_HDRS} + builder.h + normalization_rule.h + unicode_script.h + unicode_script_map.h + trainer_factory.h + trainer_interface.h + unigram_model_trainer.h + word_model_trainer.h + char_model_trainer.h + bpe_model_trainer.h + sentencepiece_trainer.h + builder.cc + unicode_script.cc + trainer_factory.cc + trainer_interface.cc + unigram_model_trainer.cc + word_model_trainer.cc + char_model_trainer.cc + bpe_model_trainer.cc + sentencepiece_trainer.cc) + +set(SPM_TEST_SRCS + ${SPM_PROTO_HDRS} + ${SPM_MODEL_PROTO_HDRS} + testharness.h + bpe_model_test.cc + bpe_model_trainer_test.cc + builder_test.cc + char_model_test.cc + char_model_trainer_test.cc + filesystem_test.cc + flags_test.cc + model_factory_test.cc + model_interface_test.cc + normalizer_test.cc + sentencepiece_processor_test.cc + sentencepiece_trainer_test.cc + test_main.cc + testharness.cc + trainer_factory_test.cc + trainer_interface_test.cc + unicode_script_test.cc + unigram_model_test.cc + unigram_model_trainer_test.cc + util_test.cc + word_model_test.cc + word_model_trainer_test.cc) + +find_package(Threads REQUIRED) + +set(SPM_LIBS ${PROTOBUF_LIBRARY} Threads::Threads) + +if (SPM_ENABLE_NFKC_COMPILE) + find_package(ICU 4.4 COMPONENTS i18n data uc REQUIRED) + include_directories(${ICU_INCLUDE_DIRS}) + add_definitions(-DENABLE_NFKC_COMPILE) + list(APPEND SPM_LIBS ICU::i18n ICU::data ICU::uc) +endif() + +if (SPM_ENABLE_TCMALLOC) + if (SPM_TCMALLOC_STATIC) + find_library(TCMALLOC_LIB NAMES libtcmalloc_minimal.a) + else() + find_library(TCMALLOC_LIB NAMES tcmalloc_minimal) + endif() + if (TCMALLOC_LIB) + message(STATUS "Found TCMalloc: ${TCMALLOC_LIB}") + list(APPEND SPM_LIBS ${TCMALLOC_LIB}) + add_definitions(-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free) + else() + message(STATUS "Not Found TCMalloc: ${TCMALLOC_LIB}") + endif() +endif() + +#build shared library with minimal exports, suitable for +#linking on Windows (i.e. do not export all of the stuff in +#the standard library) +if (SPM_ENABLE_SHARED_MINEXPORT) + add_library(sentencepiece_minexport SHARED ${SPM_SRCS}) + target_compile_definitions(sentencepiece_minexport PUBLIC PROTOBUF_USE_DLLS MINEXPORT) + generate_export_header(sentencepiece_minexport) + target_link_libraries(sentencepiece_minexport ${SPM_LIBS}) + if(MSVC) + target_compile_options(sentencepiece_minexport PUBLIC /wd4251) + #set(CMAKE_CXX_FLAGS "/wd4251 ${CMAKE_CXX_FLAGS}") + endif() +endif() + +if (SPM_ENABLE_SHARED) + add_library(sentencepiece SHARED ${SPM_SRCS}) + add_library(sentencepiece_train SHARED ${SPM_TRAIN_SRCS}) +endif() + +add_library(sentencepiece-static STATIC ${SPM_SRCS}) +add_library(sentencepiece_train-static STATIC ${SPM_TRAIN_SRCS}) + +target_link_libraries(sentencepiece-static INTERFACE ${SPM_LIBS}) +target_link_libraries(sentencepiece_train-static INTERFACE sentencepiece-static ${SPM_LIBS}) + +if (SPM_ENABLE_SHARED) + target_link_libraries(sentencepiece ${SPM_LIBS}) + target_link_libraries(sentencepiece_train ${SPM_LIBS} sentencepiece) + set(SPM_INSTALLTARGETS sentencepiece sentencepiece_train sentencepiece-static sentencepiece_train-static) + set_target_properties(sentencepiece sentencepiece_train PROPERTIES SOVERSION 0 VERSION 0.0.0) + set_target_properties(sentencepiece PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES) + set_target_properties(sentencepiece_train PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES) + if (MSVC) + set_target_properties(sentencepiece PROPERTIES IMPORT_SUFFIX "_import.lib") + set_target_properties(sentencepiece_train PROPERTIES IMPORT_SUFFIX "_import.lib") + target_compile_definitions(sentencepiece PUBLIC PROTOBUF_USE_DLLS) + elseif (MINGW) + set_target_properties(sentencepiece PROPERTIES IMPORT_SUFFIX ".dll.a") + set_target_properties(sentencepiece_train PROPERTIES IMPORT_SUFFIX ".dll.a") + endif() +else() + add_library(sentencepiece ALIAS sentencepiece-static) + add_library(sentencepiece_train ALIAS sentencepiece_train-static) + set(SPM_INSTALLTARGETS sentencepiece-static sentencepiece_train-static) +endif() + + +set_target_properties(sentencepiece-static PROPERTIES OUTPUT_NAME "sentencepiece") +set_target_properties(sentencepiece_train-static PROPERTIES OUTPUT_NAME "sentencepiece_train") + +if (NOT MSVC) + if (SPM_COVERAGE) + set(CMAKE_CXX_FLAGS "-O0 -Wall -fPIC -coverage ${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "-O3 -Wall -fPIC ${CMAKE_CXX_FLAGS}") + endif() + if (SPM_ENABLE_TENSORFLOW_SHARED) + add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) + endif() + if (SPM_NO_THREADLOCAL) + add_definitions(-DSPM_NO_THREADLOCAL=1) + endif() + set_source_files_properties( + sentencepiece.pb.cc sentencepiece_model.pb.cc + PROPERTIES COMPILE_FLAGS "-Wno-misleading-indentation") + set_source_files_properties(${SPM_TEST_SRCS} + PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") + if (SPM_ENABLE_SHARED) + set_property(TARGET sentencepiece APPEND_STRING PROPERTY COMPILE_FLAGS " -DPIC") + set_property(TARGET sentencepiece_train APPEND_STRING PROPERTY COMPILE_FLAGS " -DPIC") + endif() +endif() + +add_executable(spm_encode spm_encode_main.cc) +add_executable(spm_decode spm_decode_main.cc) +add_executable(spm_normalize spm_normalize_main.cc) +add_executable(spm_train spm_train_main.cc) +add_executable(spm_export_vocab spm_export_vocab_main.cc) + +target_link_libraries(spm_encode sentencepiece) +target_link_libraries(spm_decode sentencepiece) +target_link_libraries(spm_normalize sentencepiece sentencepiece_train) +target_link_libraries(spm_train sentencepiece sentencepiece_train) +target_link_libraries(spm_export_vocab sentencepiece) + +if (SPM_ENABLE_NFKC_COMPILE) + add_executable(compile_charsmap compile_charsmap_main.cc) + target_link_libraries(compile_charsmap sentencepiece sentencepiece_train) +endif() + +list(APPEND SPM_INSTALLTARGETS + spm_encode spm_decode spm_normalize spm_train spm_export_vocab) + +install(TARGETS ${SPM_INSTALLTARGETS} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(FILES sentencepiece_trainer.h sentencepiece_processor.h + DESTINATION ${CMAKE_INSTALL_INCDIR}) +if (SPM_ENABLE_SHARED_MINEXPORT) +install(FILES sentencepiece_minexport_export.h + DESTINATION ${CMAKE_INSTALL_INCDIR}) +endif() +install(FILES sentencepiece_trainer.h sentencepiece_processor.h + DESTINATION ${CMAKE_INSTALL_INCDIR}) + +file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/data" data_dir) + +if (SPM_BUILD_TEST OR SPM_COVERAGE) + enable_testing() + add_executable(spm_test test_main.cc ${SPM_TEST_SRCS}) + + if (SPM_COVERAGE) + target_link_libraries(spm_test sentencepiece sentencepiece_train "-lgcov") + else() + target_link_libraries(spm_test sentencepiece sentencepiece_train) + endif() + + set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-leak-kinds=definite,possible --error-exitcode=1") + find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind) + include(Dart) + + add_test(NAME sentencepiece_test + COMMAND $ --data_dir=${data_dir}) +endif() + +if (SPM_COVERAGE) + add_custom_target(coverage + COMMAND mkdir -p coverage + COMMAND $ --data_dir=${data_dir} + COMMAND lcov -c -d . -o coverage.info + COMMAND lcov --remove coverage.info "include*" "/c++" "_test*" "testharness*" "third_party*" ".pb.*" -o coverage.info + COMMAND mkdir -p lcov_html + COMMAND genhtml -o lcov_html coverage.info) + add_dependencies(coverage spm_test) +endif() diff --git a/src/freelist.h b/src/freelist.h index e39c3381..b3e977a6 100644 --- a/src/freelist.h +++ b/src/freelist.h @@ -33,7 +33,7 @@ class FreeList { // `Free` doesn't free the object but reuse the allocated memory chunks. void Free() { - const int size = std::min(chunk_index_ + 1, freelist_.size()); + const int size = std::min(chunk_index_ + 1, freelist_.size()); for (int i = 0; i < size; ++i) { T* chunk = freelist_[i]; memset(chunk, 0, sizeof(*chunk) * chunk_size_); diff --git a/src/sentencepiece_processor.h b/src/sentencepiece_processor.h index 61da691d..16e20998 100644 --- a/src/sentencepiece_processor.h +++ b/src/sentencepiece_processor.h @@ -20,6 +20,11 @@ #include #include #include +#ifdef MINEXPORT +#include "sentencepiece_minexport_export.h" +#else +#define SENTENCEPIECE_MINEXPORT_EXPORT +#endif namespace absl { class string_view; @@ -117,7 +122,7 @@ enum Code { }; } // namespace error -class Status { +class SENTENCEPIECE_MINEXPORT_EXPORT Status { public: Status(); ~Status(); @@ -160,7 +165,7 @@ class min_string_view { }; } // namespace util -class SentencePieceProcessor { +class SENTENCEPIECE_MINEXPORT_EXPORT SentencePieceProcessor { public: SentencePieceProcessor(); virtual ~SentencePieceProcessor(); diff --git a/test.bat b/test.bat index 5b425080..01c5f2f5 100644 --- a/test.bat +++ b/test.bat @@ -8,11 +8,12 @@ set PATH=c:\Program Files\Git\usr\bin;c:\MinGW\bin;%PATH% set CURRENT_PATH=%~dp0 set LIBRARY_PATH=%CURRENT_PATH%build\root +powershell -command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object Net.WebClient).DownloadFile('https://github.com/google/protobuf/releases/download/v%PROTOBUF_VERSION%/protobuf-cpp-%PROTOBUF_VERSION%.zip', '.\protobuf-cpp-%PROTOBUF_VERSION%.zip') }" + mkdir build cd build -curl -O -L https://github.com/google/protobuf/releases/download/v%PROTOBUF_VERSION%/protobuf-cpp-%PROTOBUF_VERSION%.zip -unzip protobuf-cpp-%PROTOBUF_VERSION%.zip +unzip ..\protobuf-cpp-%PROTOBUF_VERSION%.zip cd protobuf-%PROTOBUF_VERSION%\cmake cmake . -A %PLATFORM% -DCMAKE_INSTALL_PREFIX=%LIBRARY_PATH% || goto :error cmake --build . --config Release --target install || goto :error diff --git a/test_minexport.bat b/test_minexport.bat new file mode 100644 index 00000000..03e16e1c --- /dev/null +++ b/test_minexport.bat @@ -0,0 +1,58 @@ +rem This is a version of the Windows build script (test.bat) that builds a minimal +rem export library of sentencepiece in a shared dll that is linkable to other projects +rem on Windows machines. I tried for way too long to make my changes play nicely with +rem the existing cmake files, but was unsuccessful, so I opted to change in parallel +rem files instead. This file and the two CMakeLists_minexport.txt files in the root +rem directory and the src directory allow the creation of a shared Windows library +rem that does not export all of the symbols in the standard library. + +set PROTOBUF_VERSION=3.6.1 +set PLATFORM=%1 +if "%PLATFORM%"=="" set PLATFORM=x64 +set PLATFORM_PREFIX= +if "%PLATFORM%"=="x64" set PLATFORM_PREFIX=-x64 +set _CL_=/utf-8 +set PATH=c:\Program Files\Git\usr\bin;c:\MinGW\bin;%PATH% +set CURRENT_PATH=%~dp0 +set LIBRARY_PATH=%CURRENT_PATH%build\root + +rename CMakeLists.txt CMakeLists.txt.stock +rename src\CMakeLists.txt CMakeLists.txt.stock +copy CMakeLists_minexport.txt CMakeLists.txt +copy src\CMakeLists_minexport.txt src\CMakeLists.txt + +mkdir build +cd build + +unzip ..\protobuf-cpp-%PROTOBUF_VERSION%.zip +cd protobuf-%PROTOBUF_VERSION%\cmake +cmake . -A %PLATFORM% -DCMAKE_INSTALL_PREFIX=%LIBRARY_PATH% -DBUILD_SHARED_LIBS=true -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -DCMAKE_SYSTEM_VERSION=8.1 || goto :error +rem cmake . -A %PLATFORM% -DCMAKE_INSTALL_PREFIX=%LIBRARY_PATH% || goto :error +cmake --build . --config Release --target install || goto :error + +cd ..\.. +cmake .. -A %PLATFORM% -DSPM_BUILD_TEST=ON -DSPM_ENABLE_SHARED=ON -DCMAKE_INSTALL_PREFIX=%LIBRARY_PATH% -DBUILD_SHARED_LIBS=true -DSPM_ENABLE_SHARED=true -DSPM_ENABLE_SHARED_MINEXPORT=ON +rem cmake .. -A %PLATFORM% -DSPM_BUILD_TEST=ON -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=%LIBRARY_PATH% +cmake --build . --config Release --target install || goto :error +ctest -C Release || goto :error +cpack || goto :error + +cd ..\python +rem call :BuildPython C:\Python27%PLATFORM_PREFIX% +call :BuildPython C:\Python35%PLATFORM_PREFIX% +call :BuildPython C:\Python36%PLATFORM_PREFIX% +call :BuildPython C:\Python37%PLATFORM_PREFIX% +c:\Python37%PLATFORM_PREFIX%\python setup.py sdist || goto :error +exit + +:BuildPython +%1\python -m pip install wheel || goto :error +%1\python setup.py build || goto :error +%1\python setup.py bdist_wheel || goto :error +%1\python setup.py test || goto :error +rmdir /Q /S build +del /S *.pyd +exit /b + +:error +exit /b %errorlevel%