Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPMAddPackage does not export variables when finding local packages. #433

Open
Life4gal opened this issue Jan 3, 2023 · 2 comments
Open

Comments

@Life4gal
Copy link

Life4gal commented Jan 3, 2023

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.

@ClausKlein
Copy link
Contributor

ClausKlein commented Feb 20, 2023

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.

@wkjarosz
Copy link

This seems to still be an issue, also mentioned in #610

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants