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

Including project_options in the installed package for interface libraries #108

Closed
ClausKlein opened this issue Mar 20, 2022 · 7 comments
Closed

Comments

@ClausKlein
Copy link
Contributor

ClausKlein commented Mar 20, 2022

see a178b9c

bash-3.2$ cd -
/Users/clausklein/cmake/cmakelib/test_install/build
bash-3.2$ ninja
[0/1] Re-running CMake...
-- vcpkg is already installed at /Users/clausklein/vcpkg.
-- Running vcpkg install
Detecting compiler hash for triplet x64-osx...
All requested packages are currently installed.
Restored 0 packages from /Users/clausklein/.cache/vcpkg/archives in 2.44 us. Use --debug to see more details.

Total elapsed time: 1.746 s

The package eigen3 provides CMake targets:

    find_package(Eigen3 CONFIG REQUIRED)
    target_link_libraries(main PRIVATE Eigen3::Eigen)

The package fmt provides CMake targets:

    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt)

    # Or use the header-only version
    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt-header-only)

-- Running vcpkg install - done
CMake Error at /Users/clausklein/vcpkg/scripts/buildsystems/vcpkg.cmake:782 (_find_package):
  Found package configuration file:

    /Users/clausklein/cmake/cmakelib/install/share/myproj_header_only_lib/myproj_header_only_libConfig.cmake

  but it set myproj_header_only_lib_FOUND to FALSE so package
  "myproj_header_only_lib" is considered to be NOT FOUND.  Reason given by
  package:

  The following imported targets are referenced, but are missing:
  myproj::project_options myproj::project_warnings

Call Stack (most recent call first):
  CMakeLists.txt:45 (find_package)


-- Configuring incomplete, errors occurred!
See also "/Users/clausklein/cmake/cmakelib/test_install/build/CMakeFiles/CMakeOutput.log".
See also "/Users/clausklein/cmake/cmakelib/test_install/build/CMakeFiles/CMakeError.log".
FAILED: CMakeFiles/impl-Debug.ninja build-Debug.ninja CMakeFiles/impl-Release.ninja build-Release.ninja CMakeFiles/impl-RelWithDebInfo.ninja build-RelWithDebInfo.ninja build.ninja 
/usr/local/Cellar/cmake/3.22.1/bin/cmake --regenerate-during-build -S/Users/clausklein/cmake/cmakelib/test_install -B/Users/clausklein/cmake/cmakelib/test_install/build
ninja: error: rebuilding 'build.ninja': subcommand failed
bash-3.2$ 

Upvote & Fund

@aminya is using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.

Thank you in advance for helping prioritize & fund our backlog!


Fund with Polar
@aminya
Copy link
Owner

aminya commented Mar 20, 2022

This is impossible in CMake. The interface libraries cannot have private dependencies.

@ClausKlein
Copy link
Contributor Author

This is impossible in CMake. The interface libraries cannot have private dependencies.

I know, but if you install this interface, it is also impossible to use this header only lib without project_options!

@aminya aminya changed the title header only libs should not depend on private project_options Installing project_options for interface libraries Mar 20, 2022
@aminya aminya removed the impossible label Mar 20, 2022
@aminya aminya reopened this Mar 20, 2022
@aminya aminya changed the title Installing project_options for interface libraries Including project_options in the installed package for interface libraries Mar 20, 2022
@aminya
Copy link
Owner

aminya commented Mar 20, 2022

We should also install project_options for header-only libraries.

@aminya aminya added the bug Something isn't working label Mar 20, 2022
@aminya
Copy link
Owner

aminya commented Mar 20, 2022

Well, I don't think we actually need this. package_project already generates the project_options and project_warnings targets:

Running test_install, then looking at myprojTargets.cmake:

image

@aminya aminya removed the bug Something isn't working label Mar 20, 2022
@aminya aminya closed this as completed Mar 20, 2022
@ClausKlein
Copy link
Contributor Author

If I use a header only lib i.e. boost::asio I will not import there development setting like:

--coverage

-Wpedantic -Werror... or

the worst case: g++ specific warnings, if I want to use clang++

I created this issue to show it is a wrong usage of project_options to export the project_options for every installed lib, independent of it is an interface or a normal lib!

@aminya
Copy link
Owner

aminya commented Mar 21, 2022

The config files generated by CMake are not portable! They have absolute paths in them, and they are generated based on the options you pass to project_options.

To avoid having test/sanitizer-related flags in the generated config, you should use FEATURE_TESTS flag.

https://github.com/cpp-best-practices/cpp_vcpkg_project/blob/830685f328fba4bbdcfb0540d0fbcecd95aaab5c/CMakeLists.txt#L30-L48

I will add this to the readme if it is not clear.

@aminya
Copy link
Owner

aminya commented Apr 6, 2022

The example in the readme is updated. Now, the FEATURE_TESTS option handles the sanitizer flag exports.

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