cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dependencies of dependencies and setting of compile-time options?

ethindp opened this issue · comments

Hi there,

I'd like to add the hpx library as well as llvm using this project. However, hpx needs the hwloc library dependency; how is this handled? And if I want to set options for a project (e.g. LLVM), do I just use the normal -DLLVM_* configuration/set(LLVM_*...) method?

Hi, so this is more a Cmake specific concern but is very relevant to CPM I think.

Options

-DKEY=VALUE

This will work from the cmake commandline if you need user-specific options define globally in the build i.e. Requires that developers know to set your option

CMakePresets.json (Since CMake 3.19)

This is a significant improvement in CMake option management, the .json file allows you to predefine a load of options globally with ease for other devs
https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html

CPMAddPackage( ... OPTIONS "KEY VALUE" ... )

When you use CPM to add a package via CPMAddPackage you can provide the OPTIONS arguments for per package options. For examples here https://github.com/cpm-cmake/CPM.cmake#cxxopts

find_package

find_package( PACKAGE ...) is CMakes defacto method for finding dependent packages. HPX in this cases provides its own Find-Module which you may override by providing your-own one first! (See https://github.com/STEllAR-GROUP/hpx/blob/6b6e1e71343e80ad04bf610e41c26a41c1f37333/cmake/FindHwloc.cmake#L11)

Provide your custom FindPACKAGE.cmake in your CMAKE_MODULE_PATH

You may 'intercept' the find from the dependent packages by setting the module-path (list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") )and defining your own Find{package}.cmake into which you can put your CPMAddPackage(....). See https://cmake.org/cmake/help/book/mastering-cmake/chapter/Finding%20Packages.html

Use the CPM generated FindPACKAGE.cmake in {build_folder}/CPM_Modules/

CPM creates a find-module and adds the module-path automatically when you have added a package. You will see this inside the CPM_Modules folder inside your build. Knowing this, you may explicitly CPMAddPackage(hwloc...) ahead of adding other packages. Then all subsequent find_package(hwloc) calls will use your CPM selected package with the options you provided to it. NOTE; That some packages use a mix of older-cmake syntax so you may need a custom find module to setup some necessary variables e.g. Calling ${CMAKE_ROOT}/Modules/FindBoost.cmake will configure lots of package specific variables that would not be set for the CPM provided find-module.

Dependency-Provider (CMake 2.24)

The Latest-and-greatest approach lets you intercept find_package calls globally. You can try this out if you know you don't need to support developers on older CMake.
https://cmake.org/cmake/help/latest/command/cmake_language.html#provider-examples