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

Adds support for hosting sites other than GitHub. #157

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,24 @@ jobs:
with:
cmakeVersion: ${{ env.cmake_version }}

- name: Download Catch2
run: |
git clone https://github.com/catchorg/Catch2.git catch2 --branch v3.0.1
#- 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: 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: >
cmake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ cpp_class(CMakePackageManager PackageManager)
cpp_map(GET "${_rd_dependencies}" _rd_depend "${_rd_pkg_name}")
if("${_rd_depend}" STREQUAL "")
message(DEBUG "Registering dependency to package manager: ${_rd_pkg_name}")
# TODO: Actually make sure it's from GitHub
GitHubDependency(CTOR _rd_depend)

set(_rd_depend "")
if("${ARGN}" MATCHES "github")
GitHubDependency(CTOR _rd_depend)
else()
RemoteURLDependency(CTOR _rd_depend)
endif()

Dependency(init "${_rd_depend}" NAME "${_rd_pkg_name}" ${ARGN})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ include_guard()

include(cmaize/package_managers/cmake/dependency/dependency_class)
include(cmaize/package_managers/cmake/dependency/github)
include(cmaize/package_managers/cmake/dependency/remote_url)
27 changes: 6 additions & 21 deletions cmake/cmaize/package_managers/cmake/dependency/github.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

include_guard()

include(cmaize/package_managers/cmake/dependency/dependency_class)
include(cmaize/package_managers/cmake/dependency/remote_url)
include(cmaize/utilities/fetch_and_available)
include(cmaize/utilities/sanitize_url)

cpp_class(GitHubDependency Dependency)
cpp_class(GitHubDependency RemoteURLDependency)

#[[[
# :type: bool
Expand All @@ -44,7 +44,7 @@ cpp_class(GitHubDependency Dependency)
#]]
cpp_member(build_dependency GitHubDependency)
function("${build_dependency}" _bd_this)

GitHubDependency(GET "${_bd_this}" _bd_url location)
GitHubDependency(GET "${_bd_this}" _bd_private private)
GitHubDependency(GET "${_bd_this}" _bd_version version)
Expand Down Expand Up @@ -88,17 +88,7 @@ cpp_class(GitHubDependency Dependency)
set(_bd_url "https://${_bd_url}")
endif()

# 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()
RemoteURLDependency(_cache_args "${_bd_this}" _bd_old_cmake_args)

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

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()
RemoteURLDependency(_uncache_args "${_bd_this}" _bd_old_cmake_args)

_cmaize_dependency_check_target("${_bd_this}" "build")
# It's now "found" since it's been added to our build system
Expand Down Expand Up @@ -161,7 +146,7 @@ cpp_class(GitHubDependency Dependency)

# Clean up the GitHub URL and ensure it is from GitHub
cmaize_sanitize_url(_i_URL "${_i_URL}" DOMAIN "github.com")
GitHubDependency(SET "${self}" location "${_i_URL}")
RemoteURLDependency(SET "${self}" location "${_i_URL}")

GitHubDependency(SET "${self}" name "${_i_NAME}")
GitHubDependency(SET "${self}" version "${_i_VERSION}")
Expand Down
136 changes: 136 additions & 0 deletions cmake/cmaize/package_managers/cmake/dependency/remote_url.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Copyright 2023 CMakePP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_guard()

include(cmaize/package_managers/cmake/dependency/dependency_class)
include(cmaize/utilities/fetch_and_available)

cpp_class(RemoteURLDependency Dependency)

#[[[
# :type: desc
#
# URL for the resource
#]]
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.
#
# :param self: Dependency object
# :type self: Dependency
#
#]]
cpp_member(build_dependency RemoteURLDependency)
function("${build_dependency}" _bd_this)

RemoteURLDependency(GET "${_bd_this}" _bd_url location)
RemoteURLDependency(GET "${_bd_this}" _bd_name name)

RemoteURLDependency(_cache_args "${_bd_this}" _bd_old_cmake_args)

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

RemoteURLDependency(_uncache_args "${_bd_this}" _bd_old_cmake_args)

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

# It's now "found" since it's been added to our build system
Dependency(SET "${_bd_this}" found TRUE)

endfunction()

#[[[
# Initialize the dependency with project information.
#
# :param **kwargs: Additional keyword arguments may be necessary.
#
# :Keyword Arguments:
# * **BUILD_TARGET** (*desc*) --
# Name of the target when it is built. This usually does not include
# namespaces yet.
# * **FIND_TARGET** (*desc*) --
# Name of the target when it is found using something like CMake's
# ``find_package()`` tool. This typically does include a namespace.
# * **NAME** (*desc*) --
# Name used to identify this dependency. This does not need to match
# the find or build target names, but frequently will match one or
# both.
# * **URL** (*desc*) --
# URL for the GitHub repository. This can be the URL to the
# repository or the HTTPS link used to clone the repository, but
# not the SSH cloning option.
#]]
cpp_member(init RemoteURLDependency args)
function("${init}" self)

set(_i_options )
set(_i_one_value_args BUILD_TARGET FIND_TARGET NAME URL)
set(_i_list CMAKE_ARGS)
cmake_parse_arguments(
_i "${_i_options}" "${_i_one_value_args}" "${_i_list}" ${ARGN}
)

RemoteURLDependency(SET "${self}" location "${_i_URL}")

RemoteURLDependency(SET "${self}" name "${_i_NAME}")
RemoteURLDependency(SET "${self}" build_target "${_i_BUILD_TARGET}")
RemoteURLDependency(SET "${self}" find_target "${_i_FIND_TARGET}")
RemoteURLDependency(SET "${self}" cmake_args "${_i_CMAKE_ARGS}")

endfunction()

cpp_end_class()
Loading