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

`CPMAddPackage` does not `export` variables when finding local packages.

Life4gal opened this issue · comments

At first, I used CPMFindPackage to add third-party dependencies, because I wanted CPM to first find out if there was a package that needed to be installed locally, and then download and install it if there wasn't.

But then I noticed that CPMFindPackage does not export variables if it finds a locally installed package.

Then I noticed that if I use CPMAddPackage and define CPM_USE_LOCAL_PACKAGES I can also achieve the same function and export the variables after it finds the locally installed packages.

The problem is that I can't use the exported variables even though the logs output using local package.

My CMake code is roughly like this:

CPMAddPackage(
		NAME CURL
		GIT_TAG curl-7_87_0
		GITHUB_REPOSITORY "curl/curl"
		OPTIONS "CURL_USE_OPENSSL"
)

# set(linked_project CURL)
if (${linked_project}_ADDED)
		# downloaded
		message(STATUS "Successfully added [${linked_project}], the source files path is [${${linked_project}_SOURCE_DIR}], the binary files path is [${${linked_project}_BINARY_DIR}]!")
		# add_subdirectory(
		# 		${${linked_project}_SOURCE_DIR}
		# 		${${linked_project}_BINARY_DIR}
		# 		EXCLUDE_FROM_ALL
		# )
else ()
		message(FATAL_ERROR "Library [${linked_project}] not found!")
endif (${linked_project}_ADDED)

Everything works fine on Windows and Linux, but not on MacOS. I don't have a MacOS environment to test in, so I'm relying on GitHub Workflows.

If the local package is found, find_project() set ${linked_project}_FOUND and ${linked_project}_DIR, or not?

IMHO, that is right, because the other variables are related to CPM.cmake but only if the git repo was cloned -> added.