Skip to content

Commit

Permalink
Switched to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
taku910 committed Jul 24, 2018
1 parent d64cc9a commit 89831f8
Show file tree
Hide file tree
Showing 23 changed files with 432 additions and 432 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Makefile.in
/aclocal.m4
/compile
/config.guess
/config.h.in
/config.sub
/configure
/configure.scan
Expand All @@ -26,6 +25,11 @@ Makefile.in
/autogen.sh
/ltmain.sh

CMakeFiles
CMakeCache.txt
config.h
sentencepiece.pc

*.o
*.lo
*.a
Expand Down
76 changes: 76 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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.!

cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(sentencepiece VERSION 0.1.2 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_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)

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 (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)
25 changes: 0 additions & 25 deletions Makefile.am

This file was deleted.

27 changes: 0 additions & 27 deletions autogen.sh

This file was deleted.

9 changes: 9 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef CONFIG_H_
#define CONFIG_H_

#define VERSION "@PROJECT_VERSION@"
#define PACKAGE "@PROJECT_NAME@"
#define PACKAGE_STRING "@PROJECT_NAME@"


#endif // CONFIG_H_
88 changes: 0 additions & 88 deletions configure.ac

This file was deleted.

43 changes: 17 additions & 26 deletions python/make_py_wheel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,6 +17,7 @@ set -e # exit immediately on error
set -x # display all commands

PROTOBUF_VERSION=3.6.0
CMAKE_VERSION=3.12.0

run_docker() {
cd `dirname $0`
Expand All @@ -31,17 +31,15 @@ run_docker() {

build() {
TRG=$1
rm -fr tmp
mkdir -p tmp

# Installs necessary libraries under `tmp` sub directory.
cd tmp
rm -fr build
mkdir -p build
cd build

# Install libtool
curl -L -O http://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz
tar zxfv libtool-2.4.6.tar.gz
cd libtool-2.4.6
./configure
# Install cmake
curl -L -O https://cmake.org/files/v3.12/cmake-${CMAKE_VERSION}.tar.gz
tar zxfv cmake-${CMAKE_VERSION}.tar.gz
cd cmake-${CMAKE_VERSION}
./bootstrap
make -j4
make install
cd ..
Expand All @@ -51,24 +49,16 @@ build() {
tar zxfv protobuf-cpp-${PROTOBUF_VERSION}.tar.gz
cd protobuf-${PROTOBUF_VERSION}
./configure --disable-shared --with-pic
make CXXFLAGS+="-std=c++11 -O3" \
CFLAGS+="-std=c++11 -O3" -j4
make CXXFLAGS+="-std=c++11 -O3" CFLAGS+="-std=c++11 -O3" -j4
make install || true
cd ../..
cd ..

# Install sentencepiece
cmake ../.. -DSPM_ENABLE_SHARED=OFF
make -j4
make install
cd ..
make distclean || true
./autogen.sh
grep -v PKG_CHECK_MODULES configure > tmp
mv tmp -f configure
chmod +x configure
LIBS+="-pthread -L/usr/local/lib -lprotobuf" ./configure --disable-shared --with-pic
make CXXFLAGS+="-std=c++11 -O3" \
CFLAGS+="-std=c++11 -O3 -D_GLIBCXX_USE_CXX11_ABI=0" -j4
make install || true

cd python
for i in /opt/python/*
do
$i/bin/python setup.py bdist
Expand All @@ -86,8 +76,9 @@ build() {
done

mv -f wheelhouse/*${TRG}.whl .
cd .. && rm -fr tmp
cd .. && make distclean

cd ..
rm -fr build
}

if [ "$1" = "native" ]; then
Expand Down
6 changes: 3 additions & 3 deletions sentencepiece.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: @PACKAGE@
Name: @PROJECT_NAME@
Description: Unsupervised text tokenizer and detokenizer for Neural Network-based text generation.
Version: @VERSION@
Libs: -L${libdir} -lsentencepiece -lsentencepiece_train @pkgconfiglibs@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -lsentencepiece -lsentencepiece_train -lprotobuf @pkgconfiglibs@
Cflags: -I${includedir} @pkgconfigcflags@
Loading

0 comments on commit 89831f8

Please sign in to comment.