From 40755afe6ff7ce95ff326546c2211a2601f613bb Mon Sep 17 00:00:00 2001 From: methylDragon Date: Fri, 8 Jul 2022 19:10:17 -0700 Subject: [PATCH] Redirect gz_find_package and ticktock gz_import_target targets (#273) Signed-off-by: methylDragon --- cmake/IgnImportTarget.cmake | 26 ++++++++++++++++++++++++-- cmake/IgnUtils.cmake | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/cmake/IgnImportTarget.cmake b/cmake/IgnImportTarget.cmake index 3ebe2a0e..581669cd 100644 --- a/cmake/IgnImportTarget.cmake +++ b/cmake/IgnImportTarget.cmake @@ -78,6 +78,10 @@ macro(gz_import_target package) set(target_name ${package}::${package}) endif() + if(${target_name} MATCHES "^Ign[^:]*::Ign") + message(DEPRECATION "Ign prefixed ${target_name} is deprecated (e.g. IgnOGRE::IgnOGRE)! Please use Gz prefix instead (e.g. GzOGRE::GzOGRE)") + endif() + if(NOT TARGET ${target_name}) #------------------------------------ @@ -101,9 +105,27 @@ macro(gz_import_target package) # against the variable package_LIBRARIES with the old-fashioned # target_link_libraries(mytarget ${package_LIBRARIES} if(NOT gz_import_target_INTERFACE) - add_library(${target_name} UNKNOWN IMPORTED) + # TODO(CH3): Remove Global upon deprecation. Remove it on hard-tock. + # It's needed to let the alias work! + add_library(${target_name} UNKNOWN IMPORTED GLOBAL) + + # TODO(CH3): Deprecated. Remove on tock. + if(${target_name} MATCHES "^Gz[^:]*::Gz") + string(REGEX REPLACE "^Gz" "Ign" alias_name ${target_name}) + string(REGEX REPLACE "::Gz" "::Ign" alias_name ${alias_name}) + add_library(${alias_name} ALIAS ${target_name}) + endif() else() - add_library(${target_name} INTERFACE IMPORTED) + # TODO(CH3): Remove Global upon deprecation. Remove it on hard-tock. + # It's needed to let the alias work! + add_library(${target_name} INTERFACE IMPORTED GLOBAL) + + # TODO(CH3): Deprecated. Remove on tock. + if(${target_name} MATCHES "^Gz[^:]*::Gz") + string(REGEX REPLACE "^Gz" "Ign" alias_name ${target_name}) + string(REGEX REPLACE "::Gz" "::Ign" alias_name ${alias_name}) + add_library(${alias_name} ALIAS ${target_name}) + endif() endif() # Do not bother with the IMPORTED_LOCATION or IMPORTED_IMPLIB variables if it diff --git a/cmake/IgnUtils.cmake b/cmake/IgnUtils.cmake index adf397f4..798fa95a 100644 --- a/cmake/IgnUtils.cmake +++ b/cmake/IgnUtils.cmake @@ -150,7 +150,8 @@ macro(ign_find_package PACKAGE_NAME) set(gz_find_package_skip_parsing true) gz_find_package(${PACKAGE_NAME}) endmacro() -macro(gz_find_package PACKAGE_NAME) +macro(gz_find_package PACKAGE_NAME_) + set(PACKAGE_NAME ${PACKAGE_NAME_}) # Allow for variable rebinds # Deprecated, remove skip parsing logic in version 4 if (NOT gz_find_package_skip_parsing) @@ -209,7 +210,37 @@ macro(gz_find_package PACKAGE_NAME) #------------------------------------ # Call find_package with the provided arguments - find_package(${${PACKAGE_NAME}_find_package_args}) + + # TODO(CH3): Deprecated. Remove on tock. + if(${PACKAGE_NAME} MATCHES "^Ign") + + # Deliberately use QUIET since we expect Ign to fail + find_package(${${PACKAGE_NAME}_find_package_args} QUIET) + + if(NOT ${PACKAGE_NAME}_FOUND) + # Try Gz prepended version instead! + string(REGEX REPLACE "^Ign(ition)?" "Gz" PACKAGE_NAME_GZ ${PACKAGE_NAME}) + + set(${PACKAGE_NAME_GZ}_find_package_args ${${PACKAGE_NAME}_find_package_args}) + list(POP_FRONT ${PACKAGE_NAME_GZ}_find_package_args) + list(PREPEND ${PACKAGE_NAME_GZ}_find_package_args ${PACKAGE_NAME_GZ}) + + find_package(${${PACKAGE_NAME_GZ}_find_package_args}) + if(${PACKAGE_NAME_GZ}_FOUND) + + message(DEPRECATION "Ign prefixed package name [${PACKAGE_NAME}] is deprecated! Automatically using the Gz prefix instead: [${PACKAGE_NAME_GZ}]") + set(PACKAGE_NAME ${PACKAGE_NAME_GZ}) + + endif() + + endif() + else() + + # TODO(CH3): On removal of tock, unindent this and just have this line!! + find_package(${${PACKAGE_NAME}_find_package_args}) + + endif() + if(${PACKAGE_NAME}_FOUND)