libmct.cmake 3.0 KB
Newer Older
H
libmct  
heqiaozhi 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserved.
#
# 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.

IF(NOT ${WITH_LIBMCT})
  return()
ENDIF(NOT ${WITH_LIBMCT})

IF(WIN32 OR APPLE)
    MESSAGE(WARNING
        "Windows or Mac is not supported with LIBMCT in Paddle yet."
        "Force WITH_LIBMCT=OFF")
    SET(WITH_LIBMCT OFF CACHE STRING "Disable LIBMCT package in Windows and MacOS" FORCE)
    return()
ENDIF()

INCLUDE(ExternalProject)

SET(LIBMCT_PROJECT       "extern_libmct")
IF((NOT DEFINED LIBMCT_VER) OR (NOT DEFINED LIBMCT_URL))
  MESSAGE(STATUS "use pre defined download url")
H
heqiaozhi 已提交
32 33 34
  SET(LIBMCT_VER "0.1.0" CACHE STRING "" FORCE)
  SET(LIBMCT_NAME "libmct" CACHE STRING "" FORCE)
  SET(LIBMCT_URL "https://raw.githubusercontent.com/PaddlePaddle/Fleet/release/${LIBMCT_VER}/${LIBMCT_NAME}.tar.gz" CACHE STRING "" FORCE) 
H
libmct  
heqiaozhi 已提交
35
ENDIF()
H
heqiaozhi 已提交
36
MESSAGE(STATUS "LIBMCT_NAME: ${LIBMCT_NAME}, LIBMCT_URL: ${LIBMCT_URL}")
H
libmct  
heqiaozhi 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50
SET(LIBMCT_SOURCE_DIR    "${THIRD_PARTY_PATH}/libmct")
SET(LIBMCT_DOWNLOAD_DIR  "${LIBMCT_SOURCE_DIR}/src/${LIBMCT_PROJECT}")
SET(LIBMCT_DST_DIR       "libmct")
SET(LIBMCT_INSTALL_ROOT  "${THIRD_PARTY_PATH}/install")
SET(LIBMCT_INSTALL_DIR   ${LIBMCT_INSTALL_ROOT}/${LIBMCT_DST_DIR})
SET(LIBMCT_ROOT          ${LIBMCT_INSTALL_DIR})
SET(LIBMCT_INC_DIR       ${LIBMCT_ROOT}/include)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${LIBMCT_ROOT}/lib")

INCLUDE_DIRECTORIES(${LIBMCT_INC_DIR})

FILE(WRITE ${LIBMCT_DOWNLOAD_DIR}/CMakeLists.txt
  "PROJECT(LIBMCT)\n"
  "cmake_minimum_required(VERSION 3.0)\n"
H
heqiaozhi 已提交
51
  "install(DIRECTORY ${LIBMCT_NAME}/include ${LIBMCT_NAME}/lib \n"
H
libmct  
heqiaozhi 已提交
52 53 54 55 56 57 58
  "        DESTINATION ${LIBMCT_DST_DIR})\n")

ExternalProject_Add(
    ${LIBMCT_PROJECT}
    ${EXTERNAL_PROJECT_LOG_ARGS}
    PREFIX                ${LIBMCT_SOURCE_DIR}
    DOWNLOAD_DIR          ${LIBMCT_DOWNLOAD_DIR}
H
heqiaozhi 已提交
59 60
    DOWNLOAD_COMMAND      wget --no-check-certificate ${LIBMCT_URL} -c -q -O ${LIBMCT_NAME}.tar.gz
                          && tar zxvf ${LIBMCT_NAME}.tar.gz
H
libmct  
heqiaozhi 已提交
61 62 63 64 65 66
    DOWNLOAD_NO_PROGRESS  1
    UPDATE_COMMAND        ""
    CMAKE_ARGS            -DCMAKE_INSTALL_PREFIX=${LIBMCT_INSTALL_ROOT}
    CMAKE_CACHE_ARGS      -DCMAKE_INSTALL_PREFIX:PATH=${LIBMCT_INSTALL_ROOT}
)

67 68 69 70 71 72 73 74 75
if (${CMAKE_VERSION} VERSION_LESS "3.3.0" OR NOT WIN32)
    set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/boost_dummy.c)
    file(WRITE ${dummyfile} "const char *dummy = \"${dummyfile}\";")
    add_library(libmct STATIC ${dummyfile})
else()
    add_library(libmct INTERFACE)
endif()

#ADD_LIBRARY(libmct SHARED IMPORTED GLOBAL)
H
libmct  
heqiaozhi 已提交
76 77 78
ADD_DEPENDENCIES(libmct ${LIBMCT_PROJECT})
LIST(APPEND external_project_dependencies libmct)