Proposition to modify `slicer_config_set_ep` macro to work with `LIST` vars

Hi,

In SlicerConfig.cmake.in there is a macro called slicer_config_set_ep.
Current implementation assumes that the variable is represented as a STRING.
And if the variable is a LIST then cmake configure may fail. For example in my case I have some libs that I link as I dependencies:

slicer_config_set_ep(
  SOME_LIB_DEPS
  "/home/lib_0.so;/home/lib_1.so;/home/lib_2.so"
  CACHE STRING "Path to project build directory or file" FORCE)

Then when I try to configure and build some external module I need to find_package(Slicer REQUIRED).
Configuring my module for the first time works fine, but when I try to reconfigure then I get error yelding that unknown property… In brief cmake tries to retrieve REALPATH property from that "/home/lib_0.so;/home/lib_1.so;/home/lib_2.so"

To avoid that I propose to modify this macro in the following manner:

macro(slicer_config_set_ep var values)
  if(NOT "${values}" STREQUAL "")
    if(DEFINED ${var})
      get_filename_component(var_realpath "${${var}}" REALPATH)
	  foreach(value ${values})
		get_filename_component(val_realpath ${value} REALPATH)
		if (NOT ${val_realpath} IN_LIST var_realpath)
			message(FATAL_ERROR "Variable ${var} defined prior calling 'find_package(Slicer)' does NOT "
					"match value used to configure Slicer. It probably means that a different "
					"${var} has been used to configure this project and Slicer.\n"
					"${var}=${${var}}\n"
					"Slicer_${var}=${value}")
		endif()
	  endforeach()
    endif()
    set(${var} "${values}" ${ARGN})
  endif()
endmacro()

Thus I assume that the variable is a LIST and I check if list contains some each path.

How do you think?
I tested this modified version and for me it works

I could not really follow what your problem and solution was, but CMake does not have a LIST type for cache entries, so we use a the EP_LIST_SEPARATOR (this special string: ^^) to separate list items in a string.

1 Like

I think that is the truth but we can consider STRING with semicolon delimited values as a LIST I think.
EP_LIST_SEPARATOR I didn’t tested it but from ExternalProjectDependency.cmake I can see that it works only with _COMMAND options:

#.rst:
# .. cmake:variable:: EP_LIST_SEPARATOR
#
# This variable is used to separate list items when passed in various external project
# ``..._COMMAND`` options.
#
# If defaults to ``^^``.
if(NOT DEFINED EP_LIST_SEPARATOR)
  set(EP_LIST_SEPARATOR "^^")
endif()

I’ve recorded a small video where I’m trying to explain the problem and uploaded it on google drive. Please take a look

@jcfr what do you think?