Skip to content

Commit 3d58918

Browse files
fungofungo
authored andcommitted
Fix issue #12: Compile TokuDB SE into embedded library failed
Two problems fixed in this patch: 1. cmake regular expression can't compile for "stdc++"; 2. when create libmysqld.a archived library, object files of storage/tokudb/ft-index/src/loader.cc and storage/tokudb/ft-index/ft/loader/loader.cc conflicts, the former is overwrited, and lead to link failure finally.
1 parent c31dd4c commit 3d58918

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

cmake/merge_archives_unix.cmake.in

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,60 @@ SET(CMAKE_RANLIB "@CMAKE_RANLIB@")
2626

2727
SET(TEMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/merge_archives_${TARGET})
2828
MAKE_DIRECTORY(${TEMP_DIR})
29-
# Extract each archive to its own subdirectory(avoid object filename clashes)
29+
30+
# Extract each archive to its own subdirectory(avoid object filename
31+
# clashes) Since the lib may contain objects with the same name, we first
32+
# list the archive contents, then uniquify the object names as we extract
33+
# them.
34+
# For example, in TokuDB, objects of bellow two files conflict.
35+
# 1. storage/tokudb/ft-index/src/loader.cc
36+
# 2. storage/tokudb/ft-index/ft/loader/loader.cc
3037
FOREACH(LIB ${STATIC_LIBS})
3138
GET_FILENAME_COMPONENT(NAME_NO_EXT ${LIB} NAME_WE)
3239
SET(TEMP_SUBDIR ${TEMP_DIR}/${NAME_NO_EXT})
3340
MAKE_DIRECTORY(${TEMP_SUBDIR})
3441
EXECUTE_PROCESS(
35-
COMMAND ${CMAKE_AR} -x ${LIB}
36-
WORKING_DIRECTORY ${TEMP_SUBDIR}
37-
)
42+
COMMAND ${CMAKE_AR} -t ${LIB}
43+
OUTPUT_VARIABLE LIB_OBJS
44+
)
45+
STRING(REGEX REPLACE "\n" ";" LIB_OBJ_LIST "${LIB_OBJS}")
46+
STRING(REGEX REPLACE ";$" "" LIB_OBJ_LIST "${LIB_OBJ_LIST}")
47+
48+
LIST(LENGTH LIB_OBJ_LIST LENGTH_WITH_DUPS)
49+
SET(LIB_OBJ_LIST_NO_DUPS ${LIB_OBJ_LIST})
50+
IF (LENGTH_WITH_DUPS GREATER 0)
51+
LIST(REMOVE_DUPLICATES LIB_OBJ_LIST_NO_DUPS)
52+
ENDIF ()
53+
LIST(LENGTH LIB_OBJ_LIST_NO_DUPS LENGTH_WITHOUT_DUPS)
54+
55+
IF(LENGTH_WITH_DUPS EQUAL LENGTH_WITHOUT_DUPS)
56+
# Optimization for when lib doesn't actually have duplicate object
57+
# names, we can just extract everything.
58+
EXECUTE_PROCESS(
59+
COMMAND ${CMAKE_AR} -x ${LIB}
60+
WORKING_DIRECTORY ${TEMP_SUBDIR}
61+
)
62+
ELSE()
63+
LIST(SORT LIB_OBJ_LIST)
64+
SET(SAME_OBJ_COUNT 1)
65+
SET(LAST_OBJ_NAME)
66+
FOREACH(OBJ ${LIB_OBJ_LIST})
67+
IF(OBJ STREQUAL LAST_OBJ_NAME)
68+
GET_FILENAME_COMPONENT(OBJ_NO_EXT ${OBJ} NAME_WE)
69+
FILE(RENAME "${TEMP_SUBDIR}/${OBJ}" "${TEMP_SUBDIR}/${OBJ_NO_EXT}.${SAME_OBJ_COUNT}.o")
70+
MATH(EXPR SAME_OBJ_COUNT "${SAME_OBJ_COUNT}+1")
71+
ELSE()
72+
SET(SAME_OBJ_COUNT 1)
73+
ENDIF()
74+
SET(LAST_OBJ_NAME "${OBJ}")
75+
EXECUTE_PROCESS(
76+
COMMAND ${CMAKE_AR} -xN ${SAME_OBJ_COUNT} ${LIB} ${OBJ}
77+
WORKING_DIRECTORY ${TEMP_SUBDIR}
78+
)
79+
ENDFOREACH()
80+
ENDIF()
3881

39-
FILE(GLOB_RECURSE LIB_OBJECTS "${TEMP_SUBDIR}/*")
82+
FILE(GLOB_RECURSE LIB_OBJECTS "${TEMP_SUBDIR}/*.o")
4083
SET(OBJECTS ${OBJECTS} ${LIB_OBJECTS})
4184
ENDFOREACH()
4285

scripts/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,13 @@ MACRO(EXTRACT_LINK_LIBRARIES target var)
282282
LIST(REMOVE_ITEM ${target}_LIB_DEPENDS "")
283283
LIST(REMOVE_DUPLICATES ${target}_LIB_DEPENDS)
284284
FOREACH(lib ${${target}_LIB_DEPENDS})
285+
# TokuDB SE is built statically into AliSQL, and depends on stdc++ lib,
286+
# which will be used here. The '+' character has special meaning in
287+
# cmake regex, so "stdc++" need to be escaped before do matching.
288+
string(REPLACE "++" "\\+\\+" lib_escaped ${lib})
285289
# Filter out "general", it is not a library, just CMake hint
286290
# Also, remove duplicates
287-
IF(NOT lib STREQUAL "general" AND NOT ${var} MATCHES "-l${lib} ")
291+
IF(NOT lib STREQUAL "general" AND NOT ${var} MATCHES "-l${lib_escaped} ")
288292
IF (lib MATCHES "^\\-l")
289293
SET(${var} "${${var}} ${lib} ")
290294
ELSEIF(lib MATCHES "^/")

0 commit comments

Comments
 (0)