@@ -69,22 +69,58 @@ jobs:
6969 cd ${{ runner.temp }}/test-find-package
7070
7171 # Get project name from CMakeLists.txt
72- THIS_PROJECT_NAME =$(grep -m1 "project(" ${{ github.workspace }}/CMakeLists.txt | sed 's/project(\(. *\))/\1/' | awk '{print $1}')
72+ PACKAGE_NAME =$(grep -m1 "project(" ${{ github.workspace }}/CMakeLists.txt | sed 's/project(\([^)] *\)).* /\1/' | awk '{print $1}')
7373
7474 # Create test CMakeLists.txt
7575 cat > CMakeLists.txt << EOF
7676 cmake_minimum_required(VERSION 3.20)
7777 project(test-find-package CXX)
7878
7979 set(CMAKE_PREFIX_PATH "${{ runner.temp }}/install")
80- find_package(${THIS_PROJECT_NAME } REQUIRED)
80+ find_package(${PACKAGE_NAME } REQUIRED)
8181
82- message(STATUS "Successfully found ${THIS_PROJECT_NAME }")
82+ message(STATUS "Successfully found ${PACKAGE_NAME }")
8383 EOF
8484
8585 # Test find_package
8686 cmake -B build -S .
8787
88+ - name : Test CPMFindPackage
89+ shell : bash
90+ run : |
91+ # Create test to verify CPMFindPackage works (tries find_package first, then CPM)
92+ mkdir -p ${{ runner.temp }}/test-cpm
93+ cd ${{ runner.temp }}/test-cpm
94+
95+ # Download CPM.cmake
96+ mkdir cmake
97+ curl -L https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake -o cmake/CPM.cmake
98+
99+ # Get project name from CMakeLists.txt
100+ PACKAGE_NAME=$(grep -m1 "project(" ${{ github.workspace }}/CMakeLists.txt | sed 's/project(\([^)]*\)).*/\1/' | awk '{print $1}')
101+
102+ # Create test CMakeLists.txt that uses CPMFindPackage
103+ cat > CMakeLists.txt << EOF
104+ cmake_minimum_required(VERSION 3.20)
105+ project(test-cpm CXX)
106+
107+ set(CMAKE_PREFIX_PATH "${{ runner.temp }}/install")
108+ set(CPM_SOURCE_CACHE \${CMAKE_SOURCE_DIR}/.cache/cpm CACHE PATH "CPM cache")
109+ include(cmake/CPM.cmake)
110+
111+ # CPMFindPackage tries find_package first, then falls back to CPMAddPackage
112+ CPMFindPackage(
113+ NAME ${PACKAGE_NAME}
114+ GITHUB_REPOSITORY ${{ github.repository }}
115+ GIT_TAG ${{ github.sha }}
116+ )
117+
118+ message(STATUS "Successfully acquired ${PACKAGE_NAME} via CPMFindPackage")
119+ EOF
120+
121+ # Test CPMFindPackage (should find the installed version first)
122+ cmake -B build -S .
123+
88124 clang-tidy :
89125 runs-on : ubuntu-latest
90126
0 commit comments