2

I am using cmake's PackageConfigHelpers'

configure_package_config_file(
        Config.cmake.in"
        "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
        INSTALL_DESTINATION
        ....
        PATH_VARS
        my_paths
)

If my_path were to consist of multiple paths, such as:

set(my_paths path1 path2)

the config file will end up prefixing only path1 and I will end up with:

${PACKAGE_PREFIX_DIR}path1;path2.

which results into path2 not being locatable. Is there any way of fixing this while still using the function provided by PackageConfigHelpers?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Maths noob
  • 1,684
  • 20
  • 42

1 Answers1

0

Each path should be assigned to its own variable, and these variables should be enumarated for PATH_VARS option:

set(path1_var <...> CACHE ...)
set(path2_var <...> CACHE ...)

configure_package_config_file(
    "Config.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
    INSTALL_DESTINATION
    ....
    PATH_VARS
    path1_var
    path2_var
)

Each variable should be used in Config.cmake.in for specific type of deliverables.

From the documentation for configure_package_config_file:

The variables <var1> to <varN> given as PATH_VARS are the variables which contain install destinations. For each of them the macro will create a helper variable PACKAGE_<var...>. These helper variables must be used in the FooConfig.cmake.in file for setting the installed location. They are calculated by CONFIGURE_PACKAGE_CONFIG_FILE() so that they are always relative to the installed location of the package.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Yeah that's true, but that's not practical in my case. I asked of the possible ways of achieving this while still using this module. I guess I should use them as variables and add the prefix manually. My only concern is, if the prefix is always or if it can be more complicated. – Maths noob May 14 '16 at 11:54
  • `configure_package_config_file` is intended for **relocatable** package, so every its deliberable is installed under ``. If you want some paths to be outside of that prefix, just don't list them in `PATH_VARS` option. – Tsyvarev May 14 '16 at 12:06
  • The paths are subpaths of that dir. The problem is that I am trying to write a template and don't want to have to explicitly feed path1, path2, etc. as inputs to the function, which is the intention behind `my_paths`. I guess what I should do instead of passing the paths as PATH_VARS, I should write them to the config file as a single variable: `my_paths_var` and construct the paths inside config file. That would achieve my goal. – Maths noob May 15 '16 at 00:46
  • @Tsyvarev Do PATH1_var etc. have to be CACHE variables for configure_package_config_file to relocate them? (it might explain https://stackoverflow.com/q/56189739/1569204 if so) – Bruce Adams May 20 '19 at 16:19
  • The path variables are declared as `CACHE` only for allow the user of your project to redefine them. E.g. set library subdirectory to be `lib64/` instead of default `lib/`. If you don't want such functionality, you may omit `CACHE` part. Behavior of macro `configure_package_config_file` isn't affected by the nature of variables. – Tsyvarev May 20 '19 at 16:45