cmake builds/installs liblibipt on MSYS2
GitMensch opened this issue · 7 comments
I think that's an error:
cmake.exe -DBUILD_SHARED_LIBS=ON $(more_opts) ..
cmake.exe --build . --target test
cmake.exe --install .
generates libipt.dll and liblibipt.dll.a
seen in https://github.com/msys2/MINGW-packages/actions/runs/5196827879/jobs/9370933433?pr=17469
Is there a way to "fix" the cmake definition to generate libipt.dll.a instead of liblibipt.dll.a?
It shouldn't generate any archive with BUILD_SHARED_LIBS=ON. And it shouldn't generate any archive on Windows, at all. I'm using
set_target_properties(libipt PROPERTIES
PREFIX ""
PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/intel-pt.h
VERSION ${PT_VERSION}
SOVERSION ${PT_VERSION_MAJOR}
)
to remove the standard lib prefix and I call the library libipt
so it comes out the same way on Linux and Windows.
It works fine in my standard environment:
W:\ipt\bugs\issue-99>cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=install w:/ipt/git
-- The C compiler identification is MSVC 19.35.32215.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found UnixCommands: C:/Program Files/Git/usr/bin/bash.exe
-- Configuring done
-- Generating done
-- Build files have been written to: W:/ipt/bugs/issue-99
W:\ipt\bugs\issue-99>cmake --build .
[27/27] Linking C shared library bin\libipt.dll
W:\ipt\bugs\issue-99>cmake --install .
-- Install configuration: "Debug"
-- Installing: W:/ipt/bugs/issue-99/install/lib/libipt.lib
-- Installing: W:/ipt/bugs/issue-99/install/bin/libipt.dll
-- Installing: W:/ipt/bugs/issue-99/install/include/intel-pt.h
And with BUILD_SHARED_LIBS=OFF I get the expected Windows .lib
.
W:\ipt\bugs\issue-99>cmake -G Ninja -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=install w:/ipt/git
-- The C compiler identification is MSVC 19.35.32215.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found UnixCommands: C:/Program Files/Git/usr/bin/bash.exe
-- Configuring done
-- Generating done
-- Build files have been written to: W:/ipt/bugs/issue-99
W:\ipt\bugs\issue-99>cmake --build .
[27/27] Linking C static library lib\libipt.lib
W:\ipt\bugs\issue-99>cmake --install .
-- Install configuration: "Debug"
-- Installing: W:/ipt/bugs/issue-99/install/lib/libipt.lib
-- Installing: W:/ipt/bugs/issue-99/install/include/intel-pt.h
Something must confuse cmake in your environment. It uses .dll
and .lib
suffixes so it should know that it is building for Windows. But then, it tries to create an archive (or just uses the .a
suffix) and it ignores the PREFIX ""
target property. Since we end up with liblibipt.dll.a
it seems to mix Windows and Linux naming conventions.
It almost looks like the lib
and .a
were added later on to the name constructed by the libipt cmakefiles.
.dll.a is an import library and not an archive in case of non-msvc compilers.
Setting IMPORT_PREFIX ""
seems to work here for me. Removing PREFIX ""
and setting OUTPUT_NAME "ipt"
also works here.
I don't know how that later affects builds/naming with other compilers and other platforms though.
Removing PREFIX ""
and setting OUTPUT_NAME "ipt"
results in ipt.dll
when building with MSVC. Setting IMPORT_PREFIX ""
seems to work.
@GitMensch can you confirm that setting IMPORT_PREFIX ""
fixes the issue?
See https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-libipt/001-fix-import-lib-naming.patch (and yes, dropping the need for that patch would be very good).
Thanks, I'll update the MSYS2 build to the new release and drop the not needed patch there.
To be usable for my primary interest GDB will need adjustments, but at least people can use libipt on this environment now.