fix: fix cmake template of packer

This commit is contained in:
2026-08-07 10:27:47 +08:00
parent 0141c461da
commit bad72120f9
@@ -18,32 +18,45 @@ set(MyRust_LIBRARY "${_IMPORT_PREFIX}/lib/{{ artifact_dll }}")
set(MyRust_INCLUDE_DIR "${_IMPORT_PREFIX}/include") set(MyRust_INCLUDE_DIR "${_IMPORT_PREFIX}/include")
{# Create modern CMake target (IMPORTED target) -#} {# Create modern CMake target (IMPORTED target) -#}
add_library({{ namespace }}::{{ target }} SHARED IMPORTED) add_library({{ target }} SHARED IMPORTED)
set_target_properties({{ namespace }}::{{ target }} PROPERTIES add_library({{ namespace }}::{{ target }} ALIAS {{ target }})
set_target_properties({{ target }} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
) )
{# Handle Windows and UNIX-like respectively -#} {# Handle Windows and UNIX-like respectively -#}
if(WIN32) if(WIN32)
set_target_properties({{ namespace }}::{{ target }} PROPERTIES set_target_properties({{ target }} PROPERTIES
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/{{ artifact_dll }}" IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/{{ artifact_dll }}"
IMPORTED_IMPLIB "${_IMPORT_PREFIX}/lib/{{ artifact_lib }}" IMPORTED_IMPLIB "${_IMPORT_PREFIX}/lib/{{ artifact_lib }}"
) )
else() else()
set_target_properties({{ namespace }}::{{ target }} PROPERTIES set_target_properties({{ target }} PROPERTIES
IMPORTED_LOCATION "${_IMPORT_PREFIX}/lib/{{ artifact_dll }}" IMPORTED_LOCATION "${_IMPORT_PREFIX}/lib/{{ artifact_dll }}"
) )
endif() endif()
{# Cleanup temporary variables -#}
set(_IMPORT_PREFIX)
{% if dependencies | length != 0 -%} {% if dependencies | length != 0 -%}
{# Pull in declared dependencies and wire them into the imported target -#} {# Pull in declared dependencies and wire them into the imported target -#}
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
{% for dep in dependencies -%} {% for dep in dependencies -%}
find_dependency({{ dep.package }}) find_dependency({{ dep.package }})
{% endfor -%} {% endfor -%}
set_target_properties({{ namespace }}::{{ target }} PROPERTIES set_target_properties({{ target }} PROPERTIES
INTERFACE_LINK_LIBRARIES "{{ dependencies | map(attribute='target') | join(';') }}" INTERFACE_LINK_LIBRARIES "{{ dependencies | map(attribute='target') | join(';') }}"
) )
{%- endif %} {%- endif %}
{# Cleanup temporary variables -#} {# Verify component (although there is no component) -#}
set(_IMPORT_PREFIX) macro(check_required_components _NAME)
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(NOT ${_NAME}_${comp}_FOUND)
if(${_NAME}_FIND_REQUIRED_${comp})
set(${_NAME}_FOUND FALSE)
endif()
endif()
endforeach()
endmacro()
check_required_components({{ target }})