Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document minexport build #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
112 changes: 112 additions & 0 deletions CMakeLists_minexport.txt
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions readme_minexport_windows.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
To recreate these bits:

- git clone https://github.com/marian-nmt/sentencepiece.git
- cd sentencepiece
- git checkout anthonyaue/min_export_dll (or wait for this to go into master
branch and just pull that).
- run test.bat. This will build the statically-linked sentencepiece binaries.
- copy build\src\Release\*.exe \usr\tmp\sentencepiece_pack\bin
- copy build\src\Release\*.lib \usr\tmp\sentencepiece_pack\lib\amd64
- copy src\*.h \usr\tmp\sentencepiece_pack\include
- rmdir /s build
- rename CMakeLists.txt CMakeLists.txt.stock
- rename src\CMakeLists.txt src\CMakeLists.txt.stock
- copy CMakeLists_minexport.txt CMakeLists.txt
- copy src\CMakeLists_minexport.txt src\CMakeLists.txt
- run test_minexport.bat. This will build the dynamically-linked minimum
export library (needed for the managed wrapper). It fails to build a bunch
of other targets, but will build the parts you need. I spent way too much
time trying to get this to work, but I suck at CMake and CMake sucks at
Visual Studio / Windows so we're left with this inelegant hack. Sorry.
When prompted about unzipping protobuf, choose 'N' because you've already
done this.
- copy build\src\Release\sentencepiece_minexport.dll to
\usr\tmp\sentencepiece_pack\bin
- copy build\src\Release\sentencepiece_minexport.lib to
\usr\tmp\sentencepiece_pack\lib
- copy protobuf-3.6.1\cmake\Release\libprotobuf.dll to
\usr\tmp\sentencepiece_pack\bin
- Create your package (cd \usr\tmp; packagecreate SentencePiece
\usr\tmp\sentencepiece_pack VER)
- Update corext.config as appropriate.

2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading