-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
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 theexported-cmake-targetsfile.
How to Repeat
STEPS:
- Clone the ModernCppStarter repo and change into the "ModernCppStarter" subdirectory
- MAYBE OPTIONAL: In
CMakeLists.txtfile,
change the lineCPMAddPackage("gh:TheLartians/[email protected]")to use version1.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-initto 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 PROPERTIESPROBLEM
- The second library
Hello/Greeter::Hello(asTARGET) is not contained the${THIS_PROJECT}-exported-cmake-targetsfile (aka:build/CMakeFiles/Export/${THIS_PROJECT}Targets*.cmake) - Therefore, you cannot find the second library with
find_package()asCMakecommand.
EXPECTED
- Second library is contained in
exported-cmake-targetsfile for${THIS_PROJECT} - Additional targets should be contained, too (if any additional TARGETS/ARTIFACTS are defined).
- BETTER: Provide an optional-parameter in
packageProjectthat allows to specify theTARGETS/EXPORTED_TARGETS(if theTARGETScannot be auto-discovery in the namespace${PROJECT_NAME}.
QUESTION
- Am I missing something here ?!?
- I found no constraint in the description of the project
thatPackageProject()only works if only oneTARGET(executableorlibrary) is defined. - I looked at the implementation of
packageProject()and see that only oneTARGETis processed internally.
Metadata
Metadata
Assignees
Labels
No labels