Issue
I'm trying to build a conan package for netcdf-c. NetCDF requires zlib and hdf5 as dependencies, both of them are available through the conan center.
I added them as requirements to my conanfile.py. When running conan create . testing/build
to create the conan package from my conanfile.py CMake is not able to build netcdf-c. The output of conan create
shows me that zlib and hdf5 are installed, but can't be found. When compiling netcdf-c with cmake I have to set configure it like this: CPPFLAGS="-I${H5DIR}/include -I${ZDIR}/include" LDFLAGS="-L${H5DIR}/lib -L${ZDIR}/lib" --prefix=${NCDIR} --disable-dap
. How can I set these flags inside my 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 [email protected]"
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
output:
[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/[email protected]/build: A new conanfile.py version was exported
netcdf_c/[email protected]/build: Folder: /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/export
netcdf_c/[email protected]/build: Package recipe modified in export, forcing source folder removal
netcdf_c/[email protected]/build: Use the --keep-source, -k option to skip it
netcdf_c/[email protected]/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/[email protected]/build: Forced build from source
netcdf_c/[email protected]/build (test package): Installing package
Requirements
hdf5/1.10.6 from 'conan-center' - Cache
netcdf_c/[email protected]/build from local cache - Cache
zlib/1.2.11 from 'conan-center' - Cache
Packages
hdf5/1.10.6:d1d93931f0a5aab8450858e1d6eae88ac6c39f6d - Cache
netcdf_c/[email protected]/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/[email protected]/build: WARN: Build folder is dirty, removing it: /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/build/ed9c760b5cbeeac4d6f9420203834fe68a6384de
netcdf_c/[email protected]/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/[email protected]/build: Copying sources to build folder
netcdf_c/[email protected]/build: Building your package in /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/build/ed9c760b5cbeeac4d6f9420203834fe68a6384de
netcdf_c/[email protected]/build: Generator cmake created conanbuildinfo.cmake
netcdf_c/[email protected]/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/[email protected]/build:
netcdf_c/[email protected]/build: ERROR: Package 'ed9c760b5cbeeac4d6f9420203834fe68a6384de' build failed
netcdf_c/[email protected]/build: WARN: Build folder /home/domane/.conan/data/netcdf_c/4.7.3/testing/build/build/ed9c760b5cbeeac4d6f9420203834fe68a6384de
ERROR: netcdf_c/[email protected]/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
Solution
Indeed your requirements are installed, but CMake doesn't know about it. Conan won't do it automatically, thus, you need to add the generator cmake_find_package in your list, which will provide the Findxxx.cmake files for your build:
generators = "cmake", "cmake_find_package"
What does cmake generator do?
It creates the file conanbuildinfo.cmake which contains all information required to build your package. However, you need to inject that file in the author's cmake file.
Take a look on Conan docs to learn more about that generator.
Answered By - uilianries Answer Checked By - Robin (WPSolving Admin)