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

PackageProject: Does not work if more than one TARGET is used #43

Open
jenisys opened this issue Aug 28, 2024 · 0 comments
Open

PackageProject: Does not work if more than one TARGET is used #43

jenisys opened this issue Aug 28, 2024 · 0 comments

Comments

@jenisys
Copy link

jenisys commented Aug 28, 2024

VERIFIED WITH VERSION: 1.11.2 (using cmake version 3.27.5 and 3.30.2)

  • I added a second library to the ModernCppStarter/CMakeLists.txt file
  • When I perform "cmake init" to create the build directory,
    the second library is missing in the exported-cmake-targets file.

How to Repeat

STEPS:

  • Clone the ModernCppStarter repo and change into the "ModernCppStarter" subdirectory
  • MAYBE OPTIONAL: In CMakeLists.txt file,
    change the line CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.8.0") to use version 1.11.2.
  • Add a second library to the ModernCppStarter/CMakeLists.txt file:
# -- TASK: Add a SECOND LIBRARY to the "ModernCppStarter/CMakeLists.txt" file after the first library
# SEE: https://github.com/TheLartians/ModernCppStarter/blob/master/CMakeLists.txt
...
add_library(Hello)
add_library(${PROJECT_NAME}::Hello ALIAS Hello)
target_sources(Hello
    PUBLIC ${headers}
    PUBLIC ${sources}
)
set_target_properties(Hello PROPERTIES CXX_STANDARD 20)
target_link_libraries(Hello PRIVATE fmt::fmt)
target_include_directories(Hello PUBLIC
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)
...
  • In a bash shell: Perform cmake-init to create and populate the "build" directory:
$ cmake -B build -S .
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CPM: Adding package PackageProject.cmake@1.11.2 (v1.11.2)
-- CPM: Adding package fmt@10.2.1 (10.2.1)
-- Version: 10.2.1
-- Build type:
-- Configuring done (5.7s)
-- Generating done (0.0s)
-- Build files have been written to: xxx/TheLartians_ModernCppStarter/build 

$ cd build
$ grep -R Greeter::
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets-noconfig.cmake:# Import target "Greeter::Greeter" for configuration ""
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets-noconfig.cmake:set_property(TARGET Greeter::Greeter APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets-noconfig.cmake:set_target_properties(Greeter::Greeter PROPERTIES
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets-noconfig.cmake:list(APPEND _cmake_import_check_targets Greeter::Greeter )
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets-noconfig.cmake:list(APPEND _cmake_import_check_files_for_Greeter::Greeter "${_IMPORT_PREFIX}/lib/Greeter-1.0/libGreeter.a" )
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets.cmake:foreach(_cmake_expected_target IN ITEMS Greeter::Greeter)
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets.cmake:# Create imported target Greeter::Greeter
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets.cmake:add_library(Greeter::Greeter STATIC IMPORTED)
CMakeFiles/Export/062d20113924c92337e05e6db16f7bdf/GreeterTargets.cmake:set_target_properties(Greeter::Greeter PROPERTIES

PROBLEM

  • The second library Hello/Greeter::Hello (as TARGET) is not contained the ${THIS_PROJECT}-exported-cmake-targets file (aka: build/CMakeFiles/Export/${THIS_PROJECT}Targets*.cmake)
  • Therefore, you cannot find the second library with find_package() as CMake command.

EXPECTED

  • Second library is contained in exported-cmake-targets file for ${THIS_PROJECT}
  • Additional targets should be contained, too (if any additional TARGETS/ARTIFACTS are defined).
  • BETTER: Provide an optional-parameter in packageProject that allows to specify the TARGETS/EXPORTED_TARGETS (if the TARGETS cannot be auto-discovery in the namespace ${PROJECT_NAME}.

QUESTION

  • Am I missing something here ?!?
  • I found no constraint in the description of the project
    that PackageProject() only works if only one TARGET (executable or library) is defined.
  • I looked at the implementation of packageProject() and see that only one TARGET is processed internally.
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

1 participant