I have seemingly successfully built my first local conan package and uploaded it to my local artifactory.. I can also add it by full name in the dependencies of other projects like so..
[requires]
thrift/0.13.0
mypkg/0.0.1@user/channel
[generators]
cmake
I can link it without error likeso in my OtherProject CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(OtherProject)
add_compile_options(-std=c++11)
# Using the "cmake" generator
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_executable(OtherProject src/Main.cpp)
target_link_libraries(OtherProject CONAN_PKG::my-pkg)
but when I attempt to reference this in my consuming project's C++ it fails to find the mypkg.a file or any headers I expect to be available to it? Did I build my recipe incorrectly? Or am I just needing to change how I reference my new conan package in my code ?
OtherProject/consumingHeader.H
#pragma once
#include "MyPkgsHeader.h"
Error on build
> cmake --build .
Scanning dependencies of target OtherProject
[ 50%] Building CXX object CMakeFiles/OtherProject.dir/src/Main.cpp.o
In file included from /OtherProject/src/Main.cpp:12:
/OtherProject/src/TestCppClient.h:8:10: fatal error: 'MyPkgsHeader.h' file not found
#include "MyPkgsHeader.h"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/OtherProject.dir/src/Main.cpp.o] Error 1
make[1]: *** [CMakeFiles/OtherProject.dir/all] Error 2
make: *** [all] Error 2
MyPkg Recipe conanfile.py
from conans import ConanFile, CMake, tools
class MyPkgConan(ConanFile):
name = "mypkg"
version = "0.0.1"
license = "<Put the package license here>"
author = "<Put your name here> <And your email here>"
url = "<Package recipe repository url here, for issues about the package>"
description = "<Description of mypkg here>"
topics = ("<Put some tag here>", "<here>", "<and here>")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}
generators = "cmake"
def source(self):
self.run("git clone --depth 1 --branch 0.0.1 git@github.com:PROJECT/my-pkg.git")
tools.replace_in_file("my-pkg/CMakeLists.txt", " LANGUAGES CXX )",
''' LANGUAGES CXX )
add_compile_options(-std=c++11)''')
def build(self):
cmake = CMake(self)
cmake.configure(source_folder="my-pkg")
cmake.build()
# Explicit way:
# self.run('cmake %s/hello %s'
# % (self.source_folder, cmake.command_line))
# self.run("cmake --build . %s" % cmake.build_config)
def package(self):
self.copy("*.h", dst="include", src="my-pkg")
self.copy("*hello.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.dylib", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)
def package_info(self):
self.cpp_info.libs = ["mypkg"]
#EDIT: Seeing a problem with includes folder
As instructed I took a look at my conanbuildinfo.cmake and specifically looked for the path under CONAN_INCLUDE_DIRS_MY-PKG
the source files are in a folder structure I didn't expect
/../<conanhash>/include/source/cppclient/client/MyPkgsHeader.h
when I was expected perhaps
/../<conanhash>/client/MyPkgsHeader.h
or
/../<conanhash>/MyPkgsHeader.h
Sounds like I need to change my recipe a bit...