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

Add ignition- deprecations and aliases, and gz- redirect #239

Closed
wants to merge 9 commits into from
38 changes: 36 additions & 2 deletions cmake/Export.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,46 @@
#endif


#ifndef IGN_DEPRECATED
#ifndef GZ_DEPRECATED
/// For @lib_name@ developers: Use this macro to indicate that a
/// function or class has been deprecated and should no longer be used. A
/// version should be specified to provide context to the user about when the
/// function became deprecated.
#define IGN_DEPRECATED(version) IGN_DEPRECATED_ALL_VERSIONS

// NOTE(CH3): GZ_DEPRECATED_ALL_VERSIONS can't be ticktocked, it's generated
// On the bright side, it seems to be private
#define GZ_DEPRECATED(version) GZ_DEPRECATED_ALL_VERSIONS
#endif


// TICKTOCK IGNITION ========================================================
// TODO(CH3): Remove on ticktock, supports defining IGNITION macros if we're
// a lib is using GZ_ prefixed export macros
#ifndef @_ign_export_base@_VISIBLE
/// For @lib_name@ developers: Apply this macro to @lib_name@
/// functions and classes which consumers of this library will need to be able
/// to call from their own programs or libraries.
#define @_ign_export_base@_VISIBLE \
DETAIL_@export_base@_VISIBLE
#endif


#ifndef @_ign_export_base@_HIDDEN
/// For @lib_name@ developers: Apply this macro to @lib_name@
/// functions and classes which must not be used by consumers of this library.
/// By default, this property is applied to all classes and functions which are
/// not tagged with @_ign_export_base@_VISIBLE, so this does not
/// generally need to be used.
#define @_ign_export_base@_HIDDEN \
DETAIL_@export_base@_HIDDEN
#endif


#ifndef IGN_DEPRECATED
// TODO(CH3): Remove on ticktock
// NOTE(CH3): This has no docstring since we'll make GZ_DEPRECATED the default
#define IGN_DEPRECATED(version) GZ_DEPRECATED_ALL_VERSIONS
#endif


#endif // @export_base@_EXPORT_HH_
1 change: 1 addition & 0 deletions cmake/IgnConfigureProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ macro(ign_configure_project)
set(PROJECT_VERSION_FULL
${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})


# The full version of the project, but without any prerelease suffix
set(PROJECT_VERSION_FULL_NO_SUFFIX ${PROJECT_VERSION_FULL})

Expand Down
162 changes: 151 additions & 11 deletions cmake/IgnUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@
# is provided using VERSION, then this will be left
# out, whether or not it is provided.
#
macro(ign_find_package PACKAGE_NAME)
macro(ign_find_package MACRO_PACKAGE_NAME)
# This is to allow "remapping" of the macro arg for function-like capability, but also access to
# the parent scope
# TODO(CH3): Remove this on tock, along the later sections,
# and change MACRO_PACKAGE_NAME back to PACKAGE_NAME
set(PACKAGE_NAME ${MACRO_PACKAGE_NAME})

