<i id='iPLZa'><tr id='iPLZa'><dt id='iPLZa'><q id='iPLZa'><span id='iPLZa'><b id='iPLZa'><form id='iPLZa'><ins id='iPLZa'></ins><ul id='iPLZa'></ul><sub id='iPLZa'></sub></form><legend id='iPLZa'></legend><bdo id='iPLZa'><pre id='iPLZa'><center id='iPLZa'></center></pre></bdo></b><th id='iPLZa'></th></span></q></dt></tr></i><div id='iPLZa'><tfoot id='iPLZa'></tfoot><dl id='iPLZa'><fieldset id='iPLZa'></fieldset></dl></div>
  • <small id='iPLZa'></small><noframes id='iPLZa'>

    <legend id='iPLZa'><style id='iPLZa'><dir id='iPLZa'><q id='iPLZa'></q></dir></style></legend>
    <tfoot id='iPLZa'></tfoot>

        <bdo id='iPLZa'></bdo><ul id='iPLZa'></ul>
      1. 如何克隆外部(来自 git)cmake 项目并将其集成到本地项目中

        How to clone and integrate external (from git) cmake project into local one(如何克隆外部(来自 git)cmake 项目并将其集成到本地项目中)
          <tbody id='4vRkS'></tbody>
                <bdo id='4vRkS'></bdo><ul id='4vRkS'></ul>
              • <small id='4vRkS'></small><noframes id='4vRkS'>

                <i id='4vRkS'><tr id='4vRkS'><dt id='4vRkS'><q id='4vRkS'><span id='4vRkS'><b id='4vRkS'><form id='4vRkS'><ins id='4vRkS'></ins><ul id='4vRkS'></ul><sub id='4vRkS'></sub></form><legend id='4vRkS'></legend><bdo id='4vRkS'><pre id='4vRkS'><center id='4vRkS'></center></pre></bdo></b><th id='4vRkS'></th></span></q></dt></tr></i><div id='4vRkS'><tfoot id='4vRkS'></tfoot><dl id='4vRkS'><fieldset id='4vRkS'></fieldset></dl></div>

                1. <legend id='4vRkS'><style id='4vRkS'><dir id='4vRkS'><q id='4vRkS'></q></dir></style></legend>
                  <tfoot id='4vRkS'></tfoot>

                2. 本文介绍了如何克隆外部(来自 git)cmake 项目并将其集成到本地项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在尝试使用 Google Test 时遇到了一个问题.

                  I faced with a problem when I was trying to use Google Test.

                  关于如何使用ExternalProject_Add将gtest添加到项目中有很多手册,但其中大部分描述了一种基于使用gtest下载zip存档并构建它的方法.

                  There are lot of manuals on how to use ExternalProject_Add for the adding gtest into the project, however most of these describe a method based on downloading zip archive with gtest and build it.

                  众所周知,gtest 是 github 托管和基于 cmake 的项目.所以我想找到原生的 cmake 方式.

                  As we know gtest is github-hosted and cmake-based project. So I'd like to find native cmake way.

                  如果这是一个只有头文件的项目,我会这样写:

                  If this would be a header-only project, I'd write something like:

                  cmake_minimum_required(VERSION 2.8.8)
                  include(ExternalProject)
                  find_package(Git REQUIRED)
                  
                  ExternalProject_Add(
                      gtest
                      PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/ext
                      GIT_REPOSITORY https://github.com/google/googletest.git
                      TIMEOUT 10
                      UPDATE_COMMAND ${GIT_EXECUTABLE} pull
                      CONFIGURE_COMMAND ""
                      BUILD_COMMAND ""
                      INSTALL_COMMAND ""
                      LOG_DOWNLOAD ON
                  )
                  
                  ExternalProject_Get_Property(gtest source_dir)
                  set(GTEST_INCLUDE_DIR ${source_dir}/googletest/include CACHE INTERNAL "Path to include folder for GTest")
                  set(GTEST_ROOT_DIR ${source_dir}/googletest CACHE INTERNAL "Path to source folder for GTest")
                  include_directories(${INCLUDE_DIRECTORIES} ${GTEST_INCLUDE_DIR} ${GTEST_ROOT_DIR})
                  message(${GTEST_INCLUDE_DIR})
                  

                  并从我的 cmake 项目中添加此脚本,例如:

                  and add this script from my cmake project like:

                   set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake.modules/")
                   include(AddGTest)
                  ....
                   add_dependencies(${PROJECT_NAME} gtest)
                  

                  然而,这需要一个构建步骤.

                  However this requires a build step.

                  这应该如何实施?

                  1. 通过将 BUILD_COMMAND 添加到 ExternaProject_Add 并与生成的库链接?
                  2. 或者将 gtest 的 cmakelists 包含到我的项目中,如下所示:
                  1. By adding BUILD_COMMAND into ExternaProject_Add and linking with produced libs?
                  2. Or by including gtest's cmakelists into my project, something like this:

                  add_subdirectory (${CMAKE_SOURCE_DIR}extsrcgtestgoogletestCMakeLists.txt)

                  这不是正确的方法,因为在项目加载时文件夹不存在.

                  this is not correct way because on the moment of the project load the folder does not exist.

                  1. 还有其他方法吗?

                  什么是正确/首选的方式?

                  What is a correct/prefer way?

                  推荐答案

                  我会采用第一种方法.您不需要指定构建命令,因为默认使用 cmake.这可能看起来像:

                  I would go with the first approach. You don't need to specify a build command because cmake is used by default. This could look like:

                  cmake_minimum_required(VERSION 3.0)
                  project(GTestProject)
                  
                  include(ExternalProject)
                  
                  set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)
                  
                  ExternalProject_Add(googletest
                      GIT_REPOSITORY https://github.com/google/googletest
                      CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
                  )
                  
                  include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
                  link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
                  
                  add_executable(FirstTest main.cpp)
                  add_dependencies(FirstTest googletest)
                  target_link_libraries(FirstTest gtest gtest_main pthread)
                  

                  我不知道这是否是正确/首选的方式,如果有的话.如果您想实现第二种方法,则必须首先使用 execute_process 下载代码.

                  I don't know if this is the correct/preferred way if there even is one. If you wanted to implement your second approach you would have to download the code with execute_process first.

                  这篇关于如何克隆外部(来自 git)cmake 项目并将其集成到本地项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                  <tfoot id='jUFUq'></tfoot>
                  <i id='jUFUq'><tr id='jUFUq'><dt id='jUFUq'><q id='jUFUq'><span id='jUFUq'><b id='jUFUq'><form id='jUFUq'><ins id='jUFUq'></ins><ul id='jUFUq'></ul><sub id='jUFUq'></sub></form><legend id='jUFUq'></legend><bdo id='jUFUq'><pre id='jUFUq'><center id='jUFUq'></center></pre></bdo></b><th id='jUFUq'></th></span></q></dt></tr></i><div id='jUFUq'><tfoot id='jUFUq'></tfoot><dl id='jUFUq'><fieldset id='jUFUq'></fieldset></dl></div>

                            <tbody id='jUFUq'></tbody>

                            <bdo id='jUFUq'></bdo><ul id='jUFUq'></ul>

                            <small id='jUFUq'></small><noframes id='jUFUq'>

                            <legend id='jUFUq'><style id='jUFUq'><dir id='jUFUq'><q id='jUFUq'></q></dir></style></legend>