Skip to content

CMAKE_BUILD_TYPE shouldn't be required for finding Release packages #4606

@cramershoup

Description

@cramershoup

Description

./CMakeLists.txt

cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)

file(GLOB_RECURSE MAIN_SOURCE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h *.cpp)

add_executable(main ${MAIN_SOURCE})
target_include_directories(main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

find_package(CURL REQUIRED)
target_link_libraries(main PRIVATE ${CURL_LIBRARIES})
target_include_directories(main PRIVATE ${CURL_INCLUDE_DIRS})

find_package(ZLIB REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB)

find_library(CPR_LIBRARY cpr)
target_link_libraries(main PRIVATE ${CPR_LIBRARY})
target_include_directories(main PRIVATE ${CPR_INCLUDE_DIRS})

if(MSVC)
    target_link_libraries(main PRIVATE Ws2_32 Wldap32 Crypt32)
    target_compile_options(main PRIVATE "$<$<CONFIG:Debug>:/MTd>")
    target_compile_options(main PRIVATE "$<$<CONFIG:Release>:/MT>")
    target_compile_options(main PRIVATE "$<$<CONFIG:MinSizeRel>:/MT>")
    target_compile_options(main PRIVATE "$<$<CONFIG:RelWithDebInfo>:/MT>")
else()
    find_package(OpenSSL REQUIRED)
    target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
endif()

vcpkg/triplets/x64-windows-static.cmake

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(CURL_USE_WINSSL ON)

./build.bat

pushd build
vcpkg install --triplet x64-windows-static curl[ssl] cpr
cmake .. -G "Visual Studio 15 2017 Win64" -T "host=x64" -DVCPKG_TARGET_TRIPLET="x64-windows-static" -DCMAKE_TOOLCHAIN_FILE="vcpkg\scripts\buildsystems\vcpkg.cmake"
cmake --build . --config Release
popd

Error

Link:
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\projects
  \c\main\build\src\Release\main.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\projects\c\main\vendor\vcpkg\installed\x64
  -windows\lib" /LIBPATH:"C:\projects\c\main\vendor\vcpkg\installed\x64-windows\lib\manual-link" "..\..\..\vendor\vcpkg\installed\x64-windows-static\debug\lib\libcurl.lib" "..\..\..\vendor\vcpkg\install
  ed\x64-windows-static\lib\zlib.lib" "..\..\..\vendor\vcpkg\installed\x64-windows-static\debug\lib\cpr.lib" Ws2_32.lib Wldap32.lib Crypt32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.
  lib uuid.lib comdlg32.lib advapi32.lib "C:\projects\c\main\vendor\vcpkg\installed\x64-windows\lib\*.lib" /MANIFEST /MANIFESTUAC:"level='asInvok
  er' uiAccess='false'" /manifest:embed /PDB:"C:/projects/c/main/build/src/Release/main.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /D
  YNAMICBASE /NXCOMPAT /IMPLIB:"C:/projects/c/main/build/src/Release/main.lib" /MACHINE:X64  /machine:x64
cpr.lib(session.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in main.obj [C:\projects\c\main\build\src\main.vcxproj]
...

As we can see under Release configuration, the linker was trying to link curl and cpr at debug\lib\libcurl.lib and debug\lib\cpr.lib, which are both for Debug configuration that caused the errors. However zlib was resolved correctly to its Release version.

However if I try to compile the Debug configuration, zlib will be correctly resolved to debug\lib\zlibd.lib again, and other libraries unchanged, so everything compiles.

How to make it select the correct libcurl and cpr libraries for Release (this also happens for MinSizeRel and RelWithDebInfo) configurations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:vcpkg-bugThe issue is with the vcpkg system (including helper scripts in `scripts/cmake/`)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions