Fix LTO (aka interprocedural optimization) build with MSVC

Also, disable MSVC LTO for static client libraries - they won't be usable
for end-users.
This commit is contained in:
Vladislav Vaintroub 2024-04-10 12:37:06 +02:00
parent 040069f4ba
commit e87a175b3a
2 changed files with 13 additions and 0 deletions

View file

@ -370,5 +370,11 @@ ENDFUNCTION()
FUNCTION (MAYBE_DISABLE_IPO target)
IF(MSVC AND NOT CLANG_CL)
SET_TARGET_PROPERTIES(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
IF(CMAKE_CONFIGURATION_TYPES)
FOREACH(cfg ${CMAKE_CONFIGURATION_TYPES})
STRING(TOUPPER "${cfg}" cfg_upper)
SET_TARGET_PROPERTIES(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_${cfg_upper} OFF)
ENDFOREACH()
ENDIF()
ENDIF()
ENDFUNCTION()

View file

@ -40,6 +40,13 @@ SET(CLIENT_PLUGIN_PVIO_SOCKET STATIC)
MESSAGE("== Configuring MariaDB Connector/C")
ADD_SUBDIRECTORY(libmariadb)
IF(MSVC AND TARGET mariadb_obj AND TARGET mariadbclient)
# With MSVC, do not produce LTCG-compiled static client libraries.
# They are not usable by end-users, being tied to exact compiler version
MAYBE_DISABLE_IPO(mariadb_obj)
MAYBE_DISABLE_IPO(mariadbclient)
ENDIF()
IF(UNIX)
INSTALL(CODE "EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E make_directory \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${INSTALL_BINDIR})