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

package_project() does not normalize the install paths before printing #117

Open
ClausKlein opened this issue Apr 3, 2022 · 8 comments
Open
Labels
question Further information is requested

Comments

@ClausKlein
Copy link
Contributor

ClausKlein commented Apr 3, 2022

my CMakeLists.txt contains this:

# ---- Create library ----

# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
# target: add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} ${headers} ${sources})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)

# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")

# Link dependencies
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)

# FIXME: should be PRIVATE! CK
target_link_libraries(${PROJECT_NAME} PUBLIC project_warnings project_options)

# target_include_directories with the SYSTEM modifier will request the compiler
# to omit warnings from the provided paths, if the compiler supports that
target_include_directories(
  ${PROJECT_NAME} SYSTEM PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
                                $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

if(CMAKE_SKIP_INSTALL_RULES)
  return()
endif()

# ---- Create an installable target ----
# this allows users to install and find the library via `find_package()`.

# Add other targets that you want installe here. Or be default we just package
# all targets recursively found for the current folder if not specified.
package_project(
  NAME ${PROJECT_NAME}
  TARGETS ${PROJECT_NAME} project_options project_warnings
  PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/include
  PUBLIC_DEPENDENCIES_CONFIGURED "fmt 8.1.1"
  # FIXME: not yet used! PRIVATE_DEPENDENCIES_CONFIGURED project_options project_warnings
)
cmake -B ./build-ModernCmakeStarter-Debug -S /Users/clausklein/Workspace/cpp/ModernCmakeStarter/all -D OPT_ENABLE_COVERAGE=NO -DOPT_WARNINGS_AS_ERRORS=NO
-- CPM: adding package [email protected] (v3.0.0 at /Users/clausklein/.cache/CPM/cxxopts/0c1df694f5ab3306e541038e6a2ed62926062894)
-- CPM: adding package greeter@ (/Users/clausklein/Workspace/cpp/ModernCmakeStarter/standalone/..)
-- CPM: greeter: adding package [email protected] (v0.20.0 at /Users/clausklein/.cache/CPM/project_options/f4f28e0d6a43eb4247d834f6b906d21040cf1ef9)
-- CPM: greeter: adding package [email protected] (v1.8.0 at /Users/clausklein/.cache/CPM/packageproject.cmake/987b02f8a9fe04de3c43e0e7a1afbb29c87adc5e)
-- Module support is disabled.
-- Version: 8.1.1
-- Build type: Debug
-- CXX_STANDARD: 20
-- Required features: cxx_variadic_templates
-- CPM: greeter: adding package [email protected] (8.1.1 at /Users/clausklein/.cache/CPM/fmt/15c05aa781ab44fa13a906fe5737c1d14e5edee9)
-- Developer mode is ON. For production, use `-DENABLE_DEVELOPER_MODE:BOOL=OFF`. Building the project for the developer...
-- The default CMAKE_C_STANDARD used by external targets and tools is not set yet. Using the latest supported C standard that is 90
-- /usr/local/bin/ccache found and enabled
-- CPM: adding package [email protected] (v2.4.8 at /Users/clausklein/.cache/CPM/doctest/367f22d2dff85570a9f727b99741f9e40b17df46)
-- CPM: adding package [email protected] (v1.7.3 at /Users/clausklein/.cache/CPM/format.cmake/17e103764947115e78d95ecc29c4bee54dc64e08)
-- CPM: adding package Greeter@ (/Users/clausklein/Workspace/cpp/ModernCmakeStarter/test/..)
-- CPM: adding package m.css@0 (a0d292ec311b97fefd21e93cdefb60f88d19ede6 at /Users/clausklein/.cache/CPM/m.css/23b42fe3166cf5c34c25c267ae0664557edd2200)
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/clausklein/Workspace/cpp/ModernCmakeStarter/build-ModernCmakeStarter-Debug
DESTDIR=/Users/clausklein/Workspace/cpp/stage cmake --install ./build-ModernCmakeStarter-Debug --prefix /usr
-- Install configuration: "Debug"
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-config.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-config-version.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/cxxopts/cxxopts-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/cxxopts.hpp
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/pkgconfig/cxxopts.pc
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/lib/libfmtd.a
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-config.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-config-version.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-targets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/cmake/fmt/fmt-targets-debug.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/args.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/chrono.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/color.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/compile.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/core.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/format.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/format-inl.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/locale.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/os.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/ostream.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/printf.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/ranges.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/include/fmt/xchar.h
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/lib/pkgconfig/fmt.pc
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include/greeter
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include/greeter/greeter.h
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/lib/libgreeter.a
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterConfigVersion.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterConfig.cmake
-- Old export file "/Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets.cmake" will be replaced.  Removing files [/Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets-debug.cmake].
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets.cmake
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/greeterTargets-debug.cmake
-- Installing: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/usage
-- # The package greeter provides the following CMake targets:

    find_package(greeter CONFIG REQUIRED)
    target_link_libraries(main PRIVATE  greeter::greeter greeter::project_options greeter::project_warnings)
  
bash-3.2$ 

This installed CMake config packages contains:

# Create imported target greeter::greeter
add_library(greeter::greeter STATIC IMPORTED)

set_target_properties(greeter::greeter PROPERTIES
  INTERFACE_COMPILE_FEATURES "cxx_std_20"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "fmt::fmt;greeter::project_warnings;greeter::project_options"
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "include"
)

# Create imported target greeter::project_options
add_library(greeter::project_options INTERFACE IMPORTED)

set_target_properties(greeter::project_options PROPERTIES
  INTERFACE_COMPILE_FEATURES "cxx_std_20"
  INTERFACE_COMPILE_OPTIONS "-fsanitize=address,undefined"
  INTERFACE_LINK_OPTIONS "-fsanitize=address,undefined"
)

# Create imported target greeter::project_warnings
add_library(greeter::project_warnings INTERFACE IMPORTED)

set_target_properties(greeter::project_warnings PROPERTIES
  INTERFACE_COMPILE_OPTIONS "\$<\$<COMPILE_LANGUAGE:CXX>:-Wall;-Wextra;-Wshadow;-Wnon-virtual-dtor;-Wold-style-cast;-Wcast-align;-Wunused;-Woverloaded-virtual;-Wpedantic;-Wconversion;-Wsign-conversion;-Wnull-dereference;-Wdouble-promotion;-Wformat=2;-Wimplicit-fallthrough>;\$<\$<COMPILE_LANGUAGE:C>:-Wall;-Wextra;-Wshadow;-Wcast-align;-Wunused;-Wpedantic;-Wconversion;-Wsign-conversion;-Wnull-dereference;-Wdouble-promotion;-Wformat=2;-Wimplicit-fallthrough>;\$<\$<COMPILE_LANGUAGE:CUDA>:-Wall;-Wextra;-Wunused;-Wconversion;-Wshadow>"
)
``


<!-- POLAR PLEDGE BADGE START -->
## Upvote & Fund

- I am using [Polar.sh](https://polar.sh/aminya) 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.

<a href="https://polar.sh/aminya/project_options/issues/117">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/aminya/project_options/issues/117/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/aminya/project_options/issues/117/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->
@aminya
Copy link
Owner

aminya commented Apr 4, 2022

Where is the strange part?

@aminya aminya added the more-information-needed The issue needs for information label Apr 4, 2022
@ClausKlein
Copy link
Contributor Author

ClausKlein commented Apr 4, 2022

-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include/greeter
-- Up-to-date: /Users/clausklein/Workspace/cpp/stage/usr/.//include/greeter/greeter.h

And this info in not right:

cat: /Users/clausklein/Workspace/cpp/stage/usr/share/greeter/usage

    find_package(greeter CONFIG REQUIRED)
    target_link_libraries(main PRIVATE  greeter::greeter greeter::project_options greeter::project_warnings)

see

set_target_properties(greeter::greeter PROPERTIES
  INTERFACE_COMPILE_FEATURES "cxx_std_20"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "fmt::fmt;greeter::project_warnings;greeter::project_options"
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "include"
)

@aminya
Copy link
Owner

aminya commented Apr 4, 2022

It seems correct to me. I don't see any issue here.

@ClausKlein
Copy link
Contributor Author

ClausKlein commented Apr 5, 2022

It seems correct to me. I don't see any issue here.

Yes, "seems" it is correct, but may be prevented to be clear.
It looks strange in context of the other install messages. see normal-path

And https://discourse.cmake.org/t/target-include-directories-mylib-system-is-exported-without-import-prefix/5359 !

@ClausKlein
Copy link
Contributor Author

The correct usage message should:

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

@aminya
Copy link
Owner

aminya commented Apr 5, 2022

It seems correct to me. I don't see any issue here.

Yes, "seems" it is correct, but may be prevented to be clear. It looks strange in context of the other install messages. see normal-path

And discourse.cmake.org/t/target-include-directories-mylib-system-is-exported-without-import-prefix/5359 !

The reporting is just for information and debugging purposes. CMake itself should normalize the paths before installation if that is important for you.

@aminya
Copy link
Owner

aminya commented Apr 5, 2022

target_link_libraries(main PRIVATE greeter::greeter)

That is subjective. When you export greeter::project_optinos, you cannot expect CMake to hide that target. Someone might really want to link with greeter::project_options.

However, it might be useful to add an option to hide this from the usage file.

@aminya aminya added question Further information is requested and removed more-information-needed The issue needs for information labels Apr 5, 2022
@aminya aminya changed the title package_project() creates strange install paths for CMAKE_INSTALL_INCLUDEDIR package_project() does not normalize the install paths before printing Apr 5, 2022
@ClausKlein
Copy link
Contributor Author

The correct usage message should:

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

This links fmt::fmt;greeter::project_warnings;greeter::project_options implicitly.

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

No branches or pull requests

2 participants