Skip to content

Commit

Permalink
fix problem with pre-installed depends (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmrichard authored Jun 25, 2024
1 parent 4c9f063 commit 9c4ce63
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 63 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ jobs:
with:
cmakeVersion: ${{ env.cmake_version }}

#- name: Download Catch2
# run: |
# git clone https://github.com/catchorg/Catch2.git catch2 \
# --branch v3.4.0

#- name: Build Catch2
# run: |
# prefix=`pwd`/catch2_install
# cd catch2
# cmake -H. -Bbuild -DCMAKE_INSTALL_PREFIX="${prefix}"
# cmake --build build --parallel 2
# echo "CMAKE_PREFIX_PATH=${prefix}" >> $GITHUB_ENV

#- name: Install Catch2
# run: |
# cd catch2
# cmake --build build --target install
- name: Download Catch2
run: |
git clone https://github.com/catchorg/Catch2.git catch2 \
--branch v3.4.0
- name: Build Catch2
run: |
prefix=`pwd`/catch2_install
cd catch2
cmake -H. -Bbuild -DCMAKE_INSTALL_PREFIX="${prefix}"
cmake --build build --parallel 2
echo "CMAKE_PREFIX_PATH=${prefix}" >> $GITHUB_ENV
- name: Install Catch2
run: |
cd catch2
cmake --build build --target install
- name: Configure Project
run: >
Expand Down
12 changes: 12 additions & 0 deletions cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,23 @@ cpp_class(CMakePackageManager PackageManager)

CMakePackageManager(GET "${self}" _rd_dependencies dependencies)
cpp_map(GET "${_rd_dependencies}" _rd_depend "${_rd_pkg_name}")
cpp_map(KEYS "${_rd_dependencies}" _rd_keys)
foreach(_rd_key ${_rd_keys})
cpp_map(GET "${_rd_dependencies}" _rd_temp "${_rd_key}")
message("${_rd_key} = ${_rd_temp}")
endforeach()


message("PackageManager had ${_rd_pkg_name} = ${_rd_depend}")
if("${_rd_depend}" STREQUAL "")
message(DEBUG "Registering dependency to package manager: ${_rd_pkg_name}")

set(_rd_depend "")
if("${ARGN}" MATCHES "github")
message("Creating a GitHub dependency")
GitHubDependency(CTOR _rd_depend)
else()
message("Creating a non-GitHub dependency")
RemoteURLDependency(CTOR _rd_depend)
endif()

Expand Down Expand Up @@ -182,6 +192,8 @@ cpp_class(CMakePackageManager PackageManager)

PackageSpecification(GET "${_fi_package_specs}" _fi_pkg_name name)

message("Looking for ${_fi_pkg_name}")

CMakePackageManager(register_dependency
"${self}"
_fi_depend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ cpp_class(Dependency)

# Check if it was already found? If so short-circuit and return TRUE
Dependency(GET "${self}" "${_fd_found}" found)
message("Was already found? ${${_fd_found}}")
if("${${_fd_found}}")
cpp_return("${_fd_found}")
endif()
Expand Down Expand Up @@ -202,4 +203,3 @@ cpp_class(Dependency)
endfunction()

cpp_end_class()

19 changes: 17 additions & 2 deletions cmake/cmaize/package_managers/cmake/dependency/github.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,17 @@ cpp_class(GitHubDependency RemoteURLDependency)
set(_bd_url "https://${_bd_url}")
endif()

RemoteURLDependency(_cache_args "${_bd_this}" _bd_old_cmake_args)
# The only reliable way to forward arguments to subprojects seems to be
# through the cache, so we need to record the current values, set the
# temporary values, call the subproject, reset the old values
set(_bd_old_cmake_args)
foreach(_bd_pair ${_bd_cmake_args})
string(REPLACE "=" [[;]] _bd_split_pair "${_bd_pair}")
list(GET _bd_split_pair 0 _bd_var)
list(GET _bd_split_pair 1 _bd_val)
list(APPEND _bd_old_cmake_args "${_bd_var}=${${_bd_var}}")
set("${_bd_var}" "${_bd_val}" CACHE BOOL "" FORCE)
endforeach()

# It's possible GitHub URLs link to an "asset" (i.e., a tarball)
string(FIND "${_bd_url}" ".tgz" _bd_is_tarball)
Expand All @@ -103,7 +113,12 @@ cpp_class(GitHubDependency RemoteURLDependency)
cmaize_fetch_and_available("${_bd_name}" URL "${_bd_url}")
endif()

RemoteURLDependency(_uncache_args "${_bd_this}" _bd_old_cmake_args)
foreach(_bd_pair ${_bd_old_cmake_args})
string(REPLACE "=" [[;]] _bd_split_pair "${_bd_pair}")
list(GET _bd_split_pair 0 _bd_var)
list(GET _bd_split_pair 1 _bd_val)
set("${_bd_var}" "${_bd_val}" CACHE BOOL "" FORCE)
endforeach()

_cmaize_dependency_check_target("${_bd_this}" "build")
# It's now "found" since it's been added to our build system
Expand Down
60 changes: 17 additions & 43 deletions cmake/cmaize/package_managers/cmake/dependency/remote_url.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,6 @@ cpp_class(RemoteURLDependency Dependency)
#]]
cpp_attr(RemoteURLDependency location "")

#[[[
# Updates the values of the CMake cache to be consistent with the values
# requested by this dependency.
#
# :param old_cmake_args: Variable to assign the old values to.
# :type old_cmake_args: list*
#]]

cpp_member(_cache_args RemoteURLDependency list*)
function("${_cache_args}" _ca_this _ca_old_cmake_args)
RemoteURLDependency(GET "${_ca_this}" _ca_cmake_args cmake_args)

# The only reliable way to forward arguments to subprojects seems to be
# through the cache, so we need to record the current values, set the
# temporary values, call the subproject, reset the old values
foreach(_ca_pair ${_ca_cmake_args})
string(REPLACE "=" [[;]] _ca_split_pair "${_ca_pair}")
list(GET _ca_split_pair 0 _ca_var)
list(GET _ca_split_pair 1 _ca_val)
list(APPEND "${_ca_old_cmake_args}" "${_ca_var}=${${_ca_var}}")
set("${_ca_var}" "${_ca_val}" CACHE BOOL "" FORCE)
endforeach()
cpp_return("${_ca_old_cmake_args}")
endfunction()

#[[[
# Restores the values in the CMake cach to those in old_cmake_args.
#
# :param old_cmake_args: The values to put back into the cache.
# :type old_cmake_args: desc*
#]]
cpp_member(_uncache_args RemoteURLDependency list*)
function("${_uncache_args}" _ua_this _ua_old_cmake_args)
foreach(_ua_pair ${${_ua_old_cmake_args}})
string(REPLACE "=" [[;]] _ua_split_pair "${_ua_pair}")
list(GET _ua_split_pair 0 _ua_var)
list(GET _ua_split_pair 1 _ua_val)
set("${_ua_var}" "${_ua_val}" CACHE BOOL "" FORCE)
endforeach()
endfunction()

#[[[
# Attempts to fetch and build the dependency.
#
Expand All @@ -80,11 +39,26 @@ cpp_class(RemoteURLDependency Dependency)
RemoteURLDependency(GET "${_bd_this}" _bd_url location)
RemoteURLDependency(GET "${_bd_this}" _bd_name name)

RemoteURLDependency(_cache_args "${_bd_this}" _bd_old_cmake_args)
# The only reliable way to forward arguments to subprojects seems to be
# through the cache, so we need to record the current values, set the
# temporary values, call the subproject, reset the old values
set(_bd_old_cmake_args)
foreach(_bd_pair ${_bd_cmake_args})
string(REPLACE "=" [[;]] _bd_split_pair "${_bd_pair}")
list(GET _bd_split_pair 0 _bd_var)
list(GET _bd_split_pair 1 _bd_val)
list(APPEND _bd_old_cmake_args "${_bd_var}=${${_bd_var}}")
set("${_bd_var}" "${_bd_val}" CACHE BOOL "" FORCE)
endforeach()

cmaize_fetch_and_available("${_bd_name}" GIT_REPOSITORY "${_bd_url}.git")

RemoteURLDependency(_uncache_args "${_bd_this}" _bd_old_cmake_args)
foreach(_bd_pair ${_bd_old_cmake_args})
string(REPLACE "=" [[;]] _bd_split_pair "${_bd_pair}")
list(GET _bd_split_pair 0 _bd_var)
list(GET _bd_split_pair 1 _bd_val)
set("${_bd_var}" "${_bd_val}" CACHE BOOL "" FORCE)
endforeach()

_cmaize_dependency_check_target("${_bd_this}" "build")

Expand Down

0 comments on commit 9c4ce63

Please sign in to comment.