Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

headers not copied when creating a library in local cache #17677

Open
1 task done
joesulewski opened this issue Jan 31, 2025 · 3 comments
Open
1 task done

headers not copied when creating a library in local cache #17677

joesulewski opened this issue Jan 31, 2025 · 3 comments
Assignees

Comments

@joesulewski
Copy link

joesulewski commented Jan 31, 2025

What is your question?

Hello,

I have a simple project that has the following structure

  • -dplib
    • src
      • files.cpp
    • include
      • headerfiles.hpp
    • CMakeLists.txt
    • conanfile.py
    • test_project

The project is to create a library and publish the project to my local cache so another project of mine can import it and use it. When I issue the conan create the include folder is missing in the published cache so the test_project fails. When I look at the directory:
--- ~/.conan2/p/b/dplibb273b250fbe5f/p/
-coaninfo.txt
-conanmanifest.txt
-lib
-libdplib.a

How do I get the include folder to be added to the cache? By the way this is on Ubuntu 24

Joe

My CMakeFile: --------------------------------------------------------------------------------------------------------

CMAKE_MINIMUM_REQUIRED(VERSION 3.28)
PROJECT(dplib)

message(STATUS "Building in folder: ${CMAKE_CURRENT_DIRECTORY}")

FIND_PACKAGE(Boost REQUIRED)
FIND_PACKAGE(exprtk)
FIND_PACKAGE(XercesC)

FILE(GLOB DPLIB_HEADERS include)
FILE(GLOB DPLIB_SOURCES src/*.cpp src/*.cxx)
SET(SOURCE_FILES ${DPLIB_HEADERS} ${DPLIB_SOURCES})

ADD_LIBRARY(dplib ${DPLIB_SOURCES} ${DPLIB_HEADERS})
TARGET_INCLUDE_DIRECTORIES(dplib PUBLIC ${DPLIB_HEADERS})

TARGET_LINK_LIBRARIES(dplib PUBLIC boost::boost exprtk::exprtk XercesC::XercesC)
INSTALL(TARGETS dplib)

My conanfile.py: --------------------------------------------------------------------------------------------------------

from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps


class DPLibRecipe(ConanFile):
    name = "dplib"
    version = "1.0"
    package_type = "static-library"

    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = {"shared": False, "fPIC": True}

    # Sources are located in the same place as this recipe, copy them to the recipe
    exports_sources = "CMakeLists.txt", "src/*", "include/*"

    def config_options(self):
        if self.settings.os == "Windows":
            del self.options.fPIC

    def configure(self):
        if self.options.shared:
            self.options.rm_safe("fPIC")

    def layout(self):
        cmake_layout(self)

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self)
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake=CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["dplib"]

    def requirements(self):
        self.requires("boost/1.79.0")
        self.requires("exprtk/0.0.3")
        self.requires("xerces-c/3.2.3")

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded
Copy link
Member

Hi @joesulewski

thanks for your question.

This wouldn't be a Conan question, but a CMake question.
If using cmake.install() it means that the CMake should have the correct instructions to install headers, but your CMakeLists.txt is failing to do so.

A solution would be something like defining the headers of the target:

set_target_properties(dplib PROPERTIES PUBLIC_HEADER "include/myheader.h")

Some modern definition of headers would be using generator expressions, something in the line (not tested):

target_include_directories(dplib PUBLIC
          $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
          $<INSTALL_INTERFACE:include>
        )

@joesulewski
Copy link
Author

Thank you so much. I'm clearly having a hard time knowing the boundaries between conan and cmake. Thank you for the clarification!

@memsharded
Copy link
Member

Thank you so much. I'm clearly having a hard time knowing the boundaries between conan and cmake. Thank you for the clarification!

Yeah, if you don't already know some C++ building and CMake, trying to learn both things at the same time can be a bit too much, so it is usually better to do step by step, first learn CMake, then Conan (even if they are not strictly tied, as Conan works with other build systems too).

FIND_PACKAGE(Boost REQUIRED)

that kind of syntax is now a bit outdated, the modern way would be lowercase find_package() (same for all other CMake functions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants