mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-17 14:47:30 -05:00
Added export of CPM_LAST_PACKAGE_NAME (#403)
This commit is contained in:
@@ -97,6 +97,7 @@ After calling `CPMAddPackage`, the following variables are defined in the local
|
||||
- `<dependency>_SOURCE_DIR` is the path to the source of the dependency.
|
||||
- `<dependency>_BINARY_DIR` is the path to the build directory of the dependency.
|
||||
- `<dependency>_ADDED` is set to `YES` if the dependency has not been added before, otherwise it is set to `NO`.
|
||||
- `CPM_LAST_PACKAGE_NAME` is set to the determined name of the last added dependency (equivalent to `<dependency>`).
|
||||
|
||||
For using CPM.cmake projects with external package managers, such as conan or vcpkg, setting the variable [`CPM_USE_LOCAL_PACKAGES`](#options) will make CPM.cmake try to add a package through `find_package` first, and add it from source if it doesn't succeed.
|
||||
|
||||
|
||||
@@ -808,6 +808,10 @@ macro(cpm_export_variables name)
|
||||
"${${name}_ADDED}"
|
||||
PARENT_SCOPE
|
||||
)
|
||||
set(CPM_LAST_PACKAGE_NAME
|
||||
"${name}"
|
||||
PARENT_SCOPE
|
||||
)
|
||||
endmacro()
|
||||
|
||||
# declares a package, so that any call to CPMAddPackage for the package name will use these
|
||||
|
||||
@@ -14,3 +14,5 @@ foreach(test ${tests})
|
||||
endforeach()
|
||||
|
||||
add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} -C Debug --verbose)
|
||||
|
||||
add_subdirectory(style)
|
||||
|
||||
@@ -6,6 +6,7 @@ include(${CPM_PATH}/testing.cmake)
|
||||
set(CPM_DRY_RUN ON)
|
||||
|
||||
CPMAddPackage(NAME A GIT_TAG 1.2.3)
|
||||
assert_equal("${CPM_LAST_PACKAGE_NAME}" "A")
|
||||
|
||||
CPMAddPackage(NAME A VERSION 1.2.3)
|
||||
|
||||
@@ -17,6 +18,8 @@ CPMAddPackage(NAME B VERSION 2.4.1)
|
||||
CPMAddPackage(NAME B GIT_TAG v2.3.1)
|
||||
|
||||
CPMGetPackageVersion(B VERSION)
|
||||
assert_equal("${CPM_LAST_PACKAGE_NAME}" "B")
|
||||
|
||||
assert_equal(${VERSION} "2.4.1")
|
||||
|
||||
CPMAddPackage(
|
||||
@@ -24,6 +27,10 @@ CPMAddPackage(
|
||||
GIT_TAG v3.1.2-a
|
||||
VERSION 3.1.2
|
||||
)
|
||||
assert_equal("${CPM_LAST_PACKAGE_NAME}" "C")
|
||||
|
||||
CPMGetPackageVersion(C VERSION)
|
||||
assert_equal(${VERSION} "3.1.2")
|
||||
|
||||
CPMAddPackage("gh:dry-run/D")
|
||||
assert_equal("${CPM_LAST_PACKAGE_NAME}" "D")
|
||||
|
||||
@@ -32,3 +32,4 @@ include(@CPM_PATH@/testing.cmake)
|
||||
ASSERT_TRUTHY(@TEST_DEPENDENCY_NAME@_ADDED)
|
||||
ASSERT_DEFINED(@TEST_DEPENDENCY_NAME@_SOURCE_DIR)
|
||||
ASSERT_DEFINED(@TEST_DEPENDENCY_NAME@_BINARY_DIR)
|
||||
ASSERT_EQUAL("${CPM_LAST_PACKAGE_NAME}" "@TEST_DEPENDENCY_NAME@")
|
||||
|
||||
@@ -25,3 +25,5 @@ include(@CPM_PATH@/testing.cmake)
|
||||
ASSERT_TRUTHY(Dependency_ADDED)
|
||||
ASSERT_DEFINED(Dependency_SOURCE_DIR)
|
||||
ASSERT_DEFINED(Dependency_BINARY_DIR)
|
||||
ASSERT_EQUAL("${CPM_LAST_PACKAGE_NAME}" "Dependency")
|
||||
|
||||
|
||||
@@ -30,3 +30,4 @@ include(@CPM_PATH@/testing.cmake)
|
||||
ASSERT_TRUTHY(fibonacci_ADDED)
|
||||
ASSERT_DEFINED(fibonacci_SOURCE_DIR)
|
||||
ASSERT_DEFINED(fibonacci_BINARY_DIR)
|
||||
ASSERT_EQUAL("${CPM_LAST_PACKAGE_NAME}" "fibonacci")
|
||||
|
||||
Reference in New Issue
Block a user