cryptopp.cmake 3.4 KB
Newer Older
Y
Yanghello 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2016 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.

15
include(ExternalProject)
Y
Yanghello 已提交
16

17 18 19 20 21 22 23
set(CRYPTOPP_PREFIX_DIR ${THIRD_PARTY_PATH}/cryptopp)
set(CRYPTOPP_INSTALL_DIR ${THIRD_PARTY_PATH}/install/cryptopp)
set(CRYPTOPP_INCLUDE_DIR
    "${CRYPTOPP_INSTALL_DIR}/include"
    CACHE PATH "cryptopp include directory." FORCE)
set(CRYPTOPP_REPOSITORY ${GIT_URL}/weidai11/cryptopp.git)
set(CRYPTOPP_TAG CRYPTOPP_8_2_0)
Y
Yanghello 已提交
24

25 26 27 28
if(WIN32)
  set(CRYPTOPP_LIBRARIES
      "${CRYPTOPP_INSTALL_DIR}/lib/cryptopp-static.lib"
      CACHE FILEPATH "cryptopp library." FORCE)
29
  # There is a compilation parameter "/FI\"winapifamily.h\"" or "/FIwinapifamily.h" can't be used correctly
30
  # with Ninja on Windows. The only difference between the patch file and original
31
  # file is that the compilation parameters are changed to '/nologo'. This
32 33
  # patch command can be removed when upgrading to a higher version.
  if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
34 35 36
    set(CRYPTOPP_PATCH_COMMAND
        ${CMAKE_COMMAND} -E copy_if_different
        "${PADDLE_SOURCE_DIR}/patches/cryptopp/CMakeLists.txt" "<SOURCE_DIR>/")
37
  endif()
38 39 40 41 42
else(WIN32)
  set(CRYPTOPP_LIBRARIES
      "${CRYPTOPP_INSTALL_DIR}/lib/libcryptopp.a"
      CACHE FILEPATH "cryptopp library." FORCE)
endif(WIN32)
Y
Yanghello 已提交
43

44 45 46
if(APPLE AND WITH_ARM)
  set(CMAKE_CXX_FLAGS "-DCRYPTOPP_ARM_CRC32_AVAILABLE=0")
endif()
T
tianshuo78520a 已提交
47

48 49 50 51 52 53 54 55 56 57 58 59
set(CRYPTOPP_CMAKE_ARGS
    ${COMMON_CMAKE_ARGS}
    -DBUILD_SHARED=ON
    -DBUILD_STATIC=ON
    -DBUILD_TESTING=OFF
    -DCMAKE_INSTALL_LIBDIR=${CRYPTOPP_INSTALL_DIR}/lib
    -DCMAKE_INSTALL_PREFIX=${CRYPTOPP_INSTALL_DIR}
    -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
    -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
    -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
    -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
    -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
Y
Yanghello 已提交
60

61
include_directories(${CRYPTOPP_INCLUDE_DIR})
Y
Yanghello 已提交
62 63

ExternalProject_Add(
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  extern_cryptopp
  ${EXTERNAL_PROJECT_LOG_ARGS} ${SHALLOW_CLONE}
  GIT_REPOSITORY ${CRYPTOPP_REPOSITORY}
  GIT_TAG ${CRYPTOPP_TAG}
  PREFIX ${CRYPTOPP_PREFIX_DIR}
  UPDATE_COMMAND ""
  PATCH_COMMAND
  COMMAND ${CMAKE_COMMAND} -E remove_directory "<SOURCE_DIR>/cmake/"
  COMMAND git clone ${GIT_URL}/noloader/cryptopp-cmake "<SOURCE_DIR>/cmake"
  COMMAND cd "<SOURCE_DIR>/cmake" && git checkout tags/${CRYPTOPP_TAG} -b
          ${CRYPTOPP_TAG}
  COMMAND ${CMAKE_COMMAND} -E copy_directory "<SOURCE_DIR>/cmake/"
          "<SOURCE_DIR>/"
  COMMAND ${CRYPTOPP_PATCH_COMMAND}
  INSTALL_DIR ${CRYPTOPP_INSTALL_DIR}
  CMAKE_ARGS ${CRYPTOPP_CMAKE_ARGS}
  CMAKE_CACHE_ARGS
    -DCMAKE_INSTALL_PREFIX:PATH=${CRYPTOPP_INSTALL_DIR}
    -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
    -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
  BUILD_BYPRODUCTS ${CRYPTOPP_LIBRARIES})
Y
Yanghello 已提交
85

86 87 88
add_library(cryptopp STATIC IMPORTED GLOBAL)
set_property(TARGET cryptopp PROPERTY IMPORTED_LOCATION ${CRYPTOPP_LIBRARIES})
add_dependencies(cryptopp extern_cryptopp)