How to add vcpkg variable in visual studio with cmake?

learner~.~ 41 Reputation points
2023-10-11T02:52:34.78+00:00

What I need:

I want to use cmake tool to add x86-windows-static in Triplet option and Debug in Vcpkg Configuration.

Look the screenshots below,

vs screenshot 1

vs screenshot 2

What I have tried:

I read some docs to changed these vars, but failed.

My part code in CMakeLists,


...

if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Windows")

set(CMAKE_GENERATOR_PLATFORM Win32)

set(CMAKE_GENERATOR_TOOLSET "host=x86" CACHE STRING "Platform Toolset" FORCE)

#set vcpkg

set(VCPKG_ROOT_DIR "C:/Users/xxx/vcpkg" CACHE PATH "set vcpkg path")

set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT_DIR}/scripts/buildsystems/vcpkg.cmake")

message(VCPKG_ROOT = "${CMAKE_TOOLCHAIN_FILE}")

set(VCPKG_TARGET_ARCHITECTURE x86)

set(VCPKG_CRT_LINKAGE static)

set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME Empty)

set(VCPKG_TARGET_TRIPLET "x86-windows-static")

endif()

project(my_project)

...

Output:


$ cmake -B build

VCPKG_ROOT=C:/Users/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.

-- Configuring done

-- Generating done

-- Build files have been written to: D:/my_project/build

Reopen .sln project, no happended in the Triplet option and Vcpkg Configuration,they are still empty.

BTW, I can use VS_GLOBAL_VcpkgEnabled to change Use Vcpkg

`set_target_properties(my_project PROPERTIES VS_GLOBAL_VcpkgEnabled true)

`

vs screenshot 3

But I cannot change the other vcpkg options.

My question:

Can I modify the relevant variable values in CMakeLists to change the vcpkg options in VS project?

If not, is there any other way?

Thanks in advance!

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,888 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anna Xiu-MSFT 27,891 Reputation points Microsoft Vendor
    2023-10-12T09:09:56.6333333+00:00

    Hi @learner~.~, 

    Welcome to Microsoft Q&A! 

    Your issue is more related to vcpkg, please report it in dedicated vcpkg forum. 

    Thanks for your understanding! 

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

     

    0 comments No comments