Commit dc068734 authored by Daniel Black's avatar Daniel Black Committed by Vladislav Vaintroub

cmake: merge_static_libs - correct duplicate assumptions (#1583)

This corrects build failures on ppc64{,le} with the
WITH_EMBEDDED_SERVER option enabled.

MDEV-22641 added an unusual case in which the same object
file in was included twice with a different function
defination. The original cmake/merge_archives_unix.cmake
did not tolerate such eventualities.

So we move to the highest voted answer on Stack Overflow
for the merging of static libraries.
https://stackoverflow.com/questions/3821916/how-to-merge-two-ar-static-libraries-into-one

Thin archives generated compile failures and the libtool
mechanism would of been another dependency and using .la
files that isn't part of a normal cmake output. The straight
Apple mechanism of libtool with static archives also failed
on Linux.

This leaves the MRI script mechansim which was implemented
in this change.
parent dd77f072
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
.*.swp .*.swp
*.ninja *.ninja
.ninja_* .ninja_*
*.mri
*.mri.tpl
.gdb_history .gdb_history
.vs/ .vs/
errmsg.sys errmsg.sys
......
...@@ -127,7 +127,8 @@ ENDMACRO() ...@@ -127,7 +127,8 @@ ENDMACRO()
# Merge static libraries into a big static lib. The resulting library # Merge static libraries into a big static lib. The resulting library
# should not not have dependencies on other static libraries. # should not not have dependencies on other static libraries.
# We use it in MySQL to merge mysys,dbug,vio etc into mysqlclient # We use it in MariaDB to merge mysys,dbug,vio etc into the embedded server
# mariadbd.
MACRO(MERGE_STATIC_LIBS TARGET OUTPUT_NAME LIBS_TO_MERGE) MACRO(MERGE_STATIC_LIBS TARGET OUTPUT_NAME LIBS_TO_MERGE)
# To produce a library we need at least one source file. # To produce a library we need at least one source file.
...@@ -196,18 +197,33 @@ MACRO(MERGE_STATIC_LIBS TARGET OUTPUT_NAME LIBS_TO_MERGE) ...@@ -196,18 +197,33 @@ MACRO(MERGE_STATIC_LIBS TARGET OUTPUT_NAME LIBS_TO_MERGE)
) )
ELSE() ELSE()
# Generic Unix, Cygwin or MinGW. In post-build step, call # Generic Unix, Cygwin or MinGW. In post-build step, call
# script, that extracts objects from archives with "ar x" # script, that uses a MRI script to append static archives.
# and repacks them with "ar r" IF(CMAKE_VERSION VERSION_LESS "3.0")
SET(MRI_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.mri")
ELSE()
SET(MRI_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}-$<CONFIG>.mri")
ENDIF()
SET(MRI_SCRIPT_TPL "${MRI_SCRIPT}.tpl")
SET(SCRIPT_CONTENTS "CREATE $<TARGET_FILE:${TARGET}>\n")
FOREACH(LIB ${STATIC_LIBS})
STRING(APPEND SCRIPT_CONTENTS "ADDLIB ${LIB}\n")
ENDFOREACH()
STRING(APPEND SCRIPT_CONTENTS "SAVE\nEND\n")
FILE(WRITE ${MRI_SCRIPT_TPL} "${SCRIPT_CONTENTS}")
FILE(GENERATE OUTPUT ${MRI_SCRIPT} INPUT ${MRI_SCRIPT_TPL})
ADD_CUSTOM_COMMAND(TARGET ${TARGET} POST_BUILD ADD_CUSTOM_COMMAND(TARGET ${TARGET} POST_BUILD
DEPENDS ${MRI_SCRIPT}
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-DTARGET_LOCATION="$<TARGET_FILE:${TARGET}>" ARGS
-DTARGET="${TARGET}" -DTARGET_SCRIPT="${MRI_SCRIPT}"
-DSTATIC_LIBS="${STATIC_LIBS}"
-DCMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}"
-DCMAKE_AR="${CMAKE_AR}" -DCMAKE_AR="${CMAKE_AR}"
-DCMAKE_RANLIB="${CMAKE_RANLIB}"
-P "${MYSQL_CMAKE_SCRIPT_DIR}/merge_archives_unix.cmake" -P "${MYSQL_CMAKE_SCRIPT_DIR}/merge_archives_unix.cmake"
COMMAND ${CMAKE_RANLIB}
ARGS $<TARGET_FILE:${TARGET}>
) )
SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${MRI_SCRIPT_TPL})
ENDIF() ENDIF()
ENDIF() ENDIF()
ENDMACRO() ENDMACRO()
......
# Copyright (c) 2009 Sun Microsystems, Inc. # Copyright (c) 2020 IBM
# Use is subject to license terms. # Use is subject to license terms.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
...@@ -14,43 +14,7 @@ ...@@ -14,43 +14,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
FILE(REMOVE "${TARGET_LOCATION}")
SET(TEMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/merge_archives_${TARGET})
MAKE_DIRECTORY(${TEMP_DIR})
# Extract each archive to its own subdirectory(avoid object filename clashes)
SEPARATE_ARGUMENTS(STATIC_LIBS UNIX_COMMAND "${STATIC_LIBS}")
FOREACH(LIB ${STATIC_LIBS})
GET_FILENAME_COMPONENT(NAME_NO_EXT ${LIB} NAME_WE)
SET(TEMP_SUBDIR ${TEMP_DIR}/${NAME_NO_EXT})
MAKE_DIRECTORY(${TEMP_SUBDIR})
EXECUTE_PROCESS(
COMMAND ${CMAKE_AR} -x ${LIB}
WORKING_DIRECTORY ${TEMP_SUBDIR}
)
FILE(GLOB_RECURSE LIB_OBJECTS "${TEMP_SUBDIR}/*")
SET(OBJECTS ${OBJECTS} ${LIB_OBJECTS})
ENDFOREACH()
# Use relative paths, makes command line shorter.
GET_FILENAME_COMPONENT(ABS_TEMP_DIR ${TEMP_DIR} ABSOLUTE)
FOREACH(OBJ ${OBJECTS})
FILE(RELATIVE_PATH OBJ ${ABS_TEMP_DIR} ${OBJ})
FILE(TO_NATIVE_PATH ${OBJ} OBJ)
SET(ALL_OBJECTS ${ALL_OBJECTS} ${OBJ})
ENDFOREACH()
FILE(TO_NATIVE_PATH ${TARGET_LOCATION} ${TARGET_LOCATION})
# Now pack the objects into library with ar.
EXECUTE_PROCESS( EXECUTE_PROCESS(
COMMAND ${CMAKE_AR} -r ${TARGET_LOCATION} ${ALL_OBJECTS} COMMAND ${CMAKE_AR} -M
WORKING_DIRECTORY ${TEMP_DIR} INPUT_FILE ${TARGET_SCRIPT}
) )
EXECUTE_PROCESS(
COMMAND ${CMAKE_RANLIB} ${TARGET_LOCATION}
WORKING_DIRECTORY ${TEMP_DIR}
)
# Cleanup
FILE(REMOVE_RECURSE ${TEMP_DIR})
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment