So, since then I learned a bit more about CMake syntax. Here is the project I use in my tests:
cmake_minimum_required(VERSION 3.28)
project(sckit_build_core_plugin LANGUAGES C)
add_executable(_core src/example.c)
add_library(_library STATIC src/example_lib.c)
target_sources(_library PUBLIC FILE_SET HEADERS BASE_DIRS include FILES include/example1.h include/example2.h)
install(TARGETS _core RUNTIME DESTINATION bin)
install(TARGETS _library
ARCHIVE DESTINATION lib
FILE_SET HEADERS DESTINATION include
)
I anticipated that the coremodel_v2
would list 2 targets (it does) and that the HEADERS
fileset would be listed in the _library
target, as per the definition of the target in the CMakeLists.txt, they are not, in fact example?.h
are not found in the coremodel_v2, at all
The end goal was to identify the targets in a external project and configure which targets I wanted installed … right, this is not a thing I discovered, CMake does not install targets, please correct me.
So since then I moved onto defining COMPONENTS
, which can be independently installed, but not all projects will associate their TARGETS with COMPONENTS, and if I only build part of the TARGETS, CMake will fail trying to install the non-built TARGETS.
I guess, I segway’d into my real problem as a ‘bonus’ question - though it is normal that the HEADERS are not found in the coremodel_v2?
For completeness, the rest of the test that selects TARGETS & COMPONENTS:
cmake_minimum_required(VERSION 3.28)
project(sckit_build_core_plugin LANGUAGES C)
add_executable(_core src/example.c)
add_library(_library STATIC src/example_lib.c)
target_sources(_library PUBLIC FILE_SET HEADERS BASE_DIRS include FILES include/example1.h include/example2.h)
install(TARGETS _core RUNTIME DESTINATION bin COMPONENT executables)
install(TARGETS _library
ARCHIVE DESTINATION lib
COMPONENT libraries
FILE_SET HEADERS DESTINATION include
COMPONENT headers
)
So, I also discovered the directory-...
dataset. So, I first discover the TARGETS, build the ones I want, then look in the directory-...
which COMPONENTS they belong to and if I find one Unspecified
, then I rebuild all the targets and install all, because I would not know how the project intended to build/install the TARGETS. Hope this is not too confusing
Thank you