source_group for targets
Hello all,
As the groups defined by source_group
are scoped in the directory where it is called, if multiple targets are created in this directory they all share these groups. It then acts as a directory property and AFAIK there is no function that would be its target property counterpart. I wonder if it would be possible to have such feature, which could be called something like target_source_group
, and that would follow the modern way of dealing with targets instead of directories.
As an example, I would like to be able to do stuff like that:
In a CMakeList.txt:
# ...
add_library(LibA)
target_sources(LibA
PUBLIC ${LibA_PUBLIC_HEADER_FILES} # list of public header files (interface)
PRIVATE ${LibA_PRIVATE_HEADER_FILES} ${LibA_SOURCE_FILES} # list of private header files and source files (implementation)
)
target_source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/Public/LibA" # LibA's public header files are here
PREFIX "Public\\LibA"
FILES ${LibA_PUBLIC_HEADER_FILES})
target_source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/Private/LibA" # LibA's private header files and source files are here
PREFIX "Private\\LibA"
FILES ${LibA_PRIVATE_HEADER_FILES} ${LibA_SOURCE_FILES})
add_library(LibB)
target_link_libraries(LibB PRIVATE LibA)
target_sources(LibA
PUBLIC ${LibB_PUBLIC_HEADER_FILES} # list of public header files (interface)
PRIVATE ${LibB_PRIVATE_HEADER_FILES} ${LibB_SOURCE_FILES} # list of private header files and source files (implementation)
)
target_source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/Public/LibB" # LibB's public header files are here
PREFIX "Public\\LibB"
FILES ${LibB_PUBLIC_HEADER_FILES})
target_source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/Private/LibB" # LibB's private header files and source files are here
PREFIX "Private\\LibB"
FILES ${LibB_PRIVATE_HEADER_FILES} ${LibB_SOURCE_FILES})
# With source_group the following group would override the one declared for LibA
target_source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/Public/LibA" # As LibB depends on LibA, it has knowledge of LibA's public header files...
PREFIX "Include\\LibA" # ... and can add them to a different group representing the header files it uses but that are not under its control
FILES ${LibA_PUBLIC_HEADER_FILES})
#...