From 1d79f1f79dc4afdb39567547de3a395d9fddd50d Mon Sep 17 00:00:00 2001 From: Allen Guo Date: Mon, 1 Aug 2022 14:13:10 +0800 Subject: [PATCH] support build with Ninja on Linux (#44210) * support ninja * fix mkldnn on windows * fix mkldnn on windows up1 * up2 * up3 * fix gflags * BUILD_BYPRODUCTS_OPTION -> BUILD_BYPRODUCTS_ARGS * use CMAKE_COMMAND * up x --- cmake/external/dgc.cmake | 2 +- cmake/external/gflags.cmake | 4 ++-- cmake/external/mkldnn.cmake | 9 ++++++++- cmake/external/openblas.cmake | 2 +- cmake/external/rocksdb.cmake | 3 ++- cmake/third_party.cmake | 3 +++ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cmake/external/dgc.cmake b/cmake/external/dgc.cmake index 9c22ee89d4..ef1ee1b002 100644 --- a/cmake/external/dgc.cmake +++ b/cmake/external/dgc.cmake @@ -33,7 +33,7 @@ ExternalProject_Add( URL_MD5 "94e6fa1bc97169d0e1aad44570fe3251" PREFIX "${DGC_PREFIX_DIR}" CONFIGURE_COMMAND "" - BUILD_COMMAND make -j $(nproc) + BUILD_COMMAND make -j${NPROC} INSTALL_COMMAND mkdir -p ${DGC_INSTALL_DIR}/lib/ ${DGC_INCLUDE_DIR}/dgc && cp ${DGC_SOURCES_DIR}/build/lib/libdgc.a ${DGC_LIBRARIES} && cp diff --git a/cmake/external/gflags.cmake b/cmake/external/gflags.cmake index 68255b4d60..7d5bb6caed 100755 --- a/cmake/external/gflags.cmake +++ b/cmake/external/gflags.cmake @@ -29,8 +29,8 @@ else() set(GFLAGS_LIBRARIES "${GFLAGS_INSTALL_DIR}/lib/libgflags.a" CACHE FILEPATH "GFLAGS_LIBRARIES" FORCE) - set(BUILD_COMMAND $(MAKE) --silent) - set(INSTALL_COMMAND $(MAKE) install) + set(BUILD_COMMAND ${CMAKE_COMMAND} --build .) + set(INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install) endif() include_directories(${GFLAGS_INCLUDE_DIR}) diff --git a/cmake/external/mkldnn.cmake b/cmake/external/mkldnn.cmake index 909d223060..e4f25bc711 100644 --- a/cmake/external/mkldnn.cmake +++ b/cmake/external/mkldnn.cmake @@ -61,6 +61,12 @@ else() CACHE FILEPATH "mkldnn library." FORCE) endif() +if(LINUX) + set(BUILD_BYPRODUCTS_ARGS ${MKLDNN_LIB}) +else() + set(BUILD_BYPRODUCTS_ARGS "") +endif() + ExternalProject_Add( ${MKLDNN_PROJECT} ${EXTERNAL_PROJECT_LOG_ARGS} ${SHALLOW_CLONE} @@ -83,7 +89,8 @@ ExternalProject_Add( -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DDNNL_BUILD_TESTS=OFF -DDNNL_BUILD_EXAMPLES=OFF - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR}) + CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR} + BUILD_BYPRODUCTS ${BUILD_BYPRODUCTS_ARGS}) message(STATUS "MKLDNN library: ${MKLDNN_LIB}") add_definitions(-DPADDLE_WITH_MKLDNN) diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index a93121e95c..ceb7e17993 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -53,7 +53,7 @@ if(NOT WIN32) PREFIX ${CBLAS_PREFIX_DIR} INSTALL_DIR ${CBLAS_INSTALL_DIR} BUILD_IN_SOURCE 1 - BUILD_COMMAND make -j$(nproc) ${COMMON_ARGS} ${OPTIONAL_ARGS} + BUILD_COMMAND make -j${NPROC} ${COMMON_ARGS} ${OPTIONAL_ARGS} INSTALL_COMMAND make install NO_SHARED=1 NO_LAPACK=1 PREFIX= UPDATE_COMMAND "" CONFIGURE_COMMAND "" diff --git a/cmake/external/rocksdb.cmake b/cmake/external/rocksdb.cmake index 2e90f50e3c..41a1916dc3 100644 --- a/cmake/external/rocksdb.cmake +++ b/cmake/external/rocksdb.cmake @@ -44,7 +44,8 @@ ExternalProject_Add( ${ROCKSDB_PREFIX_DIR}/src/extern_rocksdb/librocksdb.a ${ROCKSDB_LIBRARIES} && cp -r ${ROCKSDB_PREFIX_DIR}/src/extern_rocksdb/include ${ROCKSDB_INSTALL_DIR}/ - BUILD_IN_SOURCE 1) + BUILD_IN_SOURCE 1 + BYPRODUCTS ${ROCKSDB_LIBRARIES}) add_dependencies(extern_rocksdb snappy) diff --git a/cmake/third_party.cmake b/cmake/third_party.cmake index dd8013d807..94fb1b4d83 100755 --- a/cmake/third_party.cmake +++ b/cmake/third_party.cmake @@ -27,6 +27,9 @@ set(THIRD_PARTY_CACHE_PATH set(THIRD_PARTY_BUILD_TYPE Release) set(third_party_deps) +include(ProcessorCount) +ProcessorCount(NPROC) + # cache funciton to avoid repeat download code of third_party. # This function has 4 parameters, URL / REPOSITOR / TAG / DIR: # 1. URL: specify download url of 3rd party -- GitLab