如何将vcpkg信息提供给CMake?

10
假设我使用安装了一些库以及它们的许多依赖项(比如)。现在我想使用编译一些针对这些库的程序。 我应该如何告诉我已经下载的所有库的所有位置?包括我已安装的主库?我只有一个设置,称为"源目录",它将指向我的代码。那么关于库的设置在哪里呢?
D:\Users\ThirdPartyDesign\CGAL-5.0-examples\CGAL-5.0\examples\Triangulation_2
λ env | grep CMAKE
CMAKE_TOOLCHAIN_FILE=D:\Users\ThirdPartyDesign\vcpkg\scripts\buildsystems\vcpkg.cmake



D:\Users\ThirdPartyDesign\CGAL-5.0-examples\CGAL-5.0\examples\Triangulation_2
λ cmake .
CMake Warning at CMakeLists.txt:18 (find_package):
  By not providing "FindCGAL.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "CGAL", but
  CMake did not find one.

  Could not find a package configuration file provided by "CGAL" with any of
  the following names:

    CGALConfig.cmake
    cgal-config.cmake

  Add the installation prefix of "CGAL" to CMAKE_PREFIX_PATH or set
  "CGAL_DIR" to a directory containing one of the above files.  If "CGAL"
  provides a separate development package or SDK, be sure it has been
  installed.


-- This program requires the CGAL library, and will not be compiled.
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Users/ThirdPartyDesign/CGAL-5.0-examples/CGAL-5.0/examples/Triangulation_2
2个回答

11

“Set CMAKE_TOOLCHAIN_FILE” 是什么意思?它是指在 shell 中使用 set 吗?它是指在 CMakeLists.txt 中添加 set 行吗?还是指在 cmake 命令行中使用 -DCMAKE...? - sigfpe
2
@sigfpe 使用它作为-DCMAKE_TOOLCHAIN_FILE=path_to_vcpkg\scripts\buildsystems\vcpkg.cmake 我不确定其他方法,但这个方法是有效的。 确保首先执行“vcpkg integrate install”。 - shubhamgoel27

6

我通过vcpkg添加了jsoncpp包。我使用以下命令将vcpkg存储库克隆到外部文件夹,甚至将其放在install_dependencies.sh文件中:

DIR="external"
git clone https://github.com/Microsoft/vcpkg.git "$DIR/vcpkg"
    cd "$DIR/vcpkg"
    ./bootstrap-vcpkg.sh
    ./vcpkg integrate install
    ./vcpkg install jsoncpp

接下来,在CMakeLists.txt文件中,在add_executable函数之后添加了以下命令:

# ...
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADERS})

#-- JSONCPP ------------------------------

set(JSON_INC_PATH external/vcpkg/packages/jsoncpp_x64-osx/include)
target_include_directories(${PROJECT_NAME} PUBLIC ${JSON_INC_PATH})

set(JSON_LIB_PATH external/vcpkg/packages/jsoncpp_x64-osx/lib)
target_link_directories(${PROJECT_NAME} PUBLIC ${JSON_LIB_PATH})

#----------------------------------------

target_link_libraries(${PROJECT_NAME}
        #...
        jsoncpp
        )

现在重新加载后,我可以使用以下方式来包含json库:
#include <json/json.h>
# Rest of code here...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接