Skip to content

Commit

Permalink
[fix][cmake] Optimize cmake speed for openssl and libunwind.
Browse files Browse the repository at this point in the history
Signed-off-by: Ketor <[email protected]>
  • Loading branch information
ketor authored and rock-git committed May 14, 2024
1 parent f41789e commit 91a1974
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
13 changes: 5 additions & 8 deletions cmake/gperftools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}/")
Expand Down
15 changes: 5 additions & 10 deletions cmake/libunwind.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
22 changes: 9 additions & 13 deletions cmake/openssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 91a1974

Please sign in to comment.