Skip to content
Snippets Groups Projects
Commit bea013a3 authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos
Browse files

Export all target [un]aliased and [un]scoped combinations

parent 7c88fd4a
No related branches found
No related tags found
1 merge request!1247Export targets under custom namespaces (Dune:: by default)
Pipeline #61744 canceled
......@@ -189,25 +189,25 @@ function(dune_add_library_normal _name)
"We recommend to choose an export name with a camel title case matching your library name "
"(e.g., Common, ISTL, and MultiDomainGrid will be exported as Dune::Common, Dune::ISTL, and Dune::MultiDomainGrid)\n"
" * Calls to `dune_add_library(<lib> ...)` without export specification will be supported until Dune 2.11\n"
" * Consumption of unscoped targets `<lib>` will be supported until Dune 2.12")
set(ARG_EXPORT_NAME ${_name})
set(ARG_EXPORT_NAME __dune_impl_${_name})
endif()
set(${ProjectName}_EXPORT_SET ${ProjectName}-targets CACHE INTERNAL "")
# Install targets to use the libraries in other modules.
add_library(Dune::${ARG_EXPORT_NAME} ALIAS ${_name})
set_target_properties(${_name} PROPERTIES EXPORT_NAME ${ARG_EXPORT_NAME})
install(TARGETS ${_name}
EXPORT ${ProjectName}-targets-scoped DESTINATION ${CMAKE_INSTALL_LIBDIR})
set(${ProjectName}_EXPORT_SET_SCOPED ${ProjectName}-targets-scoped CACHE INTERNAL "")
EXPORT ${${ProjectName}_EXPORT_SET} DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Install (unscoped) targets to use the libraries in other modules.
add_library(_dune_unscoped_${_name} INTERFACE)
target_link_libraries(_dune_unscoped_${_name} INTERFACE Dune::${ARG_EXPORT_NAME})
set_target_properties(_dune_unscoped_${_name} PROPERTIES EXPORT_NAME ${_name})
install(TARGETS _dune_unscoped_${_name}
EXPORT ${ProjectName}-targets-unscoped DESTINATION ${CMAKE_INSTALL_LIBDIR})
set(${ProjectName}_EXPORT_SET_UNSCOPED ${ProjectName}-targets-unscoped CACHE INTERNAL "")
# Install (unaliased) targets to use the libraries in other modules.
# NOTE: Remove when compatibility with 2.10 is not needed anymore (e.g., 2.13)
add_library(_dune_unaliased_${_name} INTERFACE)
target_link_libraries(_dune_unaliased_${_name} INTERFACE Dune::${ARG_EXPORT_NAME})
set_target_properties(_dune_unaliased_${_name} PROPERTIES EXPORT_NAME ${_name})
install(TARGETS _dune_unaliased_${_name}
EXPORT ${${ProjectName}_EXPORT_SET} DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Register target as an exported library
if(NOT ARG_NO_MODULE_LIBRARY)
......@@ -248,24 +248,26 @@ function(dune_add_library_interface _name)
"We recommend to choose an export name with a camel title case matching your library name "
"(e.g., Common, ISTL, and MultiDomainGrid will be exported as Dune::Common, Dune::ISTL, and Dune::MultiDomainGrid)\n"
" * Calls to `dune_add_library(<lib> ...)` without export specification will be supported until Dune 2.11\n"
" * Consumption of unscoped targets `<lib>` will be supported until Dune 2.12")
set(ARG_EXPORT_NAME ${_name})
set(ARG_EXPORT_NAME __dune_impl_${_name})
endif()
set(${ProjectName}_EXPORT_SET ${ProjectName}-targets CACHE INTERNAL "")
# Install targets to use the libraries in other modules.
add_library(Dune::${ARG_EXPORT_NAME} ALIAS ${_name})
set_target_properties(${_name} PROPERTIES EXPORT_NAME ${ARG_EXPORT_NAME})
install(TARGETS ${_name}
EXPORT ${ProjectName}-targets-scoped DESTINATION ${CMAKE_INSTALL_LIBDIR})
set(${ProjectName}_EXPORT_SET_SCOPED ${ProjectName}-targets-scoped CACHE INTERNAL "")
# Install (unscoped) targets to use the libraries in other modules.
add_library(_dune_unscoped_${_name} INTERFACE)
target_link_libraries(_dune_unscoped_${_name} INTERFACE Dune::${ARG_EXPORT_NAME})
set_target_properties(_dune_unscoped_${_name} PROPERTIES EXPORT_NAME ${_name})
install(TARGETS _dune_unscoped_${_name}
EXPORT ${ProjectName}-targets-unscoped DESTINATION ${CMAKE_INSTALL_LIBDIR})
set(${ProjectName}_EXPORT_SET_UNSCOPED ${ProjectName}-targets-unscoped CACHE INTERNAL "")
EXPORT ${${ProjectName}_EXPORT_SET} DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Install (unaliased) targets to use the libraries in other modules.
# NOTE: Remove when compatibility with 2.10 is not needed anymore (e.g., 2.13)
add_library(_dune_unaliased_${_name} INTERFACE)
target_link_libraries(_dune_unaliased_${_name} INTERFACE Dune::${ARG_EXPORT_NAME})
set_target_properties(_dune_unaliased_${_name} PROPERTIES EXPORT_NAME ${_name})
install(TARGETS _dune_unaliased_${_name}
EXPORT ${${ProjectName}_EXPORT_SET} DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Register target as an exported library
if(NOT ARG_NO_MODULE_LIBRARY)
......
......@@ -214,7 +214,7 @@ if(${ProjectName}_LIBRARIES)
include(\"\${_dir}/${ProjectName}-targets-scoped.cmake\")
include(\"\${_dir}/${ProjectName}-targets-unscoped.cmake\")
# Deprecation warning for unscoped targets
if((CMAKE_VERSION VERSION_GREATER_EQUAL \"3.19\") AND (DUNE_COMMON_VERSION VERSION_GREATER_EQUAL \"2.12\"))
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
@DUNE_DEPRECATED_LIBRARY_ALIASES@
endif()
endif()
......@@ -237,14 +237,18 @@ endif()")
set(DUNE_INSTALL_LIBDIR ${DUNE_INSTALL_NONOBJECTLIBDIR})
endif()
# setup deprecated aliases
foreach(_export_name ${${ProjectName}_INTERFACE_LIBRARIES})
get_target_property(_aliased_name ${_export_name} ALIASED_TARGET)
set(DUNE_DEPRECATED_LIBRARY_ALIASES
# add deprecated property for unaliased targets
if(${ProjectVersionString} VERSION_GREATER_EQUAL 2.11)
foreach(_interface_name ${${ProjectName}_INTERFACE_LIBRARIES})
get_target_property(_unaliased_name ${_interface_name} ALIASED_TARGET)
get_target_property(_export_unaliased_name ${_unaliased_name} EXPORT_NAME)
set(DUNE_DEPRECATED_LIBRARY_ALIASES
"${DUNE_DEPRECATED_LIBRARY_ALIASES}
set_property(TARGET ${_aliased_name} PROPERTY DEPRECATION \"Replace `${_aliased_name}` to new scoped `${_export_name}` targets.\")
")
endforeach()
set_property(TARGET ${_unaliased_name} PROPERTY DEPRECATION \"Replace `${_unaliased_name}` to new scoped `${_interface_name}` targets.\")
set_property(TARGET ${_export_unaliased_name} PROPERTY DEPRECATION \"Replace `${_export_unaliased_name}` to new scoped `${_interface_name}` targets.\")"
)
endforeach()
endif()
# Set the location of the doc file source. Needed by custom package configuration
# file section of dune-grid.
......@@ -322,27 +326,26 @@ endif()
# install pkg-config files
create_and_install_pkconfig(${DUNE_INSTALL_LIBDIR})
if(${ProjectName}_EXPORT_SET_SCOPED)
if(${ProjectName}_EXPORT_SET)
# install library export set
install(EXPORT ${${ProjectName}_EXPORT_SET_SCOPED}
install(EXPORT ${${ProjectName}_EXPORT_SET}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${ProjectName}
NAMESPACE Dune::
FILE ${ProjectName}-targets-scoped.cmake)
# export libraries for use in build tree
export(EXPORT ${${ProjectName}_EXPORT_SET_SCOPED}
export(EXPORT ${${ProjectName}_EXPORT_SET}
FILE ${PROJECT_BINARY_DIR}/${ProjectName}-targets-scoped.cmake
NAMESPACE Dune::)
endif()
if(${ProjectName}_EXPORT_SET_UNSCOPED)
# install library export set
install(EXPORT ${${ProjectName}_EXPORT_SET_UNSCOPED}
# NOTE: Remove when compatibility with 2.10 is not needed anymore (e.g., 2.13)
# install (unscoped) library export set
install(EXPORT ${${ProjectName}_EXPORT_SET}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${ProjectName}
FILE ${ProjectName}-targets-unscoped.cmake)
# export libraries for use in build tree
export(EXPORT ${${ProjectName}_EXPORT_SET_UNSCOPED}
# export (unscoped) libraries for use in build tree
export(EXPORT ${${ProjectName}_EXPORT_SET}
FILE ${PROJECT_BINARY_DIR}/${ProjectName}-targets-unscoped.cmake)
endif()
......
......@@ -26,7 +26,7 @@ set(@DUNE_MOD_NAME@_SUGGESTS "@DUNE_SUGGESTS@")
set(@DUNE_MOD_NAME@_HASPYTHON 1)
set(@DUNE_MOD_NAME@_PYTHONREQUIRES "@DUNE_MODULE_PYTHONREQUIRES@")
set_and_check(@DUNE_MOD_NAME@_MODULE_PATH "@PACKAGE_DUNE_INSTALL_MODULEDIR@")
if((CMAKE_VERSION VERSION_GREATER_EQUAL 3.19) AND (DUNE_COMMON_VERSION VERSION_GREATER_EQUAL 2.12))
if((CMAKE_VERSION VERSION_GREATER_EQUAL 3.19) AND (@ProjectVersionString@ VERSION_GREATER_EQUAL 2.11))
set_property(TARGET dunecommon PROPERTY DEPRECATION "Replace `dunecommon` to new scoped `Dune::Common` targets.")
endif()
endif(NOT @DUNE_MOD_NAME@_FOUND)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment