I’m new to CMake & CPM, and attempting to get started with using them to generate JUCE projects.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(metronome)
set(CMAKE_CXX_STANDARD 23)
set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs)
include(cmake/get_cpm.cmake RESULT_VARIABLE ret)
message("include get_cpm successful? ${ret}")
include(libs/cpm/CPM_0.40.8.cmake RESULT_VARIABLE ret)
message("include cpm directly from CMakeLists successful? ${ret}")
CPMAddPackage(
NAME JUCE
GITHUB_REPOSITORY juce-framework/JUCE
GIT_TAG 8.0.6
VERSION 8.0.6
SOURCE_DIR ${LIB_DIR}/juce
)
My slightly modified get_cpm.cmake:
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
set(CPM_DOWNLOAD_VERSION 0.40.8)
set(CPM_DOWNLOAD_LOCATION "${LIB_DIR}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
include(${CPM_DOWNLOAD_LOCATION} RESULT_VARIABLE ret)
message("include CPM from get_cpm.cmake successful? ${ret}")
And the result of execution:
D:\Code\Plug-ins\metronome> cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -S . -B build
include CPM from get_cpm.cmake successful? D:/Code/Plug-ins/metronome/libs/cpm/CPM_0.40.8.cmake
include get_cpm successful? D:/Code/Plug-ins/metronome/cmake/get_cpm.cmake
include cpm directly from CMakeLists successful? D:/Code/Plug-ins/metronome/libs/cpm/CPM_0.40.8.cmake
CMake Error at CMakeLists.txt:14 (CPMAddPackage):
Unknown CMake command "CPMAddPackage".
-- Configuring incomplete, errors occurred!
CPM seems to be successfully downloaded and included, and when I inspect the CPM_0.40.8.cmake file, I can see that a function definition for “CPMAddPackage” is in there.
# Download and add a package from source
function(CPMAddPackage)
...
Anyone know why I might be seeing “Unknown CMake command” when attempting to invoke it?