ExternalProject_Add 何时构建? [英] When does ExternalProject_Add build?
问题描述
我想构建 openssl 并将我的项目链接到它.在我的项目中,我有一个名为 net 的库,它是使用 openssl 的部分.所以在我的 netCMakeList 中,我添加了
I want to build openssl and link my project against it. In my project, I have a library called net which is the part that uses openssl. So in my netCMakeList, I added
include_directories(
../
+ ../../../ext/openssl/inc32/
)
add_library(net STATIC ${sources})
+ ADD_DEPENDENCIES(net openssl)
在用于组织所有外部库的 ext 文件夹中,我在名为 openssl 的文件夹中有一个全新的已解压的 openssl 源代码.然后我编辑了 extCmakeList
In my ext folder that is used for organizing all external library, I have a fresh unzipped openssl source code in a folder named openssl. Then I edited extCmakeList
message(STATUS "Configuring OpenSSL")
set(openssl_dir openssl)
if (CMAKE_CL_64)
include(ExternalProject)
set(OPENSSL_CONFIGURE perl Configure VC-WIN64A)
set(OPENSSL_MAKE ms\do_win64a && nmake -f ms\ntdll.mak)
ExternalProject_Add(openssl
PREFIX openssl
#-- Download Step ----------
SOURCE_DIR ${CMAKE_SOURCE_DIR}/ext/openssl
#--Configure step ----------
CONFIGURE_COMMAND ${OPENSSL_CONFIGURE}
#--Build Step ----------
BUILD_COMMAND ${OPENSSL_MAKE}
BUILD_IN_SOURCE 1
#--install Step ----------
INSTALL_COMMAND ""}
)
endif()
当我构建时,编译器抱怨它找不到包含文件,并且根本没有构建openssl源代码,因为没有out32dll和inc32.
When I built, the compiler complained the it can't find include files, and the openssl source code was not built at all, since there is no out32dll and inc32.
我的问题是:ExternalProject_Add 何时实际构建项目?如果我根据 openssl 创建我的 net 库,是否意味着当我构建 net 时,它需要先检查并构建 openssl?
My question is: When does ExternalProject_Add actually build the project? If I make my net library depending on openssl, does it mean when I build net it would need to check and build openssl first?
推荐答案
安装未完成
首先,我认为您错过了安装步骤.请参阅文档:
nmake -f "ms tdll.mak" 安装
nmake -f "ms tdll.mak" install
ExternalProject_Add
的简化版本是:
ExternalProject_Add(
OpenSSL
URL https://github.com/openssl/openssl/archive/OpenSSL_1_0_1h.tar.gz
CONFIGURE_COMMAND perl Configure VC-WIN64A "--prefix=${CMAKE_INSTALL_PREFIX}"
BUILD_COMMAND "ms\do_win64a.bat"
COMMAND nmake -f "ms\ntdll.mak"
BUILD_IN_SOURCE 1
INSTALL_COMMAND nmake -f "ms\ntdll.mak" install
)
查找 OpenSSL
其次,如果要查找openssl库和头文件,需要使用find_package(OpenSSL) 命令:
find_package(OpenSSL REQUIRED)
message("Libs: ${OPENSSL_LIBRARIES}")
message("Includes: ${OPENSSL_INCLUDE_DIR}")
构建
现在,如果您将所有这些命令放在一个项目中,配置步骤将失败:) 因为这不是 ExternalProject 的设计方式.必须首先配置由几个或一个 ExternalProject_Add 命令创建的超级构建,然后构建步骤将从外部档案安装库.这将与您的项目冲突,因为无法找到 openssl 库 - superbuild 尚未安装它们.
Builds
Now, if you put all this commands together in one project configure step will fail :) Because it's not how ExternalProject designed. Superbuild that made by few or one ExternalProject_Add commands must be configured first, then build step will install the libraries from external archives. This will conflict with your project, because openssl libraries can't be found - they are not installed by superbuild yet.
拆分 cmake 代码.首先运行 superbuild(即下载并安装 openssl):
Split cmake code. Run superbuild first (i.e. download and install openssl):
> cmake -Hsuperbuild -B_buildssuperbuild "-GVisual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=extinstall
# note, no extinstall directory yet
> cmake --build _buildssuperbuild
# install done, libraries can be found in extinstall
然后构建你的项目,注意配置步骤中找到的库:
Then build your project, note that the libraries found on configure step:
> cmake -Huse -B_buildsuse "-GVisual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=extinstall
-- Found OpenSSL: .../ext/install/lib/ssleay32.lib;.../ext/install/lib/libeay32.lib (found version "1.0.1h")
Libs: .../ext/install/lib/ssleay32.lib;.../ext/install/lib/libeay32.lib
Includes: .../ext/install/include
> cmake --build _buildsuse
# OK
实验性
我有一个实验项目,它在一个命令中包含所有这些噪音(在 Visual Studio 2013 上测试的 Windows):
Experimental
I have an experimental project that wrap all of this noise in one command (Windows tested on Visual Studio 2013):
hunter_add_package(OpenSSL)
find_package(OpenSSL REQUIRED)
- https://github.com/ruslo/hunter
这篇关于ExternalProject_Add 何时构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!