#------------------------------------
# Define the expected arguments
Expand All @@ -150,6 +155,77 @@ macro(ign_find_package PACKAGE_NAME)
# Parse the arguments
_ign_cmake_parse_arguments(gz_find_package "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

#------------------------------------
# Handle ticktock
# TODO(CH3): Remove on tock
if(${PACKAGE_NAME} MATCHES "^ignition-")
message(DEPRECATION
"\nThe use of 'ign-' and 'ignition-' prefixed libraries has been "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has find_package(ign-*) ever worked? I thought we always had to spell it out as 1ignition-*. If that is the case, I would simplify this to only cover the case of ignition-` to avoid confusion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"deprecated in favor of 'gz-' and will be removed in the next version!\n"
)
set(GZ_PACKAGE_NAME ${PACKAGE_NAME})

string(REGEX REPLACE "^ign(ition)?-" "gz-" GZ_PACKAGE_NAME ${PACKAGE_NAME})
message(NOTICE "...Trying to use the gz- version of the library you specified: '${GZ_PACKAGE_NAME}'\n")

#------------------------------------
# Construct the arguments to pass to find_package
# The duplication is necessary for the ticktock...
# TODO(CH3): Remove on tock
set(gz_find_package_args ${GZ_PACKAGE_NAME})

if(ign_find_package_VERSION)
list(APPEND gz_find_package_args ${ign_find_package_VERSION})
endif()

if(ign_find_package_QUIET)
list(APPEND gz_find_package_args QUIET)
endif()

if(ign_find_package_EXACT)
list(APPEND gz_find_package_args EXACT)
endif()

if(ign_find_package_CONFIG)
list(APPEND gz_find_package_args CONFIG)
endif()

if(ign_find_package_COMPONENTS)
list(APPEND gz_find_package_args COMPONENTS ${ign_find_package_COMPONENTS})
endif()

if(ign_find_package_OPTIONAL_COMPONENTS)
list(APPEND gz_find_package_args OPTIONAL_COMPONENTS ${ign_find_package_OPTIONAL_COMPONENTS})
endif()

if(ign_find_package_EXTRA_ARGS)
list(APPEND gz_find_package_args ${ign_find_package_EXTRA_ARGS})
endif()

find_package(${gz_find_package_args} QUIET)

if(${GZ_PACKAGE_NAME}_FOUND)
message(NOTICE "Found! Using it instead of '${PACKAGE_NAME_BAK}'")

# Manually set ignition- prefix version numbers for ticktock
# TODO(CH3): Remove on tock
set(${PACKAGE_NAME}_VERSION ${${GZ_PACKAGE_NAME}_VERSION})
set(${PACKAGE_NAME}_VERSION_MAJOR ${${GZ_PACKAGE_NAME}_VERSION_MAJOR})
set(${PACKAGE_NAME}_VERSION_MINOR ${${GZ_PACKAGE_NAME}_VERSION_MINOR})
set(${PACKAGE_NAME}_VERSION_PATCH ${${GZ_PACKAGE_NAME}_VERSION_PATCH})
set(${PACKAGE_NAME}_VERSION_TWEAK ${${GZ_PACKAGE_NAME}_VERSION_TWEAK})

else()
message(WARNING
"\n'${GZ_PACKAGE_NAME}' not found! Falling back to '${PACKAGE_NAME}'...\n"
"== NOTE ==\n"
"gz- library finding will sometimes deterministically fail because the dynamic substitution "
"doesn't get picked up by colcon-cmake.\n"
"To avoid these failures, substitute your 'ign(ition)-' prefixes with 'gz-' in your CMake "
"files, or call `colcon build --executor sequential` instead!\n")
endif()
endif()

#------------------------------------
# Construct the arguments to pass to find_package
set(${PACKAGE_NAME}_find_package_args ${PACKAGE_NAME})
Expand Down Expand Up @@ -309,7 +385,7 @@ macro(ign_find_package PACKAGE_NAME)

# TODO: When we migrate to cmake-3.9+ bring back find_dependency(~) because
# at that point it will be able to support COMPONENTS and EXTRA_ARGS
# set(${PACKAGE_NAME}_find_dependency "find_dependency(${${PACKAGE_NAME}_dependency_args})")
# set(${PACKAGE_NAME}_find_dependency "find_dependency(${${PACKAGE_NAME}_dependency_args})")

set(${PACKAGE_NAME}_find_dependency "find_package(${${PACKAGE_NAME}_dependency_args})")

Expand Down Expand Up @@ -952,12 +1028,58 @@ function(ign_create_core_library)

#------------------------------------
# Create the target for the core library, and configure it to be installed
_ign_add_library_or_component(
LIB_NAME ${PROJECT_LIBRARY_TARGET_NAME}
INCLUDE_DIR "${PROJECT_INCLUDE_DIR}"
EXPORT_BASE IGNITION_${IGN_DESIGNATION_UPPER}
SOURCES ${sources}
${interface_option})

# Support "gz-"
if(${PROJECT_LIBRARY_TARGET_NAME} MATCHES "^gz-")
_ign_add_library_or_component(
LIB_NAME ${PROJECT_LIBRARY_TARGET_NAME}
INCLUDE_DIR "${PROJECT_INCLUDE_DIR}"
EXPORT_BASE GZ_${IGN_DESIGNATION_UPPER}
SOURCES ${sources}
${interface_option})

# For ticktocking: Export an "ignition-" target as well, allowing linking against
# the ignition- prefixed name
# TODO(CH3): To remove on tock
string(REGEX REPLACE "^gz-" "ignition-" IGN_LIBRARY_TARGET_NAME ${PROJECT_LIBRARY_TARGET_NAME})
_ign_add_library_or_component(
LIB_NAME ${IGN_LIBRARY_TARGET_NAME}
INCLUDE_DIR "${PROJECT_INCLUDE_DIR}"

# Using GZ_ is deliberate, Export.hh.in has logic to deal with this
EXPORT_BASE GZ_${IGN_DESIGNATION_UPPER}
SOURCES ${sources}
${interface_option})

target_include_directories(${IGN_LIBRARY_TARGET_NAME}
${property_type}
# This is the publicly installed headers directory.
"$<INSTALL_INTERFACE:${IGN_INCLUDE_INSTALL_DIR_FULL}>"
# This is the in-build version of the core library headers directory.
# Generated headers for the core library get placed here.
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>"
# Generated headers for the core library might also get placed here.
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/core/include>")

#------------------------------------
# Handle cmake and pkgconfig packaging
# TODO(CH3): Remove on tock
string(REGEX REPLACE "^gz-" "ignition-" IGN_PROJECT_NAME_LOWER ${PROJECT_NAME_LOWER})

if(ign_create_core_library_INTERFACE)
set(project_pkgconfig_core_lib) # Intentionally blank
else()
set(project_pkgconfig_core_lib "-l${IGN_PROJECT_NAME_LOWER}")
endif()

else()
_ign_add_library_or_component(
LIB_NAME ${PROJECT_LIBRARY_TARGET_NAME}
INCLUDE_DIR "${PROJECT_INCLUDE_DIR}"
EXPORT_BASE GZ_${IGN_DESIGNATION_UPPER}
SOURCES ${sources}
${interface_option})
endif()

# These generator expressions are necessary for multi-configuration generators
# such as MSVC on Windows. They also ensure that our target exports its
Expand Down Expand Up @@ -1006,7 +1128,9 @@ function(ign_create_core_library)
if(gz_create_core_library_INTERFACE)
set(project_pkgconfig_core_lib) # Intentionally blank
else()
set(project_pkgconfig_core_lib "-l${PROJECT_NAME_LOWER}")
# We append here so the project target can live alongside the ignition- alias
# TODO(CH3): Change back to set() on tock and remove the set() in the other TODO above
ign_string_append(project_pkgconfig_core_lib "-l${PROJECT_NAME_LOWER}")
endif()

# Export and install the core library's cmake target and package information
Expand Down Expand Up @@ -1136,10 +1260,18 @@ function(ign_add_component component_name)

#------------------------------------
# Create the target for this component, and configure it to be installed

# Support "gz-"
if(${PROJECT_LIBRARY_TARGET_NAME} MATCHES "^gz-")
set(EXPORT_PREFIX "GZ")
else()
set(EXPORT_PREFIX "IGNITION")
endif()

_ign_add_library_or_component(
LIB_NAME ${component_target_name}
INCLUDE_DIR "${PROJECT_INCLUDE_DIR}/${include_subdir}"
EXPORT_BASE IGNITION_${IGN_DESIGNATION_UPPER}_${component_name_upper}
EXPORT_BASE GZ_${IGN_DESIGNATION_UPPER}_${component_name_upper}
SOURCES ${sources}
${interface_option})

Expand Down Expand Up @@ -1339,6 +1471,8 @@ macro(_ign_add_library_or_component)
# - include_dir
# - export_base
# - lib_name
#
# - _ign_export_base

#------------------------------------
# Define the expected arguments
Expand Down Expand Up @@ -1424,7 +1558,7 @@ macro(_ign_add_library_or_component)
EXPORT_FILE_NAME ${implementation_file_name}
EXPORT_MACRO_NAME DETAIL_${export_base}_VISIBLE
NO_EXPORT_MACRO_NAME DETAIL_${export_base}_HIDDEN
DEPRECATED_MACRO_NAME IGN_DEPRECATED_ALL_VERSIONS)
DEPRECATED_MACRO_NAME GZ_DEPRECATED_ALL_VERSIONS)

set(install_include_dir
"${IGN_INCLUDE_INSTALL_DIR_FULL}/${include_dir}")
Expand All @@ -1438,6 +1572,12 @@ macro(_ign_add_library_or_component)
# Configure the public-facing header for exporting and deprecating. This
# header provides commentary for the macros so that developers can know their
# purpose.

# TODO(CH3): Remove this on ticktock
# This is to allow IGNITION_ prefixed export macros to generate in Export.hh
# _using_gz_export_base is used in Export.hh.in's configuration!
string(REGEX REPLACE "^GZ_" "IGNITION_" _ign_export_base ${export_base})

configure_file(
"${IGNITION_CMAKE_DIR}/Export.hh.in"
"${binary_include_dir}/Export.hh")
Expand Down
59 changes: 59 additions & 0 deletions cmake/ignition-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ endif()

@PACKAGE_INIT@

# Add 'ignition-' prefixed package name if package is 'gz-' prefixed
# TODO(CH3): Remove on tock
if(@PKG_NAME@ MATCHES "^gz-")
string(REGEX REPLACE "^gz-" "ignition-" IGN_PKG_NAME @PKG_NAME@)
endif()

if(NOT TARGET @import_target_name@)
include("${CMAKE_CURRENT_LIST_DIR}/@target_output_filename@")

Expand All @@ -102,6 +108,16 @@ if(NOT TARGET @import_target_name@)
add_library(@simple_import_name@ INTERFACE IMPORTED)
set_target_properties(@simple_import_name@ PROPERTIES
INTERFACE_LINK_LIBRARIES @import_target_name@)

# Add 'ignition-' prefixed "alias" for the core library
# TODO(CH3): Remove on tock
if(IGN_PKG_NAME)
string(REGEX REPLACE "^gz-" "ignition-" ign_simple_import_name @simple_import_name@)
add_library(${ign_simple_import_name} INTERFACE IMPORTED)
set_target_properties(${ign_simple_import_name} PROPERTIES
INTERFACE_LINK_LIBRARIES @import_target_name@)
endif()

# Note: In a future version of cmake, we can replace this with an ALIAS target

# In case someone tries to link against the plain library name, we want to
Expand All @@ -112,11 +128,30 @@ if(NOT TARGET @import_target_name@)
set_target_properties(@PKG_NAME@ PROPERTIES
INTERFACE_LINK_LIBRARIES @import_target_name@)

# Add 'ignition-' prefixed "alias"
# TODO(CH3): Remove on tock
if(IGN_PKG_NAME)
add_library(${IGN_PKG_NAME} INTERFACE IMPORTED)
set_target_properties(${IGN_PKG_NAME} PROPERTIES
INTERFACE_LINK_LIBRARIES @import_target_name@)
endif()

endif()

# TODO(CH3): Remove on tock
if(IGN_PKG_NAME)
# This is a really bad name...
string(REGEX REPLACE "^gz-" "ignition-" ign_ign_namespace @ign_namespace@)
endif()

# Create the "all" target if it does not already exist
if(NOT TARGET @ign_namespace@requested)
add_library(@ign_namespace@requested INTERFACE IMPORTED)

# TODO(CH3): Remove on tock
if(IGN_PKG_NAME)
add_library(${ign_ign_namespace}requested INTERFACE IMPORTED)
endif()
endif()

# Link the core library to the "all" target. We set the property explicitly
Expand All @@ -128,17 +163,41 @@ if(NOT ign_all_components)
# should NOT pass into the INTERFACE_LINK_LIBRARIES property.
set_target_properties(@ign_namespace@requested PROPERTIES
INTERFACE_LINK_LIBRARIES "@import_target_name@")

# TODO(CH3): Remove on tock
if(IGN_PKG_NAME)
# This is a really bad name...
set_target_properties(${ign_ign_namespace}requested PROPERTIES
INTERFACE_LINK_LIBRARIES "@import_target_name@")
endif()
else()
set_target_properties(@ign_namespace@requested PROPERTIES
INTERFACE_LINK_LIBRARIES "${ign_all_components};@import_target_name@")

# TODO(CH3): Remove on tock
if(IGN_PKG_NAME)
# This is a really bad name...
set_target_properties(${ign_ign_namespace}requested PROPERTIES
INTERFACE_LINK_LIBRARIES "${ign_all_components};@import_target_name@")
endif()
endif()

# Package variables. Note that @PKG_NAME@_LIBRARIES and @PKG_NAME@_CORE_LIBRARY
# contain imported targets, so @PKG_NAME@_INCLUDE_DIRS is never needed.
set(@PKG_NAME@_CORE_LIBRARY @simple_import_name@)
set(@PKG_NAME@_LIBRARIES @ign_namespace@requested)

set_and_check(@PKG_NAME@_INCLUDE_DIRS "@PACKAGE_IGN_INCLUDE_INSTALL_DIR_FULL@")

# Add ignition- prefixed package variables and include directories pointing to the gz- headers
# TODO(CH3): Remove on tock
if(IGN_PKG_NAME)
set(${IGN_PKG_NAME}_CORE_LIBRARY @simple_import_name@)
set(${IGN_PKG_NAME}_LIBRARIES @ign_namespace@requested)

set_and_check(${IGN_PKG_NAME}_INCLUDE_DIRS "@PACKAGE_IGN_INCLUDE_INSTALL_DIR_FULL@")
endif()

# Backwards compatibility variables
set(@LEGACY_PROJECT_PREFIX@_LIBRARIES ${@PKG_NAME@_LIBRARIES})
set(@LEGACY_PROJECT_PREFIX@_INCLUDE_DIRS ${@PKG_NAME@_INCLUDE_DIRS})
Expand Down
Loading