You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# -- 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.
The text was updated successfully, but these errors were encountered:
VERIFIED WITH VERSION:
1.11.2
(usingcmake version 3.27.5
and3.30.2
)the second library is missing in the
exported-cmake-targets
file.How to Repeat
STEPS:
CMakeLists.txt
file,change the line
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.8.0")
to use version1.11.2
.cmake-init
to create and populate the "build" directory:PROBLEM
Hello
/Greeter::Hello
(asTARGET
) is not contained the${THIS_PROJECT}-exported-cmake-targets
file (aka:build/CMakeFiles/Export/${THIS_PROJECT}Targets*.cmake
)find_package()
asCMake
command.EXPECTED
exported-cmake-targets
file for${THIS_PROJECT}
packageProject
that allows to specify theTARGETS
/EXPORTED_TARGETS
(if theTARGETS
cannot be auto-discovery in the namespace${PROJECT_NAME}
.QUESTION
that
PackageProject()
only works if only oneTARGET
(executable
orlibrary
) is defined.packageProject()
and see that only oneTARGET
is processed internally.The text was updated successfully, but these errors were encountered: