From 280994fafac08ac77e22b796aced5535fdc3a009 Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 27 Dec 2016 11:25:28 +0800 Subject: [PATCH] Add other extern dependencies --- cmake/external/numpy.cmake | 57 ++++++++++++++++++++++++ cmake/external/openblas.cmake | 44 +++++++++++++++++++ cmake/external/python.cmake | 83 +++++++++++++++++++++++++++++++++++ cmake/external/swig.cmake | 75 +++++++++++++++++++++++++++++++ cmake/external/warpctc.cmake | 39 ++++++++++++++++ cmake/external/zlib.cmake | 44 +++++++++++++++++++ 6 files changed, 342 insertions(+) create mode 100644 cmake/external/numpy.cmake create mode 100644 cmake/external/openblas.cmake create mode 100644 cmake/external/python.cmake create mode 100644 cmake/external/swig.cmake create mode 100644 cmake/external/warpctc.cmake create mode 100644 cmake/external/zlib.cmake diff --git a/cmake/external/numpy.cmake b/cmake/external/numpy.cmake new file mode 100644 index 00000000000..de3e6492cdf --- /dev/null +++ b/cmake/external/numpy.cmake @@ -0,0 +1,57 @@ +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. +# +# 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. + +INCLUDE(ExternalProject) + +SET(NUMPY_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/numpy) +SET(NUMPY_INSTALL_DIR ${PROJECT_BINARY_DIR}/numpy) +set(NUMPY_VERSION "v1.11.3") + +# setuptools +ExternalProject_Add(setuptools + PREFIX ${PYTHON_SOURCES_DIR}/setuptools + URL http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz + URL_MD5 7df2a529a074f613b509fb44feefe74e + BUILD_IN_SOURCE 1 + UPDATE_COMMAND "" + PATCH_COMMAND "" + CONFIGURE_COMMAND "" + INSTALL_COMMAND "" + BUILD_COMMAND ${PYTHON_EXECUTABLE} setup.py install + DEPENDS python zlib +) + +ExternalProject_Add(cython + PREFIX ${PYTHON_SOURCES_DIR}/cython + GIT_REPOSITORY https://github.com/cython/cython.git + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND "" + UPDATE_COMMAND "" + PATCH_COMMAND "" + INSTALL_COMMAND "" + BUILD_COMMAND ${PYTHON_EXECUTABLE} setup.py install + DEPENDS python +) + +ExternalProject_Add(numpy + GIT_REPOSITORY https://github.com/numpy/numpy.git + GIT_TAG ${NUMPY_VERSION} + CONFIGURE_COMMAND "" + UPDATE_COMMAND "" + PREFIX ${NUMPY_SOURCES_DIR} + BUILD_COMMAND ${PYTHON_EXECUTABLE} setup.py build + INSTALL_COMMAND ${PYTHON_EXECUTABLE} setup.py install + BUILD_IN_SOURCE 1 + DEPENDS python setuptools cython +) diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake new file mode 100644 index 00000000000..d1220036a0f --- /dev/null +++ b/cmake/external/openblas.cmake @@ -0,0 +1,44 @@ +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. +# +# 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. + +# INCLUDE(cblas) + +INCLUDE(ExternalProject) + +SET(CBLAS_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/openblas) +SET(CBLAS_INSTALL_DIR ${PROJECT_BINARY_DIR}/openblas) + +ExternalProject_Add( + openblas + GIT_REPOSITORY "https://github.com/xianyi/OpenBLAS.git" + GIT_TAG v0.2.19 + PREFIX ${CBLAS_SOURCES_DIR} + INSTALL_DIR ${CBLAS_INSTALL_DIR} + BUILD_IN_SOURCE 1 + UPDATE_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND cd ${CBLAS_SOURCES_DIR}/src/openblas && make -j4 + INSTALL_COMMAND cd ${CBLAS_SOURCES_DIR}/src/openblas && make install PREFIX= +) + +SET(CBLAS_INCLUDE_DIR "${CBLAS_INSTALL_DIR}/include" CACHE PATH "openblas include directory." FORCE) +INCLUDE_DIRECTORIES(${CBLAS_INCLUDE_DIR}) + +IF(WIN32) + set(CBLAS_LIBRARIES "${CBLAS_INSTALL_DIR}/lib/openblas.lib" CACHE FILEPATH "openblas library." FORCE) +ELSE(WIN32) + set(CBLAS_LIBRARIES "${CBLAS_INSTALL_DIR}/lib/libopenblas.a" CACHE FILEPATH "openblas library" FORCE) +ENDIF(WIN32) + +LIST(APPEND external_project_dependencies openblas) diff --git a/cmake/external/python.cmake b/cmake/external/python.cmake new file mode 100644 index 00000000000..b4599133140 --- /dev/null +++ b/cmake/external/python.cmake @@ -0,0 +1,83 @@ +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. +# +# 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. + +INCLUDE(ExternalProject) + +SET(PYTHON_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/python) +SET(PYTHON_INSTALL_DIR ${PROJECT_BINARY_DIR}/python) + +if(MSVC) + list(APPEND EXTERNAL_PROJECT_OPTIONAL_ARGS + PATCH_COMMAND ${CMAKE_COMMAND} + -DPYTHON_SRC_DIR:PATH=${_python_SOURCE_DIR} + -P ${CMAKE_CURRENT_LIST_DIR}/PythonPatch.cmake + ) +endif() + +if(APPLE) + list(APPEND EXTERNAL_PROJECT_OPTIONAL_CMAKE_ARGS + -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON + ) +endif() + +set(EXTERNAL_PROJECT_OPTIONAL_CMAKE_CACHE_ARGS) + +# Force Python build to "Release". +if(CMAKE_CONFIGURATION_TYPES) + set(SAVED_CMAKE_CFG_INTDIR ${CMAKE_CFG_INTDIR}) + set(CMAKE_CFG_INTDIR "Release") +else() + list(APPEND EXTERNAL_PROJECT_OPTIONAL_CMAKE_CACHE_ARGS + -DCMAKE_BUILD_TYPE:STRING=Release) +endif() + +ExternalProject_Add(python + GIT_REPOSITORY "https://github.com/python-cmake-buildsystem/python-cmake-buildsystem.git" + GIT_TAG "ed5f9bcee540e47f82fa17f8360b820591aa6d66" + PREFIX ${PYTHON_SOURCES_DIR} + UPDATE_COMMAND "" + CMAKE_CACHE_ARGS + -DCMAKE_INSTALL_PREFIX:PATH=${PYTHON_INSTALL_DIR} + -DBUILD_SHARED:BOOL=OFF + -DBUILD_STATIC:BOOL=ON + -DUSE_SYSTEM_LIBRARIES:BOOL=OFF + -DZLIB_ROOT:FILEPATH=${ZLIB_ROOT} + -DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR} + -DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARIES} + -DDOWNLOAD_SOURCES:BOOL=ON + -DINSTALL_WINDOWS_TRADITIONAL:BOOL=OFF + ${EXTERNAL_PROJECT_OPTIONAL_CMAKE_CACHE_ARGS} + ${EXTERNAL_PROJECT_OPTIONAL_CMAKE_ARGS} + DEPENDS zlib +) + +set(_python_DIR ${PYTHON_INSTALL_DIR}) + +if(UNIX) + set(_python_IMPORT_SUFFIX so) + if(APPLE) + set(_python_IMPORT_SUFFIX dylib) + endif() + set(PYTHON_INCLUDE_DIR "${PYTHON_INSTALL_DIR}/include/python2.7" CACHE PATH "Python include dir" FORCE) + set(PYTHON_LIBRARY "${PYTHON_INSTALL_DIR}/lib/libpython2.7.${_python_IMPORT_SUFFIX}" CACHE FILEPATH "Python library" FORCE) + set(PYTHON_EXECUTABLE ${PYTHON_INSTALL_DIR}/bin/python CACHE FILEPATH "Python executable" FORCE) + set(PY_SITE_PACKAGES_PATH "${PYTHON_INSTALL_DIR}/lib/python2.7/site-packages" CACHE PATH "Python site-packages path" FORCE) +elseif(WIN32) + set(PYTHON_INCLUDE_DIR "${PYTHON_INSTALL_DIR}/include" CACHE PATH "Python include dir" FORCE) + set(PYTHON_LIBRARY "${PYTHON_INSTALL_DIR}/libs/python27.lib" CACHE FILEPATH "Python library" FORCE) + set(PYTHON_EXECUTABLE "${PYTHON_INSTALL_DIR}/bin/python.exe" CACHE FILEPATH "Python executable" FORCE) + set(PY_SITE_PACKAGES_PATH "${PYTHON_INSTALL_DIR}/Lib/site-packages" CACHE PATH "Python site-packages path" FORCE) +else() + message(FATAL_ERROR "Unknown system !") +endif() diff --git a/cmake/external/swig.cmake b/cmake/external/swig.cmake new file mode 100644 index 00000000000..9dc112b98ec --- /dev/null +++ b/cmake/external/swig.cmake @@ -0,0 +1,75 @@ +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. +# +# 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. + +# Look for system swig +# FIND_PACKAGE(SWIG) + +#IF(NOT ${SWIG_FOUND}) + # build swig as an external project + INCLUDE(ExternalProject) + SET(SWIG_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/swig) + SET(SWIG_INSTALL_DIR ${PROJECT_BINARY_DIR}/swig) + SET(SWIG_TARGET_VERSION "3.0.2") + SET(SWIG_DOWNLOAD_SRC_MD5 "62f9b0d010cef36a13a010dc530d0d41") + SET(SWIG_DOWNLOAD_WIN_MD5 "3f18de4fc09ab9abb0d3be37c11fbc8f") + + IF(WIN32) + # swig.exe available as pre-built binary on Windows: + ExternalProject_Add(swig + URL http://prdownloads.sourceforge.net/swig/swigwin-${SWIG_TARGET_VERSION}.zip + URL_MD5 ${SWIG_DOWNLOAD_WIN_MD5} + SOURCE_DIR ${SWIG_SOURCES_DIR} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + ) + SET(SWIG_DIR ${SWIG_SOURCES_DIR} CACHE FILEPATH "SWIG Directory" FORCE) + SET(SWIG_EXECUTABLE ${SWIG_SOURCES_DIR}/swig.exe CACHE FILEPATH "SWIG Executable" FORCE) + + ELSE(WIN32) + # From PCRE configure + ExternalProject_Add(pcre + GIT_REPOSITORY https://github.com/svn2github/pcre.git + PREFIX ${SWIG_SOURCES_DIR}/pcre + UPDATE_COMMAND "" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SWIG_INSTALL_DIR}/pcre + ) + + # swig uses bison find it by cmake and pass it down + FIND_PACKAGE(BISON) + + # From SWIG configure + ExternalProject_Add(swig + URL https://github.com/swig/swig/archive/rel-3.0.10.tar.gz + PREFIX ${SWIG_SOURCES_DIR} + UPDATE_COMMAND "" + CONFIGURE_COMMAND cd ${SWIG_SOURCES_DIR}/src/swig && ./autogen.sh + CONFIGURE_COMMAND cd ${SWIG_SOURCES_DIR}/src/swig && + env "PCRE_LIBS=${SWIG_INSTALL_DIR}/pcre/lib/libpcre.a \ + ${SWIG_INSTALL_DIR}/pcre/lib/libpcrecpp.a \ + ${SWIG_INSTALL_DIR}/pcre/lib/libpcreposix.a" + ./configure + --prefix=${SWIG_INSTALL_DIR} + --with-pcre-prefix=${SWIG_INSTALL_DIR}/pcre + --with-python=${PYTHON_EXECUTABLE} + BUILD_COMMAND cd ${SWIG_SOURCES_DIR}/src/swig && make + INSTALL_COMMAND cd ${SWIG_SOURCES_DIR}/src/swig && make install + DEPENDS pcre python + ) + + set(SWIG_DIR ${SWIG_INSTALL_DIR}/share/swig/${SWIG_TARGET_VERSION} CACHE FILEPATH "SWIG Directory" FORCE) + set(SWIG_EXECUTABLE ${SWIG_INSTALL_DIR}/bin/swig CACHE FILEPATH "SWIG Executable" FORCE) + ENDIF(WIN32) +#ENDIF() + diff --git a/cmake/external/warpctc.cmake b/cmake/external/warpctc.cmake new file mode 100644 index 00000000000..57864aca69c --- /dev/null +++ b/cmake/external/warpctc.cmake @@ -0,0 +1,39 @@ +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. +# +# 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. + +INCLUDE(ExternalProject) + +SET(WARPCTC_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/warpctc) +SET(WARPCTC_INSTALL_DIR ${PROJECT_BINARY_DIR}/warpctc) + +ExternalProject_Add( + warpctc + GIT_REPOSITORY "https://github.com/gangliao/warp-ctc.git" + PREFIX ${WARPCTC_SOURCES_DIR} + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${WARPCTC_INSTALL_DIR} + CMAKE_ARGS -DWITH_GPU=${CUDA_FOUND} +) + +SET(WARPCTC_INCLUDE_DIR "${WARP_INSTALL_DIR}/include" CACHE PATH "Warp-ctc Directory" FORCE) +INCLUDE_DIRECTORIES(${WARPCTC_INCLUDE_DIR}) + +IF(WIN32) + set(WARPCTC_LIBRARIES + "${WARPCTC_INSTALL_DIR}/lib/warpctc.dll" CACHE FILEPATH "Warp-ctc Library" FORCE) +ELSE(WIN32) + set(WARPCTC_LIBRARIES + "${WARPCTC_INSTALL_DIR}/lib/libwarpctc.so" CACHE FILEPATH "Warp-ctc Library" FORCE) +ENDIF(WIN32) + +LIST(APPEND external_project_dependencies warpctc) diff --git a/cmake/external/zlib.cmake b/cmake/external/zlib.cmake new file mode 100644 index 00000000000..ec44467aa70 --- /dev/null +++ b/cmake/external/zlib.cmake @@ -0,0 +1,44 @@ +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. +# +# 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. + +INCLUDE(ExternalProject) + +SET(ZLIB_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib) +SET(ZLIB_INSTALL_DIR ${PROJECT_BINARY_DIR}/zlib) + +ExternalProject_Add( + zlib + GIT_REPOSITORY "https://github.com/madler/zlib.git" + GIT_TAG "v1.2.8" + PREFIX ${ZLIB_SOURCES_DIR} + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${ZLIB_INSTALL_DIR} + CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF + CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON + CMAKE_ARGS -DCMAKE_MACOSX_RPATH=ON + LOG_DOWNLOAD =ON + UPDATE_COMMAND "" +) + +SET(ZLIB_ROOT ${ZLIB_INSTALL_DIR} CACHE PATH "zlib root directory." FORCE) + +SET(ZLIB_INCLUDE_DIR "${ZLIB_INSTALL_DIR}/include" CACHE PATH "zlib include directory." FORCE) +INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) + +IF(WIN32) + SET(ZLIB_LIBRARIES "${ZLIB_INSTALL_DIR}/lib/zlibstatic.lib" CACHE FILEPATH "zlib library." FORCE) +ELSE(WIN32) + set(ZLIB_LIBRARIES "${ZLIB_INSTALL_DIR}/lib/libz.a" CACHE FILEPATH "zlib library." FORCE) +ENDIF(WIN32) + +LIST(APPEND external_project_dependencies zlib) -- GitLab