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

Support CPM_<dependency name>_SOURCE local package override from ENV #406

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
14 changes: 11 additions & 3 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,18 @@ function(CPMAddPackage)
return()
endif()

# Check for ENV overide for local package-source when not already defined. NOTE: Uses a recursive
# CPMAddPackage call where `CPM_${CPM_ARGS_NAME}_SOURCE` == "" which causes first if-case to stop
# recusrion
if(CPM_${CPM_ARGS_NAME}_SOURCE)
file(TO_CMAKE_PATH "${CPM_${CPM_ARGS_NAME}_SOURCE}" PACKAGE_SOURCE)
CraigHutchinson marked this conversation as resolved.
Show resolved Hide resolved
elseif(DEFINED ENV{CPM_${CPM_ARGS_NAME}_SOURCE})
file(TO_CMAKE_PATH "$ENV{CPM_${CPM_ARGS_NAME}_SOURCE}" PACKAGE_SOURCE)
endif()

# Check for manual overrides
if(NOT CPM_ARGS_FORCE AND NOT "${CPM_${CPM_ARGS_NAME}_SOURCE}" STREQUAL "")
set(PACKAGE_SOURCE ${CPM_${CPM_ARGS_NAME}_SOURCE})
set(CPM_${CPM_ARGS_NAME}_SOURCE "")
if(NOT CPM_ARGS_FORCE AND NOT "${PACKAGE_SOURCE}" STREQUAL "")
set(CPM_${CPM_ARGS_NAME}_SOURCE "") # Assign empty to prevent recursion
CPMAddPackage(
NAME "${CPM_ARGS_NAME}"
SOURCE_DIR "${PACKAGE_SOURCE}"
Expand Down
6 changes: 5 additions & 1 deletion cmake/get_cpm.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
set(CPM_DOWNLOAD_VERSION 1.0.0-development-version)

if(CPM_SOURCE_CACHE)
if(CPM_PATH) # CPM_PATH may be provided on command-line
set(CPM_DOWNLOAD_LOCATION "${CPM_PATH}/CPM.cmake")
elseif(DEFINED ENV{CPM_PATH}) # CPM_PATH may be provided from script environment
file(TO_CMAKE_PATH "$ENV{CPM_PATH}/CPM.cmake" CPM_DOWNLOAD_LOCATION)
elseif(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ foreach(test ${tests})
endforeach()

add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} -C Debug --verbose)

add_subdirectory(style)
TheLartians marked this conversation as resolved.
Show resolved Hide resolved