获取VCPKG在构建端口时将VCPKG Include目录包含在include路径中

Get VCPKG to include the VCPKG Include directory in the include path when building a port

我正在尝试为 Arabica project 创建 VCPKG 的新端口。 vcpkg 安装命令失败。第一个错误如下

...\include\XPath/impl/xpath_namespace_context.hpp(7,10):
fatal error C1083: Cannot open include file: 'boost/shared_ptr.hpp':
No such file or directory [D:\vcpkg\buildtrees\arabica\x64-windows-dbg\mangle.vcxproj]

问题是这个文件安装在 VCPKG 包含目录中。准确的说是安装在D:\vcpkg\installed\x64-windows\include\boost\shared_ptr.hpp.

编译文件的命令如下

...\CL.exe /c /I"D:\vcpkg\buildtrees\arabica\x64-windows-dbg\include" /I"D:\vcpkg\buildtrees\arabica\src[=11=]-February-67b234ed05\include" /Z7 /W3 /WX- /diagnostics:column /MP /Od /Ob0 /D WIN32 /D _WINDOWS /D _DEBUG /D ARABICA_DEBUG /D ARABICA_NOT_USE_PRAGMA_LINKER_OPTIONS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"xgrep.dir\Debug\" /Fd"xgrep.dir\Debug\vc142.pdb" /Gd /TP /errorReport:queue  /utf-8 "D:\vcpkg\buildtrees\arabica\src[=11=]-February-67b234ed05\examples\XPath\xgrep.cpp"

如果我能让 VCPKG 添加 /I"D:\vcpkg\installed\x64-windows\include" 命令行参数就可以了。

我的CONTROL文件内容如下

Source: arabica
Version: 2020-February
Homepage: https://github.com/BenKeyFSI/arabica
Description: Arabica is an XML and HTML processing toolkit, providing SAX2, DOM, XPath, and XSLT implementations, written in Standard C++.
Build-Depends: boost-mpl, boost-type-traits, boost-spirit, boost-function, boost-bind, boost-smart-ptr, boost-lexical-cast

portfile.cmake内容如下

include(vcpkg_common_functions)

vcpkg_from_github(
  OUT_SOURCE_PATH SOURCE_PATH
  REPO BenKeyFSI/arabica
  REF 2020-February
  SHA512 3cf56a71c53e35eb2bc48332c96958e6800e5735a629f292f47e9b22b106f378e45abe046d6a7ed8604fe434d356efbf8744bd31fa905de6fcec62c7223f9e4c
  HEAD_REF master
)

vcpkg_configure_cmake(
  SOURCE_PATH ${SOURCE_PATH}
  PREFER_NINJA
)
vcpkg_install_cmake()
vcpkg_copy_pdbs()

file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/arabica RENAME copyright)

由于缺少 Boost 头文件,我在上面提到的编译器错误和其他几个错误导致失败。 None 如果仅在包含目录列表中包含 VCPKG 包含目录,则会发生这些编译器错误,因为已经安装了 Boost 并且 CONTROL 文件指出该库依赖于 Boost。

是否有我需要传递给 vcpkg_configure_cmake 或 vcpkg_install_cmake 的魔法咒语 "include the VCPKG include directory in the include path?"

If I could just get VCPKG to add the /I"D:\vcpkg\installed\x64-windows\include" command line argument it would work.

你不需要说服 vcpkg 去做,但 cmake。因此,只需将 vcpkg_configure_cmake 调用替换为:

vcpkg_configure_cmake(
  SOURCE_PATH ${SOURCE_PATH}
  PREFER_NINJA
  OPTIONS -DBUILD_WITH_BOOST=ON
)

在您的 CMakeLists.txt 中实际进行 find_package 提升。 (实际上 BUILD_WITH_BOOST 似乎不是一个选项,因为它是构建要求?!?!)。最好 link 反对 Boost::headers 目标,因为如果目标不可用,这会引发 CMake 错误。

然后它会构建但无法 link 并出现以下错误(三元组 x64-windows):

taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::M_ANY" (?M_ANY@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::M_EMPTY" (?M_EMPTY@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::M_PCDATA" (?M_PCDATA@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::M_ROOT" (?M_ROOT@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::F_RESTART" (?F_RESTART@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::F_CDATA" (?F_CDATA@Schema@SAX@Arabica@@2HB)
taggle.cpp.obj : error LNK2001: unresolved external symbol "public: static int const Arabica::SAX::Schema::F_NOFORCE" (?F_NOFORCE@Schema@SAX@Arabica@@2HB)
taggle.exe : fatal error LNK1120: 7 unresolved externals

因此,如果找不到内部符号,我假设您的 CMakeLists.txt 存在逻辑错误。 (构建x64-windows-static成功所以是符号可见性问题)

您还需要添加

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

给你的portfile.cmake