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

[question] Locating scripts in a "build-scripts" package via CMake #15925

Open
1 task done
tbsuht opened this issue Mar 22, 2024 · 4 comments
Open
1 task done

[question] Locating scripts in a "build-scripts" package via CMake #15925

tbsuht opened this issue Mar 22, 2024 · 4 comments
Assignees

Comments

@tbsuht
Copy link

tbsuht commented Mar 22, 2024

What is your question?

Hi,

I have a package for all our "generic" CMake files and this also contains some shell scripts, which are called by custom CMake targets.

class BuildFiles(ConanFile):
    name="foobar"
    exports_sources = ("cmake/*", "coverage/*")
    package_type = "build-scripts"

    def package(self):
        copy(self, pattern="cmake/*",
             src=self.source_folder, dst=self.package_folder)
        copy(self, pattern="coverage/*", excludes=["*.md"],
             src=self.source_folder, dst=self.package_folder)

    def package_info(self):
        self.cpp_info.includedirs = []
        self.cpp_info.libdirs = []
        self.cpp_info.builddirs = ["cmake", "coverage"]

Locating and using the contained CMake files is simple:

find_package(foobar)
include(whatever)

Is there also a nice and easy way to locate scripts?
Currently in order to call a contained script "coverage.sh", I'm using the path variables conan is generating to locate the installed package "foobar".

Example:

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(BUILD_DIRS ${foobar_BUILD_DIRS_DEBUG})
else()
    set(BUILD_DIRS ${foobar_BUILD_DIRS_RELEASE})
endif()

foreach(BUILD_DIR ${BUILD_DIRS})
    if(${BUILD_DIR} MATCHES "coverage$")
        set(COVERAGE_FILES_PATH ${BUILD_DIR})
    endif()
endforeach()

add_custom_target(
    gcovr-${PROJECT_NAME}
    COMMAND ${COVERAGE_FILES_PATH}/coverage.sh
)

Is there a simpler way? Can I use those CMake variables conan is providing or are they an implementation detail which shouldn't be used?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Mar 27, 2024
@memsharded
Copy link
Member

Hi @tbsuht

In general, build-scripts will be tool_requires, so they will not be generating files for find_package() by default.
But it shouldn't be necessary, please check https://docs.conan.io/2/examples/graph/requires/consume_cmake_macro.html#consume-cmake-macro, adding via builddirs the directories containing cmake files, you can directly include() it without a find_package().

It is not very clear if the code with add_custom_target(gcovr-${PROJECT_NAME} is in the consumer CMakeLists.txt using the foobar build scripts, or it is inside the .cmake scripts inside the "foobar" package, could you please clarify?

@tbsuht
Copy link
Author

tbsuht commented Mar 28, 2024

In general, build-scripts will be tool_requires, so they will not be generating files for find_package() by default.
But it shouldn't be necessary, please check https://docs.conan.io/2/examples/graph/requires/consume_cmake_macro.html#consume-cmake-macro, adding via builddirs the directories containing cmake files, you can directly include() it without a find_package().

This is somehow not working for me, neither if I use requires() nor tool_requires() as long as I don't place a find_package() (which only works for requires()) in front of the includes().

How are the builddirs transfered to the consumer in order to debug this?
I'm using the BuildFiles package mentioned above.

@tbsuht
Copy link
Author

tbsuht commented Mar 28, 2024

It is not very clear if the code with add_custom_target(gcovr-${PROJECT_NAME} is in the consumer CMakeLists.txt using the foobar build scripts, or it is inside the .cmake scripts inside the "foobar" package, could you please clarify?

Both are in the same package foobar. The cmake code creates a target for generating code coverage and should call a script in the same package.

@tbsuht
Copy link
Author

tbsuht commented Mar 28, 2024

Ok, I think I understand why this is not working (builddirs part)

First: I was building with cmake-conan. The infos about the builddirs are placed in the generated toolchain file. As far as I remember, cmake-conan and CMakeToolchain-generator are not playing well together?

If I build directly via conan create it is working.

So is there any way around that? using requires() and find_package is working but that feels like a hack for such a build-package.

/e: I'm talking about the workflow without using a manual conan install

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

No branches or pull requests

2 participants