From 91a19740d0661f5a6139b82fd2206bd716627b9c Mon Sep 17 00:00:00 2001 From: Ketor Date: Mon, 13 May 2024 19:21:13 +0800 Subject: [PATCH] [fix][cmake] Optimize cmake speed for openssl and libunwind. Signed-off-by: Ketor --- cmake/gperftools.cmake | 13 +++++-------- cmake/libunwind.cmake | 15 +++++---------- cmake/openssl.cmake | 22 +++++++++------------- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/cmake/gperftools.cmake b/cmake/gperftools.cmake index d3ea169ba..2950ef7a5 100644 --- a/cmake/gperftools.cmake +++ b/cmake/gperftools.cmake @@ -22,14 +22,11 @@ SET(GPERFTOOLS_INCLUDE_DIR "${GPERFTOOLS_INSTALL_DIR}/include" CACHE PATH "gperf SET(GPERFTOOLS_LIBRARIES "${GPERFTOOLS_INSTALL_DIR}/lib/libtcmalloc_and_profiler.a" CACHE FILEPATH "gperftools library." FORCE) SET(GPERFTOOLS_MINIMAL_LIBRARIES "${GPERFTOOLS_INSTALL_DIR}/lib/libtcmalloc_minimal.a" CACHE FILEPATH "gperftools library." FORCE) -if(BRPC_ENABLE_CPU_PROFILER) - set(CONFIGURE_COMMAND_GPERF sh autogen.sh COMMAND sh ./configure --prefix=${GPERFTOOLS_INSTALL_DIR} --enable-shared=no --enable-static=yes --with-pic --enable-libunwind --enable-cpu-profiler --enable-heap-profiler --enable--heap-checker CPPFLAGS=-I${THIRD_PARTY_PATH}/install/libunwind/include LDFLAGS=-L${THIRD_PARTY_PATH}/install/libunwind/lib CXXFLAGS=-g) - message(STATUS "gperftools found BRPC_ENABLE_CPU_PROFILER is enabled, enable all profiler") -else() - set(CONFIGURE_COMMAND_GPERF sh autogen.sh COMMAND sh ./configure --prefix=${GPERFTOOLS_INSTALL_DIR} --enable-shared=no --enable-static=yes --enable-minimal CPPFLAGS=-I${THIRD_PARTY_PATH}/install/libunwind/include LDFLAGS=-L${THIRD_PARTY_PATH}/install/libunwind/lib CXXFLAGS=-g) - message(STATUS "gperftools found BRPC_ENABLE_CPU_PROFILER is disable, use --enable-minimal") -endif() - +set(CONFIGURE_COMMAND_GPERF sh autoreconf -i -f + COMMAND patch --forward -t --reject-file=- m4/libtool.m4 m4/libtool.patch + COMMAND sh autoreconf -i + COMMAND sh configure --prefix=${GPERFTOOLS_INSTALL_DIR} --enable-shared=no --enable-static=yes --with-pic --enable-libunwind --enable-cpu-profiler --enable-heap-profiler --enable-heap-checker CPPFLAGS=-I${THIRD_PARTY_PATH}/install/libunwind/include LDFLAGS=-L${THIRD_PARTY_PATH}/install/libunwind/lib CXXFLAGS=-g) +message(STATUS "gperftools enable all profiler") FILE(WRITE ${GPERFTOOLS_BUILD_DIR}/copy_repo.sh "mkdir -p ${GPERFTOOLS_BUILD_DIR} && cp -rf ${GPERFTOOLS_SOURCES_DIR}/* ${GPERFTOOLS_BUILD_DIR}/") diff --git a/cmake/libunwind.cmake b/cmake/libunwind.cmake index 44a19248a..69ad47d17 100644 --- a/cmake/libunwind.cmake +++ b/cmake/libunwind.cmake @@ -16,27 +16,22 @@ INCLUDE(ExternalProject) message(STATUS "Include libunwind...") SET(LIBUNWIND_SOURCES_DIR ${CMAKE_SOURCE_DIR}/contrib/libunwind) -SET(LIBUNWIND_BUILD_DIR ${THIRD_PARTY_PATH}/build/libunwind) +SET(LIBUNWIND_BINARY_DIR ${THIRD_PARTY_PATH}/build/libunwind) SET(LIBUNWIND_INSTALL_DIR ${THIRD_PARTY_PATH}/install/libunwind) SET(LIBUNWIND_INCLUDE_DIR "${LIBUNWIND_INSTALL_DIR}/include" CACHE PATH "libunwind include directory." FORCE) SET(LIBUNWIND_LIBRARIES "${LIBUNWIND_INSTALL_DIR}/lib/libunwind.a" CACHE FILEPATH "libunwind library." FORCE) SET(LIBUNWIND_GENERIC_LIBRARIES "${LIBUNWIND_INSTALL_DIR}/lib/libunwind-generic.a" CACHE FILEPATH "libunwind generic library." FORCE) SET(LIBUNWIND_ARCH_LIBRARIES "${LIBUNWIND_INSTALL_DIR}/lib/libunwind-${CMAKE_HOST_SYSTEM_PROCESSOR}.a" CACHE FILEPATH "libunwind library." FORCE) -FILE(WRITE ${LIBUNWIND_BUILD_DIR}/copy_repo.sh - "mkdir -p ${LIBUNWIND_BUILD_DIR} && cp -rf ${LIBUNWIND_SOURCES_DIR}/* ${LIBUNWIND_BUILD_DIR}/") - -execute_process(COMMAND sh ${LIBUNWIND_BUILD_DIR}/copy_repo.sh) - ExternalProject_Add( extern_libunwind ${EXTERNAL_PROJECT_LOG_ARGS} - SOURCE_DIR ${LIBUNWIND_BUILD_DIR} - PREFIX ${LIBUNWIND_BUILD_DIR} + SOURCE_DIR ${LIBUNWIND_SOURCES_DIR} + BINARY_DIR ${LIBUNWIND_BINARY_DIR} + PREFIX ${LIBUNWIND_BINARY_DIR} - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND autoreconf -i COMMAND ./configure --prefix ${LIBUNWIND_INSTALL_DIR} --disable-minidebuginfo --enable-shared --enable-static --with-pic --disable-msabi-support + CONFIGURE_COMMAND autoreconf -i ${LIBUNWIND_SOURCES_DIR} COMMAND ${LIBUNWIND_SOURCES_DIR}/configure --prefix ${LIBUNWIND_INSTALL_DIR} --disable-minidebuginfo --enable-shared --enable-static --with-pic --disable-msabi-support BUILD_COMMAND $(MAKE) INSTALL_COMMAND $(MAKE) install ) diff --git a/cmake/openssl.cmake b/cmake/openssl.cmake index 4afdebc9d..40f067143 100644 --- a/cmake/openssl.cmake +++ b/cmake/openssl.cmake @@ -16,32 +16,28 @@ INCLUDE(ExternalProject) message(STATUS "Include openssl...") SET(OPENSSL_SOURCES_DIR ${CMAKE_SOURCE_DIR}/contrib/openssl) -SET(OPENSSL_BUILD_DIR ${THIRD_PARTY_PATH}/build/openssl) +SET(OPENSSL_BINARY_DIR ${THIRD_PARTY_PATH}/build/openssl) SET(OPENSSL_INSTALL_DIR ${THIRD_PARTY_PATH}/install/openssl) SET(OPENSSL_INCLUDE_DIR "${OPENSSL_INSTALL_DIR}/include" CACHE PATH "openssl include directory." FORCE) SET(OPENSSL_LIBRARIES "${OPENSSL_INSTALL_DIR}/lib/libssl.a" CACHE FILEPATH "openssl library." FORCE) SET(CRYPTO_LIBRARIES "${OPENSSL_INSTALL_DIR}/lib/libcrypto.a" CACHE FILEPATH "openssl library." FORCE) -FILE(WRITE ${OPENSSL_BUILD_DIR}/copy_repo.sh - "mkdir -p ${OPENSSL_BUILD_DIR} && cp -rf ${OPENSSL_SOURCES_DIR}/* ${OPENSSL_BUILD_DIR}/") - -execute_process(COMMAND sh ${OPENSSL_BUILD_DIR}/copy_repo.sh) - ExternalProject_Add( extern_openssl ${EXTERNAL_PROJECT_LOG_ARGS} - SOURCE_DIR ${OPENSSL_BUILD_DIR} - PREFIX ${OPENSSL_BUILD_DIR} + SOURCE_DIR ${OPENSSL_SOURCES_DIR} + BINARY_DIR ${OPENSSL_BINARY_DIR} + PREFIX ${OPENSSL_BINARY_DIR} UPDATE_COMMAND "" - CONFIGURE_COMMAND sh config -DOPENSSL_NO_SCTP -DOPENSSL_NO_KTLS -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -no-shared - BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND sh ${OPENSSL_SOURCES_DIR}/config -DOPENSSL_NO_SCTP -DOPENSSL_NO_KTLS -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -no-shared BUILD_COMMAND $(MAKE) INSTALL_COMMAND mkdir -p ${OPENSSL_INSTALL_DIR}/lib - COMMAND cp ${OPENSSL_BUILD_DIR}/libssl.a ${OPENSSL_INSTALL_DIR}/lib - COMMAND cp ${OPENSSL_BUILD_DIR}/libcrypto.a ${OPENSSL_INSTALL_DIR}/lib - COMMAND cp -rf ${OPENSSL_BUILD_DIR}/include ${OPENSSL_INSTALL_DIR}/ + COMMAND cp ${OPENSSL_BINARY_DIR}/libssl.a ${OPENSSL_INSTALL_DIR}/lib + COMMAND cp ${OPENSSL_BINARY_DIR}/libcrypto.a ${OPENSSL_INSTALL_DIR}/lib + COMMAND cp -rf ${OPENSSL_SOURCES_DIR}/include ${OPENSSL_INSTALL_DIR}/ + COMMAND cp -rf ${OPENSSL_BINARY_DIR}/include ${OPENSSL_INSTALL_DIR}/ ) ADD_LIBRARY(openssl STATIC IMPORTED GLOBAL)