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

Verify headers #75

Merged
merged 8 commits into from
Dec 6, 2024
Merged

Conversation

steve-downey
Copy link
Member

Convert to an INTERFACE target rather than static library and use the new-ish cmake verify headers mechanism to test that the headers compile and are stand alone.

Convert to an interface library and use verify headers to test that headers are
self-contained and compile correctly by themselves. Test install at end of CI
and run both Asan and RWDI builds.
Add the verify headers target to the build presets for each compiler.
Copy link
Member

@neatudarius neatudarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I think we should add this idea to our tomorrow's agenda.

I'm what others think. TLDR: We should have a rule in the standard for header only libraries!

@JeffGarland ?

Add the EXPORT component for the header install components.
@steve-downey
Copy link
Member Author

steve-downey commented Nov 10, 2024 via email

Add back FindPackage support.
Lint failed. Fixed indentation.
install(
EXPORT beman_optional26_export
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman/optional26/
NAMESPACE Beman::Optional26::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NAMESPACE Beman::Optional26::
NAMESPACE beman::optional26::

?

# Create the library target and named header set for beman_optional26
add_library(beman_optional26 STATIC)
add_library(beman_optional26 INTERFACE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_library(beman_optional26 INTERFACE)
add_library(beman.optional26 INTERFACE)

The standard says it should use . after beman. Would you like to apply these updates in your PR?

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can fix this up as part of the PR. Need to merge in other changes in any case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great. But feel free to speed-up/skip steps today if you need something in main for Poland.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: that will end in very strange behaviour! Normally I use something like this:

find_package(Boost CONFIG QUIET)
if(TARGET Boost::headers AND TARGET fmt::fmt)
    add_executable(to_string to_string.cpp)
    target_link_libraries(to_string fmt::fmt Boost::headers)
endif()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is creating the target that gets the named header file_set added to it? It's up here to avoid ordering problems between subdirectories.

@neatudarius
Copy link
Member

neatudarius commented Nov 12, 2024

@steve-downey , please proceed with this PR. We discussed yesterday in the sync and it's OK to propose this standard cmake practice in the Beman standard (same document, a new CMAKE.$NAME rule). Can you add this recommendation?

If you cannot help with that, I can do it after Poland week (in 2-3 weeks).

@steve-downey
Copy link
Member Author

@steve-downey , please proceed with this PR. We discussed yesterday in the sync and it's OK to propose this standard cmake practice in the Beman standard (same document, a new CMAKE.$NAME rule). Can you add this recommendation?

If you cannot help with that, I can do it after Poland week (in 2-3 weeks).

Names of the header set, install component, or all of the above?
The header set name needs to be non-colliding to allow add subdir composition. If it's not clear in the standard that the goal is to allow project composition, we should do so, just to clarify that if you find something that conflicts with composition, fixing it is allowed over rote adherence to the standard (not an issue here...)
The component name is part of the interface to the project, so it's probably even more important to standardise that. In particular it's likely to affect how building within vcpkg and conan, etc work.

@neatudarius
Copy link
Member

@steve-downey , please proceed with this PR. We discussed yesterday in the sync and it's OK to propose this standard cmake practice in the Beman standard (same document, a new CMAKE.$NAME rule). Can you add this recommendation?
If you cannot help with that, I can do it after Poland week (in 2-3 weeks).

Names of the header set, install component, or all of the above? The header set name needs to be non-colliding to allow add subdir composition. If it's not clear in the standard that the goal is to allow project composition, we should do so, just to clarify that if you find something that conflicts with composition, fixing it is allowed over rote adherence to the standard (not an issue here...) The component name is part of the interface to the project, so it's probably even more important to standardise that. In particular it's likely to affect how building within vcpkg and conan, etc work.

It sounds like it's a good idea to put in standard all of the above. I would approve that, and David was also happy about your PR. It's true that we had only 5 people in the last sync. If you want to get more feedback, do a discourse thread, but I would go directly with the PR in BEMAN_STANDARD.md.

@ClausKlein
Copy link

ClausKlein commented Nov 17, 2024

this PR ends in this cmake export packages which is not usable!

bash-5.2$ tree .install/clang-19/lib/cmake/
.install/clang-19/lib/cmake/
`-- beman
    `-- optional26
        |-- BemanOptional26Config.cmake
        `-- beman_optional26.cmake

3 directories, 2 files
bash-5.2$ 

Also the packagename-version.cmake is missing.

Usage:

cmake_minimum_required(VERSION 3.27...3.31)

project(beman_optional26_example VERSION 0.0.0 LANGUAGES CXX)

set(BEMAN_OPTIONAL26_LIBRARY "Beman::Optional26::beman_optional26")

if(PROJECT_IS_TOP_LEVEL)
    find_package(Beman::Optional26 0.0.0 EXACT REQUIRED)
endif()

Result:

cmake -S . -G Ninja -B .build -D CMAKE_PREFIX_PATH=../.install/clang-19
CMake Error at CMakeLists.txt:15 (find_package):
  By not providing "FindBeman::Optional26.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "Beman::Optional26", but CMake did not find one.

  Could not find a package configuration file provided by "Beman::Optional26"
  (requested version 0.0.0) with any of the following names:

    Beman::Optional26Config.cmake
    beman::optional26-config.cmake

  Add the installation prefix of "Beman::Optional26" to CMAKE_PREFIX_PATH or
  set "Beman::Optional26_DIR" to a directory containing one of the above
  files.  If "Beman::Optional26" provides a separate development package or
  SDK, be sure it has been installed.


-- Configuring incomplete, errors occurred!
bash-5.2$ 

@ClausKlein
Copy link

A header only library is architecture and compiler independent.

Why install under prefix/clang-19?

@ClausKlein
Copy link

bash-5.2$ cmake -S . -G Ninja -B .build -D CMAKE_PREFIX_PATH=../.install/clang-19
CMake Error at CMakeLists.txt:13 (find_package):
  Could not find a configuration file for package "beman_optional26" that
  exactly matches requested version "0.0.0".

  The following configuration files were considered but not accepted:

    /Users/clausklein/Workspace/cpp/beman-project/optional26/.install/clang-19/lib/cmake/beman_optional26/beman_optional26-config.cmake, version: unknown

-- Configuring incomplete, errors occurred!
bash-5.2$ 

@steve-downey
Copy link
Member Author

A header only library is architecture and compiler independent.

Why install under prefix/clang-19?

Habit, I suppose? Easier to always disambiguate than sort out of its strictly necessary.
Although if there are any other components of the project installed, not having collisions is useful.
In my normal usage, this install location is transient, and just used to produce a deb that's installed later.

@steve-downey
Copy link
Member Author

I'll work on the installation bugs and catch up with the Beman Standard in follow on PRs.

@steve-downey steve-downey merged commit 5cffcdb into bemanproject:main Dec 6, 2024
8 checks passed
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

Successfully merging this pull request may close these issues.

3 participants