Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[qt5] Do not link all .lib files #1792

Merged
merged 2 commits into from
Sep 7, 2017

Conversation

ShinNoNoir
Copy link
Contributor

This PR addresses issue #1442

Currently, all .lib files produced in the compilation process are marked as an automatic dependency. This results in two conflicts:

  1. Qt5Bootstrap.lib is a file that should only be used and linked against in release builds. This file is not meant to be linked against in debug builds.
  2. qtmain.lib/qtmaind.lib cannot be linked against at the same time as Qt5AxServer.lib/Qt5AxServerd.lib. These two sets of lib files represent two different use cases (desktop applications vs. ActiveX servers).

The first conflict is resolved by moving Qt5Bootstrap.lib from debug\lib to a dummy subfolder. Note that simply deleting this file does not work at the moment since the warning generated by PostBuildLint's check_matching_debug_and_release_binaries(...) is actually considered to be an error.

The second conflict is resolved by moving the .lib files to a manual-link subfolder. This does mean, however, that users of the qt5 package now have to explicitly specify qtmain.lib/qtmaind.lib (or Qt5AxServer.lib/Qt5AxServerd.lib) as a lib dependency.

This commit moves a few .lib files to subfolders to prevent them from
automatically getting linked:

Qt5Bootstrap (dbg):
This lib is linked against a release version of the CRT and is only
meant for release builds. For debug builds, this lib should not be
linked at all.

qtmain (rel), qtmaind (dbg),
Qt5AxServer (rel), Qt5AxServerd (dbg):
These libs are mutually exclusive. The user either links against
qtmain(d) for desktop applications or against Qt5AxServer(d) for ActiveX
servers.

See microsoft#1442 for more information.
@msftclas
Copy link

msftclas commented Sep 6, 2017

@ShinNoNoir,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@ras0219-msft
Copy link
Collaborator

This is the right solution, thank you for making the PR.

Does this still work with CMake? Can find_package() still pick up everything?

@ras0219-msft ras0219-msft merged commit 3ac99b2 into microsoft:master Sep 7, 2017
@szechyjs
Copy link
Contributor

@ras0219-msft I don't think this is the correct change as it breaks existing CMake functionality.

For example with CMake > 2.8.11 simply adding WIN32 to add_executable will automatically include Qt5::WinMain in target_link_libraries. Qt5::WinMain expects qtmain.lib to be located in the lib directory. If this manual-link directory is going to continue to exist the cmake scripts need to be updated to utilize this. I'd rather not have to customize my CMakeLists.txt files for every project that uses vcpkg.

@ShinNoNoir
Copy link
Contributor Author

@szechyjs Do you have any suggestions how to fix it in a way such that things also still work in a plain vanilla Visual Studio project?

@ShinNoNoir
Copy link
Contributor Author

Hmm, I notice that vcpkg/packages/qt5_${TRIPLET}/share/cmake/Qt5Core/Qt5CoreConfigExtras.cmake contains the following lines:

set(imported_location "${_qt5Core_install_prefix}/lib/qtmain.lib")
set(imported_location_debug "${_qt5Core_install_prefix}/debug/lib/qtmaind.lib")

If these would be patched to reflect the manual-link subdirectory, would this solve the issue? Or should this be patched elsewhere? (Not entirely sure how Qt5CoreConfigExtras.cmake is created.)

Also, something similar would need to be done for Qt5AxServer.lib.

@ShinNoNoir
Copy link
Contributor Author

I also see that fixcmake.py is called in portfile.cmake to fix any CMake files, so patching would have to be done there.

@szechyjs
Copy link
Contributor

I guess ultimately I don't understand the all .lib files are automatic dependencies. In the years that I've been using Qt, the qtmain.lib file is always in the lib directory, when manually compiling Qt and when downloading the official binaries. From my experience the default Qt install structure has always worked just fine with VS and CMake.

@szechyjs
Copy link
Contributor

I think I've found what you mean by all libs are automatic dependencies, from vcpkg.targets:

    <Link>
      <AdditionalDependencies Condition="$(VcpkgConfiguration.StartsWith('Debug')) and '$(VcpkgAutoLink)' != 'false'">%(AdditionalDependencies);$(VcpkgRoot)debug\lib\*.lib</AdditionalDependencies>
      <AdditionalDependencies Condition="$(VcpkgConfiguration.StartsWith('Release')) and '$(VcpkgAutoLink)' != 'false'">%(AdditionalDependencies);$(VcpkgRoot)lib\*.lib</AdditionalDependencies>
      <AdditionalLibraryDirectories Condition="$(VcpkgConfiguration.StartsWith('Release'))">%(AdditionalLibraryDirectories);$(VcpkgRoot)lib;$(VcpkgRoot)lib\manual-link</AdditionalLibraryDirectories>
      <AdditionalLibraryDirectories Condition="$(VcpkgConfiguration.StartsWith('Debug'))">%(AdditionalLibraryDirectories);$(VcpkgRoot)debug\lib;$(VcpkgRoot)debug\lib\manual-link</AdditionalLibraryDirectories>
    </Link>

In my opinion that is very bad form to automatically link every lib file found. However, I can understand why it was done, I'd just rather see an explicit list of libraries to link against in each project and have vcpkg.targets only setup the library directories.

Regardless of how vcpkg.targets is handled going forward, the CMake files need to be updated/patched to reflect this custom directory structure as it's currently broken.

@ras0219-msft
Copy link
Collaborator

@szechyjs We definitely understand the desire to have a more "total" accounting for all your dependencies, which can be easily done by setting VcpkgAutoLink to false in the Globals PropertyGroup for your project.

I'll look into the imported_location patch.

@ShinNoNoir
Copy link
Contributor Author

ShinNoNoir commented Sep 19, 2017

I might have a possible fix which I'll soon commit and push to a test branch.

Edit: PR is up. See #1847.

@ShinNoNoir ShinNoNoir deleted the qt5-removedefaultdeps branch June 28, 2018 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants