aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2023-09-27 22:46:20 +0300
committerJia Tan <jiat0218@gmail.com>2023-10-31 18:44:59 +0800
commit661549ecb7a9b136d72a01c137d9776c75d52d51 (patch)
treebedf6138347e66d510a91638dc2454a29ca67a42 /CMakeLists.txt
parentCMake: Change one CMAKE_CURRENT_SOURCE_DIR to CMAKE_CURRENT_LIST_DIR. (diff)
downloadxz-661549ecb7a9b136d72a01c137d9776c75d52d51.tar.xz
CMake: Create liblzma.def when building liblzma.dll with MinGW-w64.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt20
1 files changed, 20 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 117f2c66..61103c7e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -853,6 +853,26 @@ if(WIN32)
# Export the public API symbols with __declspec(dllexport).
target_compile_definitions(liblzma PRIVATE DLL_EXPORT)
+
+ if(NOT MSVC)
+ # Create a DEF file. The linker puts the ordinal numbers there
+ # too so the output from the linker isn't our final file.
+ target_link_options(liblzma PRIVATE
+ "-Wl,--output-def,liblzma.def.in")
+
+ # Remove the ordinal numbers from the DEF file so that
+ # no one will create an import library that links by ordinal
+ # instead of by name. We don't maintain a DEF file so the
+ # ordinal numbers aren't stable.
+ add_custom_command(TARGET liblzma POST_BUILD
+ COMMAND "${CMAKE_COMMAND}"
+ -DINPUT_FILE=liblzma.def.in
+ -DOUTPUT_FILE=liblzma.def
+ -P
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/remove-ordinals.cmake"
+ BYPRODUCTS "liblzma.def"
+ VERBATIM)
+ endif()
else()
# Disable __declspec(dllimport) when linking against static liblzma.
target_compile_definitions(liblzma INTERFACE LZMA_API_STATIC)