vcpkg doesn't install CMake targets for RelWithDebInfo and MinSizeRel

Created on 10 Mar 2019  路  4Comments  路  Source: microsoft/vcpkg

For libraries that provide CMake targets when installed (eg. SDL2), vcpkg will only generate import files for Debug and Release (eg. SDL2Targets-debug.cmake and SDL2Targets-release.cmake). This leaves vcpkg/CMake to incorrectly default to Debug when using RelWithDebInfo and MinSizeRel, causing bugs like linking the wrong version or not copying the DLL (#2559 #3463).

One can workaround this at the project level, but this shouldn't be required:

set_target_properties(SDL2::SDL2 SDL2::SDL2main PROPERTIES
    MAP_IMPORTED_CONFIG_MINSIZEREL Release
    MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
)

vcpkg should automatically support the RelWithDebInfo and MinSizeRel targets as Release, either by generating import files for all 3 or redirecting them like in the workaround above.

discussion

Most helpful comment

I also looked into this and removed the mapping in my PRs for fftw and hdf5.

Reasoning:
a) This seems to be a CMake issue and only applys for multi configuration generators
b) If you need the mapping behavior you probably want to set it globally yourself with:

set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL Release)
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release) 

within your project.
c) patching all target files generated by packages within vcpkg seems unreasonable

Knowing the cmake behavior the vcpkg cmake toolchain file could probably set those values for us if they are not set.

All 4 comments

I also looked into this and removed the mapping in my PRs for fftw and hdf5.

Reasoning:
a) This seems to be a CMake issue and only applys for multi configuration generators
b) If you need the mapping behavior you probably want to set it globally yourself with:

set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL Release)
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release) 

within your project.
c) patching all target files generated by packages within vcpkg seems unreasonable

Knowing the cmake behavior the vcpkg cmake toolchain file could probably set those values for us if they are not set.

@Neumann-A I dug around but apparently CMake says this is by design: https://gitlab.kitware.com/cmake/cmake/issues/16091

When multiple matching configurations are imported, CMake uses the first one. Since most libraries only export a single universal configuration and it's vcpkg splitting them into Debug/Release versions, I assume the issue is somewhere on vcpkg's end.

Maybe vcpkg can always just import Release first and then Debug, so it always falls back to "Release", like they did for FindBoost?

Nope, I would say it is a CMake issue:

  // If we have not yet found it then the project is willing to try
  // any available configuration.
  if (!*loc && !*imp) {
    std::vector<std::string> availableConfigs;
    if (const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
      cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
    }
    for (std::vector<std::string>::const_iterator aci =
           availableConfigs.begin();
         !*loc && !*imp && aci != availableConfigs.end(); ++aci) {
      suffix = "_";
      suffix += cmSystemTools::UpperCase(*aci);
      std::string locProp = locPropBase;
      locProp += suffix;
      *loc = this->GetProperty(locProp);
      if (allowImp) {
        std::string impProp = "IMPORTED_IMPLIB";
        impProp += suffix;
        *imp = this->GetProperty(impProp);
      }

This should fallback to Release for MinSizeRel and RelWithDebInfo because these configurations are defined by CMake. Due to the code above it will always consider Debug before Release because the list is probably alphabetically ordered. But in the meantime we could just overwrite global mappings if those are not set in the toolchain file.

This issue hasn鈥檛 been updated in a year, if it is still an issue, please reopen.

Was this page helpful?
0 / 5 - 0 ratings