diff --git a/CMakeLists.txt b/CMakeLists.txt index eaec3883e2944e0b4eaf0016c39240ffd07a1eee..50070c7fc05133da758650eb5ac50e32effe63c9 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License -cmake_minimum_required(VERSION 3.10) -cmake_policy(VERSION 3.10) +if(APPLE AND WITH_ARM) + # cmake 3.19.2 version starts to support M1 + cmake_minimum_required(VERSION 3.19.2) + cmake_policy(VERSION 3.19.2) +else(APPLE AND WITH_ARM) + cmake_minimum_required(VERSION 3.10) + cmake_policy(VERSION 3.10) +endif(APPLE AND WITH_ARM) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(PADDLE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(PADDLE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) @@ -73,6 +79,11 @@ if(WITH_MUSL) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations -Wno-deprecated-declarations -Wno-error=pessimizing-move -Wno-error=deprecated-copy") endif() +if(APPLE AND WITH_ARM) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target arm64-apple-darwin") + set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -target arm64-apple-darwin") +endif() + if(WITH_ASCEND_CL AND NOT WITH_ASCEND_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0") endif() @@ -332,8 +343,9 @@ endif() if(WITH_ARM) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") - set(WITH_XBYAK OFF CACHE STRING "Disable XBYAK when compiling WITH_ARM=ON" FORCE) + set(WITH_XBYAK OFF CACHE STRING "Disable XBYAK when compiling WITH_ARM=ON." FORCE) set(WITH_MKL OFF CACHE STRING "Disable MKL when compiling WITH_ARM=ON." FORCE) + set(WITH_AVX OFF CACHE STRING "Disable AVX when compiling WITH_AVX=OFF." FORCE) add_definitions(-DPADDLE_WITH_ARM) endif() diff --git a/cmake/external/cryptopp.cmake b/cmake/external/cryptopp.cmake index f7f7a9b52e895dcfb39860331161d902080fe4c6..aedd40aec68481e1a92924bcd484384ecdd87d88 100644 --- a/cmake/external/cryptopp.cmake +++ b/cmake/external/cryptopp.cmake @@ -33,6 +33,10 @@ ELSE(WIN32) SET(CRYPTOPP_LIBRARIES "${CRYPTOPP_INSTALL_DIR}/lib/libcryptopp.a" CACHE FILEPATH "cryptopp library." FORCE) ENDIF(WIN32) +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 diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 19ba6d15c59ea802cc94ea6138871c15cb49077b..a6033a20c6fb06c6e6b26100c1997b7881767e85 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -19,6 +19,10 @@ SET(CBLAS_SOURCE_DIR ${THIRD_PARTY_PATH}/openblas/src/extern_openblas) SET(CBLAS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/openblas) SET(CBLAS_REPOSITORY ${GIT_URL}/xianyi/OpenBLAS.git) SET(CBLAS_TAG v0.3.7) +if(APPLE AND WITH_ARM) + SET(CBLAS_TAG v0.3.13) +endif() + if(WITH_MIPS) SET(CBLAS_TAG v0.3.13) endif() diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 94fd29b905009ba1202abdb184d7c35b185489e5..7afff25664bbbb6f8ac93392dc39ed621e57e849 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -186,8 +186,11 @@ endif() endif(NOT WIN32) if (APPLE) - # On Mac OS X build fat binaries with x86_64 architectures by default. - set (CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX" FORCE) + if(WITH_ARM) + set (CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Build architectures for OSX" FORCE) + else(WITH_ARM) + set (CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX" FORCE) + endif(WITH_ARM) # On Mac OS X register class specifier is deprecated and will cause warning error on latest clang 10.0 set (COMMON_FLAGS -Wno-deprecated-register) endif(APPLE)