Dependencies of dependencies and setting of compile-time options?
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
So, reopening this because it weirdly isn't working on this one project.
If I have OpenAL, ogg, flac, vorbis, and opus, and I add them like so:
CPMAddPackage(
NAME openal-soft
VERSION 1.23.1
GITHUB_REPOSITORY "kcat/openal-soft"
GIT_TAG 1.23.1
OPTIONS
"ALSOFT_DLOPEN ON"
"ALSOFT_WERROR ON"
"ALSOFT_UTILS OFF"
"ALSOFT_NO_CONFIG_UTIL ON"
"ALSOFT_EXAMPLES OFF"
"ALSOFT_TESTS OFF"
"ALSOFT_INSTALL OFF"
"ALSOFT_INSTALL_CONFIG OFF"
"ALSOFT_INSTALL_HRTF_DATA OFF"
"ALSOFT_INSTALL_AMBDEC_PRESETS ON"
"ALSOFT_INSTALL_EXAMPLES OFF"
"ALSOFT_INSTALL_UTILS OFF"
"ALSOFT_UPDATE_BUILD_VERSION ON"
"ALSOFT_BUILD_ROUTER OFF"
"FORCE_STATIC_VCRT ON"
"ALSOFT_STATIC_LIBGCC ON"
"ALSOFT_STATIC_STDCXX ON"
"ALSOFT_STATIC_WINPTHREAD ON"
"ALSOFT_CPUEXT_SSE ON"
"ALSOFT_CPUEXT_SSE2 ON"
"ALSOFT_CPUEXT_SSE3 ON"
"ALSOFT_CPUEXT_SSE4_1 ON"
"ALSOFT_CPUEXT_NEON ON"
"ALSOFT_ENABLE_SSE2_CODEGEN ON"
"ALSOFT_BACKEND_WAVE ON"
"ALSOFT_EMBED_HRTF_DATA ON"
)
CPMAddPackage(
NAME ogg
VERSION 1.3.5
GITHUB_REPOSITORY "xiph/ogg"
OPTIONS
"BUILD_SHARED_LIBS ON"
"BUILD_FRAMEWORK ON"
"INSTALL_DOCS OFF"
"INSTALL_PKG_CONFIG_MODULE OFF"
"INSTALL_CMAKE_PACKAGE_MODULE OFF"
)
CPMAddPackage(
NAME flac
VERSION 1.4.3
GITHUB_REPOSITORY "xiph/flac"
GIT_TAG 1.4.3
OPTIONS
"BUILD_CXXLIBS ON"
"BUILD_PROGRAMS OFF"
"BUILD_EXAMPLES OFF"
"BUILD_TESTING OFF"
"BUILD_DOCS OFF"
"WITH_FORTIFY_SOURCE ON"
"WITH_STACK_PROTECTOR ON"
"INSTALL_MANPAGES OFF"
"INSTALL_PKGCONFIG_MODULES OFF"
"INSTALL_CMAKE_CONFIG_MODULE OFF"
"WITH_OGG ON"
"BUILD_SHARED_LIBS ON"
"ENABLE_MULTITHREADING ON"
"ENABLE_WERROR OFF"
)
CPMAddPackage(
NAME vorbis
VERSION 1.3.7
GITHUB_REPOSITORY "xiph/vorbis"
EXCLUDE_FROM_ALL YES
SYSTEM YES
OPTIONS
"BUILD_SHARED_LIBS ON"
"BUILD_FRAMEWORK OFF"
"INSTALL_CMAKE_PACKAGE_MODULE OFF"
)
CPMAddPackage(
NAME opus
VERSION 1.5.2
URL https://ftp.osuosl.org/pub/xiph/releases/opus/opus-1.5.2.tar.gz
URL_HASH SHA256=65c1d2f78b9f2fb20082c38cbe47c951ad5839345876e46941612ee87f9a7ce1
OPTIONS
"OPUS_BUILD_SHARED_LIBRARY ON"
"OPUS_BUILD_TESTING OFF"
"OPUS_CUSTOM_MODES ON"
"OPUS_BUILD_PROGRAMS OFF"
"OPUS_DISABLE_INTRINSICS OFF"
"OPUS_FIXED_POINT OFF"
"OPUS_ENABLE_FLOAT_API ON"
"OPUS_FLOAT_APPROX ON"
"OPUS_ASSERTIONS OFF"
"OPUS_HARDENING ON"
"OPUS_FUZZING OFF"
"OPUS_CHECK_ASM OFF"
"OPUS_DNN_FLOAT_DEBUG OFF"
"OPUS_INSTALL_PKG_CONFIG_MODULE OFF"
"OPUS_INSTALL_CMAKE_CONFIG_MODULE OFF"
"OPUS_DRED ON"
"OPUS_OSCE ON"
"OPUS_STATIC_RUNTIME ON"
)
CPMAddPackage(
NAME libsndfile
VERSION 1.2.2
GITHUB_REPOSITORY "libsndfile/libsndfile"
GIT_TAG 1.2.2
OPTIONS
"ENABLE_EXTERNAL_LIBS ON"
"ENABLE_MPEG ON"
"BUILD_REGTEST OFF"
"BUILD_SHARED_LIBS ON"
"BUILD_PROGRAMS OFF"
"BUILD_EXAMPLES ON"
"ENABLE_CPACK ON"
"ENABLE_BOW_DOCS OFF"
"ENABLE_STATIC_RUNTIME ON"
"ENABLE_PACKAGE_CONFIG ON"
"INSTALL_PKGCONFIG_MODULE OFF"
)
Then this:
CPMAddPackage(
NAME alure
VERSION master
GITHUB_REPOSITORY "kcat/alure"
GIT_TAG master
OPTIONS
"ALURE_DISABLE_RTTI OFF"
"ALURE_STATIC_GCCRT ON"
"ALURE_INSTALL OFF"
"ALURE_BUILD_SHARED ON"
"ALURE_BUILD_STATIC OFF"
"ALURE_ENABLE_WAVE ON"
"ALURE_ENABLE_VORBIS ON"
"ALURE_ENABLE_FLAC ON"
"ALURE_ENABLE_OPUS ON"
"ALURE_ENABLE_SNDFILE ON"
"ALURE_ENABLE_MINIMP3 ON"
"ALURE_BUILD_EXAMPLES OFF"
)
Doesn't work as one woudl expect:
-- The following RECOMMENDED packages have not been found:
* Vorbis, open source lossy audio codec, <www.vorbis.com/>
Enables Vorbis support
* FLAC, Free Lossless Audio Codec Library, <www.xiph.org/flac/>
Enables FLAC support
* Opus, Standardized open source low-latency fullband codec, <www.opus-codec.org/>
Enables experimental Opus support
* mp3lame, High quality MPEG Audio Layer III (MP3) encoder, <https://lame.sourceforge.io/>
Enables MPEG layer III (MP3) writing support
* mpg123 (required version >= 1.25.10), MPEG Audio Layer I/II/III decoder, <https://www.mpg123.de/>
Enables MPEG Audio reading support
-- CPM: Adding package alure@master (master)
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find OpenAL (missing: OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
Even trying a full reconfigure doesn't solve the problem. So I'm struggling to figure out what matters and what doesn't and how to get all of this to actually propagate properly.