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

CPM in CMake scripts: define_property command is not scriptable

gerhardol opened this issue · comments

fetchContent can be used in CMake scripts (cmake -P)
However, cpm.cmake manipulates some properties so this is not possible as a script.
Any way this can be fixed? (I tried commenting out setting of properties but it still fails).

The workaround I see is to define a dummy project to do the downloading, then use the path.

CMake Error at /usr/local/src/cmake-3.28.3/share/cmake-3.28/Modules/FetchContent.cmake:1188 (define_property):
  define_property command is not scriptable
Call Stack (most recent call first):
  /usr/local/src/cmake-3.28.3/share/cmake-3.28/Modules/FetchContent.cmake:1366:EVAL:1 (__FetchContent_declareDetails)
  /usr/local/src/cmake-3.28.3/share/cmake-3.28/Modules/FetchContent.cmake:1366 (cmake_language)
  util/CMakeConfig/cpm/CPM.cmake:929 (FetchContent_Declare)
  util/CMakeConfig/cpm/CPM.cmake:805 (cpm_declare_fetch)
  util/CMakeConfig/compiler_env.cmake:16 (cpmaddpackage)

Background:
cpm.cmake is a nice way to get dependencies, the handling of a cache outside of the build/ folder is easier to handle.
Some compilers fits in Docker, there are several variants of some other that makes it inconvenient to handle them in Docker.

So it is the natural step to try using cpm.cmake to distribute the compilers as packages (other tools are already handled).
Unfortunately, our compilers require some environment variables to be set and I have not got that working using cpm "from within" CMake configure. (Env var in CMake are not used by subshells).
The compiler must be fetched with a separate step and source the setup before the CMake configure call for the actual project.
This is actually also required for some products that are not using CMake at all, just the compiler.

The natural way would be to use a CMake script to fetch the package, source setup and then start the build.
I guess that it would be possible to use a dummy CMakeLists.txt and only run the configure phase as a workaround.

--
Edit:
Additional information: CMake 3.28.3
I get the same error with FetchContent_MakeAvailable() directly, so it may not be a CPM issue.