I never used it in my configuration files and never encountered any issues. What I read about this placeholder did not help me to understand it’s actual purpose (and why I survived so far without it).
Can someone provide me with an explanation of its purpose and/or a use case where it is mandatory?
If @PACKAGE_INIT@ is in your .config.in template, when generating the corresponding .config file it will be replaced with:
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was foo-config.cmake.in ########
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
macro(set_and_check _var _file)
set(${_var} "${_file}")
if(NOT EXISTS "${_file}")
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
endif()
endmacro()
macro(check_required_components _NAME)
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(NOT ${_NAME}_${comp}_FOUND)
if(${_NAME}_FIND_REQUIRED_${comp})
set(${_NAME}_FOUND FALSE)
endif()
endif()
endforeach()
endmacro()
####################################################################################
That’s all there is to it. It’s never mandatory, but if you include it then you can use the set_and_check and check_required_components macros in your config code, as well as the PACKAGE_PREFIX_DIR variable. If you don’t need to use those, then you don’t need @PACKAGE_INIT@.
(However, setting file locations with set_and_check() instead of regular set(), in particular, is a good idea to ensure that you aren’t referencing any missing files in your config variables.)