Files
2026-07-13 12:40:42 +08:00

97 lines
3.5 KiB
CMake

# 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.
include(ExternalProject)
set(CRYPTOPP_SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/cryptopp)
set(CRYPTOPP_CMAKE_SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/cryptopp-cmake)
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_TAG CRYPTOPP_8_6_0)
# cryptopp-cmake 8.6.0 adds the full CMAKE_CXX_FLAGS string through
# add_compile_options(), which makes compilers treat Paddle's space-separated
# flags as a single input file. Paddle also keeps the Windows Ninja workaround
# for "/FIwinapifamily.h" here.
set(CRYPTOPP_PATCH_COMMAND
${CMAKE_COMMAND} -E copy_if_different
"${PADDLE_SOURCE_DIR}/patches/cryptopp/CMakeLists.txt" "<SOURCE_DIR>/")
if(WIN32)
set(CRYPTOPP_LIBRARIES
"${CRYPTOPP_INSTALL_DIR}/lib/cryptopp-static.lib"
CACHE FILEPATH "cryptopp library." FORCE)
else()
set(CRYPTOPP_LIBRARIES
"${CRYPTOPP_INSTALL_DIR}/lib/libcryptopp.a"
CACHE FILEPATH "cryptopp library." FORCE)
endif()
if(APPLE AND WITH_ARM)
set(CMAKE_CXX_FLAGS "-DCRYPTOPP_ARM_CRC32_AVAILABLE=0")
endif()
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})
# For CMake >= 4.0.0, set policy compatibility for cryptopp's CMake.
if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")
message(
WARNING
"cryptopp: forcing CMake policy compatibility for CMake >= 4.0 (CMAKE_POLICY_VERSION_MINIMUM=3.5)"
)
list(APPEND CRYPTOPP_CMAKE_ARGS -DCMAKE_POLICY_VERSION_MINIMUM=3.5)
endif()
include_directories(${CRYPTOPP_INCLUDE_DIR})
ExternalProject_Add(
extern_cryptopp
${EXTERNAL_PROJECT_LOG_ARGS} ${SHALLOW_CLONE}
PREFIX ${CRYPTOPP_PREFIX_DIR}
SOURCE_DIR ${CRYPTOPP_SOURCE_DIR}
UPDATE_COMMAND ""
PATCH_COMMAND
COMMAND ${CMAKE_COMMAND} -E copy "${CRYPTOPP_CMAKE_SOURCE_DIR}/CMakeLists.txt"
"<SOURCE_DIR>/CMakeLists.txt"
COMMAND
${CMAKE_COMMAND} -E copy
"${CRYPTOPP_CMAKE_SOURCE_DIR}/cryptopp-config.cmake"
"<SOURCE_DIR>/cryptopp-config.cmake"
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})
add_library(cryptopp STATIC IMPORTED GLOBAL)
set_property(TARGET cryptopp PROPERTY IMPORTED_LOCATION ${CRYPTOPP_LIBRARIES})
add_dependencies(cryptopp extern_cryptopp)