From edca4b690299996c5690887ca39f7b5568a85dae Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Thu, 15 Sep 2022 11:45:10 +0100 Subject: [PATCH 1/8] Allow CPM_DOWNLOAD_LOCATION from ENV or Command-line --- cmake/get_cpm.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmake/get_cpm.cmake b/cmake/get_cpm.cmake index 89343975..3dc09029 100644 --- a/cmake/get_cpm.cmake +++ b/cmake/get_cpm.cmake @@ -1,11 +1,15 @@ set(CPM_DOWNLOAD_VERSION 1.0.0-development-version) -if(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") -else() - set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +if ( NOT CPM_DOWNLOAD_LOCATION) + if(DEFINED ENV{CPM_DOWNLOAD_LOCATION}) + file(TO_CMAKE_PATH "$ENV{CPM_DOWNLOAD_LOCATION}" 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") + else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + endif() endif() # Expand relative path. This is important if the provided path contains a tilde (~) From 1a6b27f0b5fe2dbd29fd2ebcb66d77612ac2204d Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Thu, 15 Sep 2022 11:46:25 +0100 Subject: [PATCH 2/8] Allow Local package override from ENV variable --- cmake/CPM.cmake | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 44236192..a1bb8d5d 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -611,10 +611,17 @@ 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) + 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}" From ec7c226fcf20bb7473b9c875b29a56e41484ef77 Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Wed, 21 Sep 2022 10:05:29 +0100 Subject: [PATCH 3/8] Removed nesting on `CPM_DOWNLOAD_LOCATION` --- cmake/get_cpm.cmake | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmake/get_cpm.cmake b/cmake/get_cpm.cmake index 3dc09029..e6ed3e15 100644 --- a/cmake/get_cpm.cmake +++ b/cmake/get_cpm.cmake @@ -1,15 +1,15 @@ set(CPM_DOWNLOAD_VERSION 1.0.0-development-version) -if ( NOT CPM_DOWNLOAD_LOCATION) - if(DEFINED ENV{CPM_DOWNLOAD_LOCATION}) - file(TO_CMAKE_PATH "$ENV{CPM_DOWNLOAD_LOCATION}" 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") - else() - set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") - endif() +if ( CPM_DOWNLOAD_LOCATION) + # Empty as `CPM_DOWNLOAD_LOCATION` already set in parent scope +elseif(DEFINED ENV{CPM_DOWNLOAD_LOCATION}) + file(TO_CMAKE_PATH "$ENV{CPM_DOWNLOAD_LOCATION}" 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") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") endif() # Expand relative path. This is important if the provided path contains a tilde (~) From 3ebaabc531c153baff1bc01fc5bae73376e2fac5 Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Wed, 28 Sep 2022 12:42:04 +0100 Subject: [PATCH 4/8] Apply `fix-cmake-format` build target --- cmake/CPM.cmake | 9 +++++---- cmake/get_cpm.cmake | 12 ++++++------ test/CMakeLists.txt | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index a1bb8d5d..56f856a5 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -611,11 +611,12 @@ 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 ) + # 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) - elseif( DEFINED ENV{CPM_${CPM_ARGS_NAME}_SOURCE}) + elseif(DEFINED ENV{CPM_${CPM_ARGS_NAME}_SOURCE}) file(TO_CMAKE_PATH "$ENV{CPM_${CPM_ARGS_NAME}_SOURCE}" PACKAGE_SOURCE) endif() diff --git a/cmake/get_cpm.cmake b/cmake/get_cpm.cmake index e6ed3e15..9280c703 100644 --- a/cmake/get_cpm.cmake +++ b/cmake/get_cpm.cmake @@ -1,15 +1,15 @@ set(CPM_DOWNLOAD_VERSION 1.0.0-development-version) -if ( CPM_DOWNLOAD_LOCATION) - # Empty as `CPM_DOWNLOAD_LOCATION` already set in parent scope +if(CPM_DOWNLOAD_LOCATION) + # Empty as `CPM_DOWNLOAD_LOCATION` already set in parent scope elseif(DEFINED ENV{CPM_DOWNLOAD_LOCATION}) - file(TO_CMAKE_PATH "$ENV{CPM_DOWNLOAD_LOCATION}" CPM_DOWNLOAD_LOCATION) + file(TO_CMAKE_PATH "$ENV{CPM_DOWNLOAD_LOCATION}" CPM_DOWNLOAD_LOCATION) elseif(CPM_SOURCE_CACHE) - set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + 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") + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") else() - set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") endif() # Expand relative path. This is important if the provided path contains a tilde (~) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4bc734c3..35496f81 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,3 +14,5 @@ foreach(test ${tests}) endforeach() add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} -C Debug --verbose) + +add_subdirectory(style) From d680cb769ee1c293f2b94b9fb0674269c2855a36 Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Tue, 4 Oct 2022 10:32:02 +0100 Subject: [PATCH 5/8] Change to use `CPM_PATH` as user-defined CPM source location --- cmake/get_cpm.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake/get_cpm.cmake b/cmake/get_cpm.cmake index 9280c703..2dfd89a4 100644 --- a/cmake/get_cpm.cmake +++ b/cmake/get_cpm.cmake @@ -1,10 +1,10 @@ set(CPM_DOWNLOAD_VERSION 1.0.0-development-version) -if(CPM_DOWNLOAD_LOCATION) - # Empty as `CPM_DOWNLOAD_LOCATION` already set in parent scope -elseif(DEFINED ENV{CPM_DOWNLOAD_LOCATION}) - file(TO_CMAKE_PATH "$ENV{CPM_DOWNLOAD_LOCATION}" CPM_DOWNLOAD_LOCATION) -elseif(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") From f753ce871b7926cf67ab40c39bbf14f80dd40c8e Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Mon, 10 Oct 2022 12:24:20 +0100 Subject: [PATCH 6/8] Revert add of `style` to test build --- test/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 35496f81..4bc734c3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,5 +14,3 @@ foreach(test ${tests}) endforeach() add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} -C Debug --verbose) - -add_subdirectory(style) From 8f58d23d9f3b1317b658df4b537c349d35bc4c85 Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Mon, 10 Oct 2022 12:25:20 +0100 Subject: [PATCH 7/8] Removed trailing space --- cmake/get_cpm.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/get_cpm.cmake b/cmake/get_cpm.cmake index 2dfd89a4..1dac891b 100644 --- a/cmake/get_cpm.cmake +++ b/cmake/get_cpm.cmake @@ -4,7 +4,7 @@ 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) +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") From 68a0f7463d158271bce2bf48b253661716b7ec45 Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Thu, 13 Oct 2022 13:33:32 +0100 Subject: [PATCH 8/8] Simplified local-package with TODO for allowing as extension-point --- cmake/CPM.cmake | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 56f856a5..be56e3a7 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -611,18 +611,16 @@ 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) - elseif(DEFINED ENV{CPM_${CPM_ARGS_NAME}_SOURCE}) - file(TO_CMAKE_PATH "$ENV{CPM_${CPM_ARGS_NAME}_SOURCE}" PACKAGE_SOURCE) + # @TODO Allow this as from a user-extension point for locating package source e.g. Check for ENV + # overide for local package-source + if(NOT DEFINED CPM_${CPM_ARGS_NAME}_SOURCE AND DEFINED ENV{CPM_${CPM_ARGS_NAME}_SOURCE}) + file(TO_CMAKE_PATH $ENV{CPM_${CPM_ARGS_NAME}_SOURCE} CPM_${CPM_ARGS_NAME}_SOURCE) endif() # Check for manual overrides - if(NOT CPM_ARGS_FORCE AND NOT "${PACKAGE_SOURCE}" STREQUAL "") - set(CPM_${CPM_ARGS_NAME}_SOURCE "") # Assign empty to prevent recursion + 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 "") CPMAddPackage( NAME "${CPM_ARGS_NAME}" SOURCE_DIR "${PACKAGE_SOURCE}"