我正在尝试为netcdf-c构建一个conan包。NetCDF需要zlib和hdf 5作为依赖项,这两个都可以通过conan中心获得。
我把它们作为需求添加到我的conanfile.py。当运行conan create . testing/build
从我的conanfile.py创建conan包时,CMake无法构建netcdf-c。conan create
的输出显示zlib和hdf 5已经安装,但找不到。当使用cmake编译netcdf-c时,我必须如下设置configure:CPPFLAGS="-I${H5DIR}/include -I${ZDIR}/include" LDFLAGS="-L${H5DIR}/lib -L${ZDIR}/lib" --prefix=${NCDIR} --disable-dap
。如何在conanfile.py
中设置这些标志?
conanfile.py:
from conans import ConanFile, CMake, tools
class NetcdfcConan(ConanFile):
name = "netcdf_c"
version = "4.7.3"
license = "BSD 3-Clause 'New' or 'Revised' License"
author = "Arne Osterthun arne.osterthun@dlr.de"
description = "The Unidata network Common Data Form (netCDF) is an interface for scientific data access and a freely-distributed software library that provides an implementation of the interface. The netCDF library also defines a machine-independent format for representing scientific data. Together, the interface, library, and format support the creation, access, and sharing of scientific data. The current netCDF software provides C interfaces for applications and data. Separate software distributions available from Unidata provide Java, Fortran, Python, and C++ interfaces. They have been tested on various common platforms."
topics = ("raster data", "ndarray", "array")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}
requires = "zlib/1.2.11", "hdf5/1.10.6"
generators = "cmake"
def source(self):
self.run("git clone --branch v4.7.3 https://github.com/Unidata/netcdf-c.git")
def build(self):
cmake = CMake(self)
cmake.configure(source_folder="netcdf-c")
cmake.build()
def package(self):
pass
def package_info(self):
pass
输出:
[HOOK - attribute_checker.py] pre_export(): WARN: Conanfile doesn't have 'url'. It is recommended to add it as attribute
Exporting package recipe
netcdf_c/4.7.3@testing/build: A new conanfile.py version was exported
netcdf_c/4.7.3@testing/build: Folder: /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/export
netcdf_c/4.7.3@testing/build: Package recipe modified in export, forcing source folder removal
netcdf_c/4.7.3@testing/build: Use the --keep-source, -k option to skip it
netcdf_c/4.7.3@testing/build: Exported revision: d70e63d07a15cf7376055e606b3244c3
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=7
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
netcdf_c/4.7.3@testing/build: Forced build from source
netcdf_c/4.7.3@testing/build (test package): Installing package
Requirements
hdf5/1.10.6 from 'conan-center' - Cache
netcdf_c/4.7.3@testing/build from local cache - Cache
zlib/1.2.11 from 'conan-center' - Cache
Packages
hdf5/1.10.6:d1d93931f0a5aab8450858e1d6eae88ac6c39f6d - Cache
netcdf_c/4.7.3@testing/build:ed9c760b5cbeeac4d6f9420203834fe68a6384de - Build
zlib/1.2.11:d50a0d523d98c15bb147b18fa7d203887c38be8b - Cache
Installing (downloading, building) binaries...
zlib/1.2.11: Already installed!
hdf5/1.10.6: Already installed!
netcdf_c/4.7.3@testing/build: WARN: Build folder is dirty, removing it: /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/build/ed9c760b5cbeeac4d6f9420203834fe68a6384de
netcdf_c/4.7.3@testing/build: Configuring sources in /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/source
Cloning into 'netcdf-c'...
Note: checking out 'b7cd387bee8c661141fabb490f4969587c008c55'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
Checking out files: 100% (2211/2211), done.
netcdf_c/4.7.3@testing/build: Copying sources to build folder
netcdf_c/4.7.3@testing/build: Building your package in /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/build/ed9c760b5cbeeac4d6f9420203834fe68a6384de
netcdf_c/4.7.3@testing/build: Generator cmake created conanbuildinfo.cmake
netcdf_c/4.7.3@testing/build: Calling build()
-- The C compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Performing Test LIBTOOL_HAS_NO_UNDEFINED
-- Performing Test LIBTOOL_HAS_NO_UNDEFINED - Success
-- Performing Test CC_HAS_WCONVERSION
-- Performing Test CC_HAS_WCONVERSION - Success
-- Performing Test CC_HAS_SHORTEN_64_32
-- Performing Test CC_HAS_SHORTEN_64_32 - Failed
-- Unable to determine HDF5 C flags from HDF5 wrapper.
-- Unable to determine HDF5 C version from HDF5 wrapper.
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS
HDF5_HL_LIBRARIES C HL) (found version "")
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.10/Modules/FindHDF5.cmake:905 (find_package_handle_standard_args)
CMakeLists.txt:623 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "/home/domane/.conan/data/netcdf_c/4.7.3/testing/build/build/ed9c760b5cbeeac4d6f9420203834fe68a6384de/netcdf-c/build/CMakeFiles/CMakeOutput.log".
See also "/home/domane/.conan/data/netcdf_c/4.7.3/testing/build/build/ed9c760b5cbeeac4d6f9420203834fe68a6384de/netcdf-c/build/CMakeFiles/CMakeError.log".
netcdf_c/4.7.3@testing/build:
netcdf_c/4.7.3@testing/build: ERROR: Package 'ed9c760b5cbeeac4d6f9420203834fe68a6384de' build failed
netcdf_c/4.7.3@testing/build: WARN: Build folder /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/build/ed9c760b5cbeeac4d6f9420203834fe68a6384de
ERROR: netcdf_c/4.7.3@testing/build: Error in build() method, line 22
self.run("cd netcdf-c && mkdir build && cd build && cmake .. && cmake --build . -- -j8", run_environment=True)
ConanException: Error 1 while executing cd netcdf-c && mkdir build && cd build && cmake .. && cmake --build . -- -j8
1条答案
按热度按时间pw9qyyiw1#
实际上你的需求已经安装好了,但是CMake并不知道,Conan不会自动安装,因此,你需要在列表中添加生成器cmake_find_package,它将为你的构建提供Findxxx.cmake文件:
cmake发生器有什么作用?
它会创建conanbuildinfo.cmake文件,其中包含构建软件包所需的所有信息。但是,您需要将该文件插入到作者的cmake文件中。
请查看Conan docs以了解有关该生成器的更多信息。