Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support installing imported targets #167

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ include_guard()
macro(set_project_options_src_dir)
get_directory_property(LISTFILE_STACK LISTFILE_STACK)
list(POP_BACK LISTFILE_STACK _LIST_FILE)
cmake_path(GET _LIST_FILE PARENT_PATH ProjectOptions_SRC_DIR)
cmake_path(
GET
_LIST_FILE
PARENT_PATH
ProjectOptions_SRC_DIR)
endmacro()

# Common project settings run by default for all the projects that call `project_options()`
Expand Down
31 changes: 30 additions & 1 deletion src/PackageProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,21 @@ function(package_project)
set(FILE_SET_ARGS "FILE_SET" "HEADERS")
endif()

set(_filtered_targets_list)
set(_imported_targets_list)
foreach(_target ${_targets_list})
if(TARGET ${_target})
get_target_property(is_imported ${_target} IMPORTED)
if(NOT ${is_imported})
list(APPEND _filtered_targets_list ${_target})
else()
list(APPEND _imported_targets_list ${_target})
endif()
endif()
endforeach()

install(
TARGETS ${_targets_list}
TARGETS ${_filtered_targets_list}
EXPORT ${_PackageProject_EXPORT}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib
Expand All @@ -155,6 +168,22 @@ function(package_project)
COMPONENT dev
${FILE_SET_ARGS})

foreach(_imported_target ${_imported_targets_list})
get_target_property(_imported_location ${_imported_target} IMPORTED_LOCATION)
get_target_property(_imported_type ${_imported_target} TYPE)
if(${_imported_type} STREQUAL "SHARED_LIBRARY" OR ${_imported_type} STREQUAL "EXECUTABLE")
install(
FILES ${_imported_location}
TYPE BIN
COMPONENT bin)
elseif(${_imported_type} STREQUAL "STATIC_LIBRARY")
install(
FILES ${_imported_location}
TYPE LIB
COMPONENT lib)
endif()
endforeach()

# download ForwardArguments
FetchContent_Declare(
_fargs
Expand Down