How to fix 'Vcpkg/CMake Is Unable to determine target architecture' (Windows10,vcpkg,clion,cmake)
Asked Answered
C

1

7

I want to use this library see: https://github.com/jtv/libpqxx

I decided to install this library manager vcpkg see: https://github.com/microsoft/vcpkg

I set the CMake Option to "CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake"

This is the Error:

"C:\Program Files\JetBrains\CLion 2019.1.4\bin\cmake\win\bin\cmake.exe"     -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/vcpkg/scripts   /buildsystems/vcpkg.cmake -G "CodeBlocks - MinGW Makefiles" C:\Users  \Vaio\CLionProjects\untitled
CMake Warning at C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake:68   (message):
Unable to determine target architecture, continuing without vcpkg.
Call Stack (most recent call first):
cmake-build-debug-mingw/CMakeFiles/3.14.3/CMakeSystem.cmake:6 (include)
CMakeLists.txt:2 (project)

The corresponding CMake Code is this:

if(VCPKG_TARGET_TRIPLET)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$")
    set(_VCPKG_TARGET_TRIPLET_ARCH x86)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Xx]64$")
    set(_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]$")
    set(_VCPKG_TARGET_TRIPLET_ARCH arm)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]64$")
    set(_VCPKG_TARGET_TRIPLET_ARCH arm64)
else()
    if(CMAKE_GENERATOR MATCHES "^Visual Studio 14 2015 Win64$")
        set(_VCPKG_TARGET_TRIPLET_ARCH x64)
    elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 14 2015 ARM$")
        set(_VCPKG_TARGET_TRIPLET_ARCH arm)
    elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 14 2015$")
        set(_VCPKG_TARGET_TRIPLET_ARCH x86)
    elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 15 2017 Win64$")
        set(_VCPKG_TARGET_TRIPLET_ARCH x64)
    elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 15 2017 ARM$")
        set(_VCPKG_TARGET_TRIPLET_ARCH arm)
    elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 15 2017$")
        set(_VCPKG_TARGET_TRIPLET_ARCH x86)
    elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 16 2019$")
        if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^[Xx]86$")
            set(_VCPKG_TARGET_TRIPLET_ARCH x86)
        elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^[Aa][Mm][Dd]64$")
            set(_VCPKG_TARGET_TRIPLET_ARCH x64)
        elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^[Aa][Rr][Mm]$")
            set(_VCPKG_TARGET_TRIPLET_ARCH arm)
        elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^[Aa][Rr][Mm]64$")
            set(_VCPKG_TARGET_TRIPLET_ARCH arm64)
        else()

        endif()
    else()
        find_program(_VCPKG_CL cl)
        if(_VCPKG_CL MATCHES "amd64/cl.exe$" OR _VCPKG_CL MATCHES "x64/cl.exe$")
            set(_VCPKG_TARGET_TRIPLET_ARCH x64)
        elseif(_VCPKG_CL MATCHES "arm/cl.exe$")
            set(_VCPKG_TARGET_TRIPLET_ARCH arm)
        elseif(_VCPKG_CL MATCHES "arm64/cl.exe$")
            set(_VCPKG_TARGET_TRIPLET_ARCH arm64)
        elseif(_VCPKG_CL MATCHES "bin/cl.exe$" OR _VCPKG_CL MATCHES "x86/cl.exe$")
            set(_VCPKG_TARGET_TRIPLET_ARCH x86)
        elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
            set(_VCPKG_TARGET_TRIPLET_ARCH x64)
        else()
            if( _CMAKE_IN_TRY_COMPILE )
                message(STATUS "Unable to determine target architecture, continuing without vcpkg.")
            else()
                message(WARNING "Unable to determine target architecture, continuing without vcpkg.")
            endif()
            set(VCPKG_TOOLCHAIN ON)
            return()
        endif()
    endif()
endif()

Here is a step by step on what I did.

  1. Installed Visual Studio 2019
  2. Installed GIT
  3. Installed CMake
  4. Installed vcpkg see: https://github.com/microsoft/vcpkg install command: .\bootstrap-vcpkg.bat 5 run : vcpkg install libpqxx --triplet x64-windows
  5. run : vcpkg list // to see that it is installed
  6. run : vcpkg integrate install
  7. specified -DCMAKE-TOOLCHAIN-FILE inside of CLion/CMake

Im using MinGW/GNU as a Compiler

Is there something I missed? Or why can't it find my target architecture? This are my environment variables.

Note: Everything works inside of Visual Studio 2019

enter image description here

Chong answered 18/7, 2019 at 10:43 Comment(1)
It seems MinGW+vcpkg is not officialy supported, see github.com/Microsoft/vcpkg/issues/3752 for description, github.com/microsoft/vcpkg/issues/4418#issuecomment-428168157 for explanation (you need to create mingw toolchain file)Squashy
C
12

I Added -DVCPKG_TARGET_TRIPLET=x64-windows before -DCMAKE_TOOLCHAIN_FILE and it worked.

link for solution: https://vcpkg.readthedocs.io/en/latest/users/integration/

With CMake you can set VCPKG_TARGET_TRIPLET on the configure line:

cmake ../my/project -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=...

If you use VCPKG_DEFAULT_TRIPLET environment variable to control the unqualified triplet in vcpkg command lines you can default VCPKG_TARGET_TRIPLET in CMake like

Using an environment variable instead of a command line option:

if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
  set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
endif()
Chong answered 18/7, 2019 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.