|
| 1 | +# Copyright (c) 2024, Oracle and/or its affiliates. |
| 2 | +# |
| 3 | +# This program is free software; you can redistribute it and/or modify |
| 4 | +# it under the terms of the GNU General Public License, version 2.0, |
| 5 | +# as published by the Free Software Foundation. |
| 6 | +# |
| 7 | +# This program is designed to work with certain software (including |
| 8 | +# but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | +# as designated in a particular file or component or in included license |
| 10 | +# documentation. The authors of MySQL hereby grant you an additional |
| 11 | +# permission to link the program and your derivative works with the |
| 12 | +# separately licensed software that they have either included with |
| 13 | +# the program or referenced in the documentation. |
| 14 | +# |
| 15 | +# This program is distributed in the hope that it will be useful, |
| 16 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | +# GNU General Public License, version 2.0, for more details. |
| 19 | +# |
| 20 | +# You should have received a copy of the GNU General Public License |
| 21 | +# along with this program; if not, write to the Free Software |
| 22 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | + |
| 24 | +INCLUDE(ExternalProject) |
| 25 | + |
| 26 | +SET(TCMALLOC_SOURCE_DIR |
| 27 | + "${CMAKE_SOURCE_DIR}/extra/gperftools/gperftools-2.15" |
| 28 | + ) |
| 29 | + |
| 30 | +FIND_PROGRAM(MAKE_EXECUTABLE make) |
| 31 | + |
| 32 | +SET(TCMALLOC_CMAKE_ARGS |
| 33 | + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} |
| 34 | + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} |
| 35 | + -DGPERFTOOLS_BUILD_STATIC=OFF |
| 36 | + -Dgperftools_build_benchmark=OFF |
| 37 | + -Dgperftools_enable_libunwind=OFF |
| 38 | + -DBUILD_TESTING=OFF |
| 39 | + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/tcmalloc |
| 40 | + -DCMAKE_INSTALL_LIBDIR=${CMAKE_BINARY_DIR}/library_output_directory |
| 41 | +) |
| 42 | + |
| 43 | +IF(LINUX_RHEL AND ALTERNATIVE_GCC) |
| 44 | + LIST(APPEND TCMALLOC_CMAKE_ARGS -DCMAKE_C_FLAGS="-B${GCC_B_PREFIX}") |
| 45 | + LIST(APPEND TCMALLOC_CMAKE_ARGS -DCMAKE_CXX_FLAGS="-B${GCC_B_PREFIX}") |
| 46 | +ENDIF() |
| 47 | + |
| 48 | +IF(ALTERNATIVE_LD) |
| 49 | + LIST(APPEND TCMALLOC_CMAKE_ARGS -DCMAKE_LINKER=${ALTERNATIVE_LD}) |
| 50 | +ENDIF() |
| 51 | + |
| 52 | +IF(ALTERNATIVE_AR) |
| 53 | + LIST(APPEND TCMALLOC_CMAKE_ARGS -DCMAKE_AR=${ALTERNATIVE_AR}) |
| 54 | +ENDIF() |
| 55 | + |
| 56 | +IF(ALTERNATIVE_RANLIB) |
| 57 | + LIST(APPEND TCMALLOC_CMAKE_ARGS -DCMAKE_RANLIB=${ALTERNATIVE_RANLIB}) |
| 58 | +ENDIF() |
| 59 | + |
| 60 | +EXTERNALPROJECT_ADD(tcmalloc_ext |
| 61 | + SOURCE_DIR ${TCMALLOC_SOURCE_DIR} |
| 62 | + CMAKE_ARGS ${TCMALLOC_CMAKE_ARGS} |
| 63 | + BUILD_BYPRODUCTS |
| 64 | + "${CMAKE_BINARY_DIR}/lib/libtcmalloc.so" |
| 65 | + "${CMAKE_BINARY_DIR}/lib/libtcmalloc.so.9.16.5" |
| 66 | + "${CMAKE_BINARY_DIR}/lib/libtcmalloc_debug.so" |
| 67 | + "${CMAKE_BINARY_DIR}/lib/libtcmalloc_debug.so.9.16.5" |
| 68 | + ) |
| 69 | + |
| 70 | +# Cannot use INSTALL_PRIVATE_LIBRARY because these are not targets. |
| 71 | +INSTALL(FILES |
| 72 | + "${CMAKE_BINARY_DIR}/lib/libtcmalloc.so" |
| 73 | + "${CMAKE_BINARY_DIR}/lib/libtcmalloc.so.9.16.5" |
| 74 | + DESTINATION "${INSTALL_PRIV_LIBDIR}" COMPONENT SharedLibraries |
| 75 | + PERMISSIONS |
| 76 | + OWNER_READ OWNER_WRITE OWNER_EXECUTE |
| 77 | + GROUP_READ GROUP_EXECUTE |
| 78 | + WORLD_READ WORLD_EXECUTE |
| 79 | +) |
| 80 | + |
| 81 | +ADD_LIBRARY(my_tcmalloc SHARED IMPORTED GLOBAL) |
| 82 | +SET_TARGET_PROPERTIES(my_tcmalloc PROPERTIES |
| 83 | + IMPORTED_LINK_INTERFACE_LANGUAGES "C" |
| 84 | + IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/lib/libtcmalloc.so") |
| 85 | + |
| 86 | +ADD_LIBRARY(my_tcmalloc_debug SHARED IMPORTED GLOBAL) |
| 87 | +SET_TARGET_PROPERTIES(my_tcmalloc_debug PROPERTIES |
| 88 | + IMPORTED_LINK_INTERFACE_LANGUAGES "C" |
| 89 | + IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/lib/libtcmalloc_debug.so") |
| 90 | + |
| 91 | +ADD_DEPENDENCIES(my_tcmalloc tcmalloc_ext) |
| 92 | +ADD_DEPENDENCIES(my_tcmalloc_debug tcmalloc_ext) |
0 commit comments