Skip to content

Commit

Permalink
Redirect gz_find_package and ticktock gz_import_target targets (#273)
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <[email protected]>
  • Loading branch information
methylDragon committed Jul 9, 2022
1 parent 9e7cf73 commit 77e83d2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
26 changes: 24 additions & 2 deletions cmake/IgnImportTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

#------------------------------------
Expand All @@ -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
Expand Down
35 changes: 33 additions & 2 deletions cmake/IgnUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 77e83d2

Please sign in to comment.