Search code examples
vcpkg

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


I am attempting to create a new port for VCPKG, for the Arabica project. The vcpkg install command is failing. The first error is as follows.

...\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]

The thing is that this file is installed in the VCPKG include directory. To be precise it is installed at D:\vcpkg\installed\x64-windows\include\boost\shared_ptr.hpp.

The command used to compile the file is as follows.

...\CL.exe /c /I"D:\vcpkg\buildtrees\arabica\x64-windows-dbg\include" /I"D:\vcpkg\buildtrees\arabica\src\0-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\0-February-67b234ed05\examples\XPath\xgrep.cpp"

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

The contents of my CONTROL file is as follows.

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

The contents of the portfile.cmake is as follows.

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)

This is failing with the compiler error I mentioned above and several other due to missing Boost header files. None of these compiler errors would occur if it would just include the VCPKG include directory in the list of include directories since Boost is already installed and the CONTROL file states that this library depends on Boost.

Is there a magical incantation I need to pass to either vcpkg_configure_cmake or vcpkg_install_cmake that says "include the VCPKG include directory in the include path?"


Solution

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

    You don't need to convince vcpkg to do that but cmake. So just replace your vcpkg_configure_cmake call with:

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

    to actually do the find_package call for boost in your CMakeLists.txt. (Actually BUILD_WITH_BOOST seems like a non option since it is build requirement?!?!). It is also better to link against the Boost::headers target since this would have thrown a CMake error if the target is unavailable.

    It will then build but fail to link with the following errors (triplet 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
    

    So I assume your CMakeLists.txt has logical errors if internal symbols cannot be found. (Building x64-windows-static is successful so it is a symbol visibility problem)

    you also need to add

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

    to your portfile.cmake