Skip to content

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

@jenisys

Description

@jenisys

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:

# -- 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 [email protected] (v1.11.2)
-- CPM: Adding package [email protected] (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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions