Конан создать пакет с зависимостями - PullRequest
0 голосов
/ 27 марта 2020

Я пытаюсь собрать пакет conan для netcdf- c. NetCDF требует zlib и hdf5 в качестве зависимостей, они оба доступны через центр conan.

Я добавил их как требования к моему conanfile.py. При запуске conan create . testing/build для создания пакета conan из моего conanfile.py CMake не может собрать netcdf- c. Вывод conan create показывает, что zlib и hdf5 установлены, но не могут быть найдены. При компиляции netcdf- c с помощью cmake я должен настроить его следующим образом: 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 Ответ

2 голосов
/ 27 марта 2020

Действительно, ваши требования установлены, но CMake не знает об этом. Конан не будет делать это автоматически, поэтому вам нужно добавить генератор conan_find_package в ваш список, который предоставит файлы Findxxx.cmake для вашей сборки:

generators = "cmake", "cmake_find_package"

Что делает cmake генератор do?

Создает файл conanbuildinfo.cmake, который содержит всю информацию, необходимую для сборки вашего пакета. Однако вам нужно вставить этот файл в файл cmake автора.

Просмотрите Conan docs , чтобы узнать больше об этом генераторе.

...