feat: finish cmake generation
This commit is contained in:
@@ -1,23 +1,36 @@
|
||||
{# Get the path to directory where current XXXConfig.cmake file is (i.e. /path/to/installation/lib/cmake/XXX) -#}
|
||||
get_filename_component(PACKAGE_CMAKE_CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
{# Check whether this target is already exported -#}
|
||||
if(TARGET {{ namespace }}::{{ target }})
|
||||
message(STATUS "Target {{ namespace }}::{{ target }} is already defined.")
|
||||
message(STATUS "We will reuse it. Please check their version for compatibility.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
{# Compute installation root directory (back to parent 3 times, i.e. /path/to/installation) -#}
|
||||
get_filename_component(PACKAGE_PREFIX_DIR "${PACKAGE_CMAKE_CONFIG_PATH}/../../../" ABSOLUTE)
|
||||
{#
|
||||
Get the path to directory where current XXXConfig.cmake file is (i.e. /path/to/installation/lib/cmake/XXX)
|
||||
And compute installation root directory (back to parent 3 times, i.e. /path/to/installation)
|
||||
-#}
|
||||
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}/../../../" ABSOLUTE)
|
||||
|
||||
{# Setup library and header file paths -#}
|
||||
set(MyRust_LIBRARY "${PACKAGE_PREFIX_DIR}/lib/ {{- artifact_filename -}} }")
|
||||
set(MyRust_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||
set(MyRust_LIBRARY "${_IMPORT_PREFIX}/lib/{{ artifact_dll }}")
|
||||
set(MyRust_INCLUDE_DIR "${_IMPORT_PREFIX}/include")
|
||||
|
||||
{# Create modern CMake target (IMPORTED target) -#}
|
||||
add_library(MyRust::MyRust SHARED IMPORTED)
|
||||
set_target_properties(MyRust::MyRust PROPERTIES
|
||||
IMPORTED_LOCATION "${MyRust_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${MyRust_INCLUDE_DIR}"
|
||||
add_library({{ namespace }}::{{ target }} SHARED IMPORTED)
|
||||
set_target_properties({{ namespace }}::{{ target }} PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
|
||||
)
|
||||
|
||||
{# Handle the Windows-specific case that .dll is seperated with .lib -#}
|
||||
{# Handle Windows and UNIX-like respectively -#}
|
||||
if(WIN32)
|
||||
set_target_properties(MyRust::MyRust PROPERTIES
|
||||
IMPORTED_IMPLIB "${PACKAGE_PREFIX_DIR}/lib/myrust.lib"
|
||||
)
|
||||
set_target_properties({{ namespace }}::{{ target }} PROPERTIES
|
||||
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/{{ artifact_dll }}"
|
||||
IMPORTED_IMPLIB "${_IMPORT_PREFIX}/lib/{{ artifact_lib }}"
|
||||
)
|
||||
else()
|
||||
set_target_properties({{ namespace }}::{{ target }} PROPERTIES
|
||||
IMPORTED_LOCATION "${_IMPORT_PREFIX}/lib/{{ artifact_dll }}"
|
||||
)
|
||||
endif()
|
||||
|
||||
{# Cleanup temporary variables -#}
|
||||
set(_IMPORT_PREFIX)
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
{# Setup package version -#}
|
||||
set(PACKAGE_VERSION "1.2.3") # TODO: replace with jinja argument
|
||||
# This is a basic version file for the Config-mode of find_package().
|
||||
# It is created by sarasacw-omrf-packer and should not be changed manually.
|
||||
#
|
||||
# This file sets PACKAGE_VERSION_EXACT if the current version string and
|
||||
# the requested version string are exactly the same and it sets
|
||||
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version.
|
||||
|
||||
{# Check whether user request EXACT match -#}
|
||||
if(PACKAGE_FIND_VERSION_EXACT)
|
||||
if(NOT "${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
|
||||
set(PACKAGE_VERSION_UNSUPPORTED TRUE)
|
||||
endif()
|
||||
{# Setup package version -#}
|
||||
set(PACKAGE_VERSION "{{- version -}}")
|
||||
|
||||
{# Check package version (code are copied from CMake generation) -#}
|
||||
if (PACKAGE_FIND_VERSION_RANGE)
|
||||
# Package version must be in the requested version range
|
||||
if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN)
|
||||
OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX)
|
||||
OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX)))
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||
endif()
|
||||
else()
|
||||
{# Check whether user requested version is <= current version (compatible with new version) -#}
|
||||
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
|
||||
set(PACKAGE_VERSION_UNSUPPORTED TRUE)
|
||||
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
set(PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
|
||||
set(PACKAGE_VERSION_EXACT TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user