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

[workspaces] Add support for sub-projects that use find_package #3330

Closed
wants to merge 2 commits into from
Closed

[workspaces] Add support for sub-projects that use find_package #3330

wants to merge 2 commits into from

Conversation

AlessandroA
Copy link

@AlessandroA AlessandroA commented Aug 10, 2018

When using conan workspaces, if a sub-project contains a find_package command that points to another sub-project, CMake will fail saying that it cannot find the package.

This is expected, because the package will be added as a sub-directory by the top-level CMakeLists.txt file generated by conan.

The presence of find_package commands is common in packages that use the conan cmake_paths generator, for example.

The recommended solution to this is to re-define find_package as a no-op for all sub-projects, which is what this PR implements. See #3302 for more details. Closes #3302

Note: System-level packages and other conan dependencies found through find_package are unaffected, because they are not in the list of conan workspace packages, hence find_package is not redefined for them.

Implements #3302.

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one. Also adding a description of the changes in the changelog.rst file. https://github.com/conan-io/docs

find_package does not play well with subprojects added through
add_subdirectory.

As of today, the recommended approach is to re-define find_package to a
no-op for all subprojects before they are added as subdirectories.

After all subprojects have been added as subdirectories, all outstanding
targets will be found and there will be no linking error.

Fixes #3302: "[workspaces] Support for the cmake_paths generator".
This allows the user to run commands like `ninja test` for all
subprojects at once.
@ghost ghost added the contributor pr label Aug 10, 2018
@CLAassistant
Copy link

CLAassistant commented Aug 10, 2018

CLA assistant check
All committers have signed the CLA.

@pleroux0
Copy link

This change will break projects that already redefine find_package. Making add_subdirectory and find_package work together is an open CMake issue.

A better solution might be to generate a dummy config file that can be found by find_package which results in a no-op. This alternative solution will IMO cause the least amount of surprises for projects using this. I also think that it's the CMake project's responsibility to do so as well as define <project>_DIR so that the dummy config is the config file found after add_subdirectory is called. If #4808 gets addressed then the problem can be solved from CMake's side and hopefully remain compatible if the Cmake issue gets resolved.

@lasote
Copy link
Contributor

lasote commented May 21, 2019

The workspaces feature has been refactored. There is still no find package support but some ideas about the right approach. Take a look at my comment here: #4523

@lasote lasote closed this May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[workspaces] Support for the cmake_paths generator
4 participants