Skip to content

How do I override CMAKE_INSTALL_PREFIX per-package in CPMAddPackage? #667

@romain-noel

Description

@romain-noel

My question is probably very stupid or already answered but I found nothing about it.

I’m would like to fetch several third-party libraries with CPM and install each one into its own directory. For example, I’d like to bring in cxxopts and have it install to /hereA/, and then bring in packageB and have it install to /hereB/ directory.

So I tried:

CPMAddPackage(
  NAME        cxxopts
  GITHUB_REPOSITORY jarro2783/cxxopts
  VERSION     3.0.0
  
  OPTIONS
   # turn off tests/examples and enable its install logic
    "CXXOPTS_BUILD_EXAMPLES=Off"
    "CXXOPTS_BUILD_TESTS=Off"
    "CXXOPTS_ENABLE_INSTALL=ON"
  # attempt to override the install prefix for this subpackage
    "CMAKE_INSTALL_PREFIX=/hereA/"
)

After running cmake --build . and then cmake --install ., I still get cxxopts installed into the top-level CMAKE_INSTALL_PREFIX, not /hereA/.
If I instead run:

cmake --install . --prefix /hereA/

then it works—but that override is global and I can’t use it to give another packageB its own separate install directory.
Thus:

  • Why does the OPTIONS "CMAKE_INSTALL_PREFIX=/hereA/" not actually take effect for the sub-project?

  • How can I specify a different install location for each CPM-fetched package, without relying on the cmake --install --prefix … command?

Thank you for any pointers or examples!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions