Skip to content

Commit 803bb5c

Browse files
committed
Windows, cmake : Fix occasional link error when switching between debug to optimized compilation
For Visual Studio generator, use a per-config .def/.lib files with symbols exported from mysqld.exe Functions exported from mysqld.exe may differ between debug/optimized compilation, e.g dbug functions are missing in release config.
1 parent 0fd5b11 commit 803bb5c

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

sql/CMakeLists.txt

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS)
197197
# without necessity.E.g source modifications, that do not
198198
# change list of exported symbols, will not result in a relink for plugins.
199199

200-
SET(MYSQLD_DEF ${CMAKE_CURRENT_BINARY_DIR}/mysqld_lib.def)
201-
SET(MYSQLD_EXP ${CMAKE_CURRENT_BINARY_DIR}/mysqld_lib.exp)
202-
SET(MYSQLD_LIB ${CMAKE_CURRENT_BINARY_DIR}/mysqld_lib.lib)
200+
SET(MYSQLD_DEF ${CMAKE_CURRENT_BINARY_DIR}/mysqld_lib${CMAKE_CFG_INTDIR}.def)
201+
SET(MYSQLD_EXP ${CMAKE_CURRENT_BINARY_DIR}/mysqld_lib${CMAKE_CFG_INTDIR}.exp)
202+
SET(MYSQLD_LIB ${CMAKE_CURRENT_BINARY_DIR}/mysqld_lib${CMAKE_CFG_INTDIR}.lib)
203203
SET(MYSQLD_CORELIBS sql mysys dbug strings)
204204
FOREACH (CORELIB ${MYSQLD_CORELIBS})
205205
GET_TARGET_PROPERTY(LOC ${CORELIB} LOCATION)
@@ -214,12 +214,12 @@ IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS)
214214
# Create a cmake script to generate import and export libs
215215
# from a .def file
216216
SET(CMAKE_CONFIGURABLE_FILE_CONTENT "
217-
IF ((mysqld_lib.def IS_NEWER_THAN mysqld_lib.lib) OR
218-
(mysqld_lib.def IS_NEWER_THAN mysqld_lib.exp))
219-
FILE(REMOVE mysqld_lib.lib mysqld_lib.exp)
217+
IF ((mysqld_lib\${CFG}.def IS_NEWER_THAN mysqld_lib\${CFG}.lib) OR
218+
(mysqld_lib\${CFG}.def IS_NEWER_THAN mysqld_lib\${CFG}.exp))
219+
FILE(REMOVE mysqld_lib\${CFG}.lib mysqld_lib\${CFG}.exp)
220220
SET(ENV{VS_UNICODE_OUTPUT})
221221
EXECUTE_PROCESS (
222-
COMMAND \"${CMAKE_LINKER}\" /lib /NAME:mysqld.exe \"/DEF:${MYSQLD_DEF}\" /MACHINE:${_PLATFORM}
222+
COMMAND \"${CMAKE_LINKER}\" /lib /NAME:mysqld.exe \"/DEF:${CMAKE_CURRENT_BINARY_DIR}/mysqld_lib\${CFG}.def\" /MACHINE:${_PLATFORM}
223223
RESULT_VARIABLE ret)
224224
IF(NOT ret EQUAL 0)
225225
MESSAGE(FATAL_ERROR \"process failed ret=\${ret}\")
@@ -229,41 +229,22 @@ IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS)
229229

230230
CONFIGURE_FILE(
231231
${PROJECT_SOURCE_DIR}/cmake/configurable_file_content.in
232-
make_mysqld_lib.cmake)
232+
make_mysqld_lib.cmake
233+
@ONLY)
233234

234235
IF(CMAKE_VERSION VERSION_GREATER "3.2.0")
235236
SET(MYSQLD_LIB_BYPRODUCTS BYPRODUCTS ${MYSQLD_DEF} ${MYSQLD_LIB} ${MYSQLD_EXP})
236237
ENDIF()
237238

238-
# Create a cmake script to generate import and export libs
239-
# from a .def file
240-
SET(CMAKE_CONFIGURABLE_FILE_CONTENT "
241-
IF ((mysqld_lib.def IS_NEWER_THAN mysqld_lib.lib) OR
242-
(mysqld_lib.def IS_NEWER_THAN mysqld_lib.exp))
243-
FILE(REMOVE mysqld_lib.lib mysqld_lib.exp)
244-
SET(ENV{VS_UNICODE_OUTPUT})
245-
EXECUTE_PROCESS (
246-
COMMAND \"${CMAKE_LINKER}\" /lib /NAME:mysqld.exe \"/DEF:${MYSQLD_DEF}\" /MACHINE:${_PLATFORM}
247-
RESULT_VARIABLE ret)
248-
IF(NOT ret EQUAL 0)
249-
MESSAGE(FATAL_ERROR \"process failed ret=\${ret}\")
250-
ENDIF()
251-
ENDIF()
252-
")
253-
254-
CONFIGURE_FILE(
255-
${PROJECT_SOURCE_DIR}/cmake/configurable_file_content.in
256-
make_mysqld_lib.cmake)
257-
258239
ADD_CUSTOM_COMMAND(
259240
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mysqld_lib.stamp
260241
${MYSQLD_LIB_BYPRODUCTS}
261-
COMMENT "Generating mysqld_lib.def, mysqld_lib.lib, mysqld_lib.exp"
242+
COMMENT "Generating ${MYSQLD_DEF}, ${MYSQLD_LIB}, ${MYSQLD_EXP}"
262243
COMMAND cscript //nologo ${PROJECT_SOURCE_DIR}/win/create_def_file.js
263-
${_PLATFORM} /forLib ${LIB_LOCATIONS} > mysqld_lib.def.tmp
264-
COMMAND ${CMAKE_COMMAND} -E copy_if_different mysqld_lib.def.tmp mysqld_lib.def
265-
COMMAND ${CMAKE_COMMAND} -E remove mysqld_lib.def.tmp
266-
COMMAND ${CMAKE_COMMAND} -P make_mysqld_lib.cmake
244+
${_PLATFORM} /forLib ${LIB_LOCATIONS} > ${MYSQLD_DEF}.tmp
245+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MYSQLD_DEF}.tmp ${MYSQLD_DEF}
246+
COMMAND ${CMAKE_COMMAND} -E remove ${MYSQLD_DEF}.tmp
247+
COMMAND ${CMAKE_COMMAND} "-DCFG=${CMAKE_CFG_INTDIR}" -P make_mysqld_lib.cmake
267248
COMMAND ${CMAKE_COMMAND} -E touch mysqld_lib.stamp
268249
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
269250
DEPENDS ${MYSQLD_CORELIBS}

0 commit comments

Comments
 (0)