Skip to content

Commit d50f776

Browse files
committed
MDEV-22454 Allow -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
Disable IPO (interprocedural optimization, aka /GL) on Windows on libraries, from which server.dll exports symbols - exporting symbols does not work for objects compiled with /GL.
1 parent f544a71 commit d50f776

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ ENDIF()
3030
IF(POLICY CMP0075)
3131
CMAKE_POLICY(SET CMP0075 NEW)
3232
ENDIF()
33+
IF(POLICY CMP0069)
34+
CMAKE_POLICY(SET CMP0069 NEW)
35+
ENDIF()
3336

3437
MESSAGE(STATUS "Running cmake version ${CMAKE_VERSION}")
3538

cmake/libutils.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,15 @@ FUNCTION(RESTRICT_SYMBOL_EXPORTS target)
330330
COMPILE_FLAGS "${COMPILE_FLAGS} ${VISIBILITY_HIDDEN_FLAG}")
331331
ENDIF()
332332
ENDFUNCTION()
333+
334+
# The MSVC /GL flag, used for link-time code generation
335+
# creates objects files with a format not readable by tools
336+
# i.e exporting all symbols is not possible with IPO
337+
# To workaround this, we disable INTERPROCEDURAL_OPTIMIZATION
338+
# for some static libraries.
339+
340+
FUNCTION (MAYBE_DISABLE_IPO target)
341+
IF(MSVC AND NOT CLANG_CL)
342+
SET_TARGET_PROPERTIES(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
343+
ENDIF()
344+
ENDFUNCTION()

dbug/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ INCLUDE_DIRECTORIES(
2020
SET(DBUG_SOURCES dbug.c)
2121
ADD_CONVENIENCE_LIBRARY(dbug ${DBUG_SOURCES})
2222
TARGET_LINK_LIBRARIES(dbug mysys)
23+
MAYBE_DISABLE_IPO(dbug)
2324

2425
ADD_EXECUTABLE(tests tests.c)
2526
TARGET_LINK_LIBRARIES(tests dbug)

mysys/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ IF(HAVE_MLOCK)
7171
ENDIF()
7272

7373
ADD_CONVENIENCE_LIBRARY(mysys ${MYSYS_SOURCES})
74+
MAYBE_DISABLE_IPO(mysys)
7475
TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY}
7576
${LIBNSL} ${LIBM} ${LIBRT} ${LIBDL} ${LIBSOCKET} ${LIBEXECINFO} ${CRC32_LIBRARY})
7677
DTRACE_INSTRUMENT(mysys)

sql/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ MYSQL_ADD_PLUGIN(sql_sequence ha_sequence.cc STORAGE_ENGINE MANDATORY STATIC_ONL
188188
RECOMPILE_FOR_EMBEDDED)
189189

190190
ADD_LIBRARY(sql STATIC ${SQL_SOURCE})
191+
MAYBE_DISABLE_IPO(sql)
191192
DTRACE_INSTRUMENT(sql)
192193
TARGET_LINK_LIBRARIES(sql
193194
mysys mysys_ssl dbug strings vio pcre2-8
@@ -234,13 +235,13 @@ IF(MSVC)
234235
IF(deps)
235236
LIST(APPEND all_deps ${deps})
236237
ENDIF()
237-
ENDFOREACH()
238+
ENDFOREACH()
238239
LIST(REMOVE_DUPLICATES all_deps)
239240
FOREACH(lib ${libs_to_export_symbols})
240241
LIST(REMOVE_ITEM all_deps ${lib})
241242
ENDFOREACH()
242243

243-
TARGET_LINK_LIBRARIES(server
244+
TARGET_LINK_LIBRARIES(server PRIVATE
244245
${all_deps}
245246
sql_builtins
246247
)

strings/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ ENDIF()
3232
# Avoid dependencies on perschema data defined in mysys
3333
ADD_DEFINITIONS(-DDISABLE_MYSQL_THREAD_H)
3434
ADD_CONVENIENCE_LIBRARY(strings ${STRINGS_SOURCES})
35-
35+
TARGET_LINK_LIBRARIES(strings dbug mysys)
36+
MAYBE_DISABLE_IPO(strings)
3637
ADD_EXECUTABLE(conf_to_src EXCLUDE_FROM_ALL conf_to_src.c)
3738
SET_TARGET_PROPERTIES(conf_to_src PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
3839
TARGET_LINK_LIBRARIES(conf_to_src mysys strings)

0 commit comments

Comments
 (0)