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 a package manager based on PIP #142

Merged
merged 32 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
316deb3
fixes 122, 109, and 100
ryanmrichard Nov 30, 2023
14a11bf
backup
ryanmrichard Nov 30, 2023
a9ff0b1
missed some deprecations.
ryanmrichard Nov 30, 2023
c254cad
Merge branch '122' into 113
ryanmrichard Nov 30, 2023
481a872
backup
ryanmrichard Nov 30, 2023
e9e3247
missed cpp reference
ryanmrichard Dec 4, 2023
a0ce51d
Merge branch 'master' into 113
ryanmrichard Dec 4, 2023
4ed9cfe
try again
ryanmrichard Dec 4, 2023
d711d3f
cmaize_option is added and tested
ryanmrichard Dec 7, 2023
8a5fa85
fix missing prefixes?
ryanmrichard Dec 8, 2023
78be79b
Committing license headers
Dec 8, 2023
733c173
sanity check
ryanmrichard Dec 8, 2023
282b309
Merge branch '113' of https://github.com/CMakePP/CMaize into 113
ryanmrichard Dec 8, 2023
01d6643
backup
ryanmrichard Dec 11, 2023
98b1320
remove print
ryanmrichard Dec 11, 2023
54c5ca1
adds cmaize_option_list
ryanmrichard Dec 11, 2023
6c2fb4b
backup [skip ci]
ryanmrichard Dec 11, 2023
9bdf638
properly get languages and adds missing self
ryanmrichard Dec 11, 2023
3c2f12d
backup
ryanmrichard Dec 11, 2023
8f1da10
remove extra enabled_languages
ryanmrichard Dec 11, 2023
0869785
addresses Zach's comments
ryanmrichard Dec 11, 2023
ace9004
Merge branch '113' into pip_pm
ryanmrichard Dec 11, 2023
74c77bc
adds missed comment from 138
ryanmrichard Dec 11, 2023
2298db9
Merge branch 'master' into pip_pm
ryanmrichard Dec 11, 2023
78476d4
backup [skip ci]
ryanmrichard Dec 13, 2023
96a882d
backup [skip ci]
ryanmrichard Dec 14, 2023
d6b449a
finally works (I hope...)
ryanmrichard Dec 15, 2023
7a8154d
missed some capitalization changes
ryanmrichard Dec 15, 2023
f6f416e
Committing license headers
Dec 15, 2023
c797f91
Update TODO based on 144
ryanmrichard Dec 20, 2023
11efead
Merge branch 'master' into pip_pm
ryanmrichard Dec 20, 2023
64d3768
address Zach's comments
ryanmrichard Dec 21, 2023
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
1 change: 1 addition & 0 deletions cmake/cmaize/cmaize_impl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if(NOT CMAKE_MAXIMUM_RECURSION_DEPTH)
endif()

include(cmaize/globals)
include(cmaize/package_managers/package_managers)
include(cmaize/project/projects)
include(cmaize/targets/targets)
include(cmaize/toolchain/toolchain)
Expand Down
2 changes: 1 addition & 1 deletion cmake/cmaize/globals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ cpp_set_global(
#]]
cpp_set_global(
CMAIZE_SUPPORTED_PACKAGE_MANAGERS
CMake
cmake
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include(cmakepp_lang/cmakepp_lang)
include(cmaize/package_managers/package_manager)
include(cmaize/package_managers/get_package_manager)
include(cmaize/package_managers/cmake/dependency/dependency)
include(cmaize/package_managers/cmake/cmake_package_manager_impl_/impl_)
include(cmaize/package_managers/cmake/impl_/impl_)
include(cmaize/project/package_specification)
include(cmaize/targets/cmaize_target)
include(cmaize/utilities/fetch_and_available)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro(_cpm_ctor_impl self)
include(GNUInstallDirs)
endif()

PackageManager(SET "${self}" type "CMake")
PackageManager(SET "${self}" type "cmake")

# Establish default paths
if(CMAKE_INSTALL_LIBDIR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ INTERFACE_LINK_LIBRARIES "
__gtc_file_contents
"
set(_CMAIZE_IMPORT_LOCATION \"\${PACKAGE_PREFIX_DIR}/${__gtc_lib_prefix}/${__gtc_target_name}/${__gtc_libname_w_version}\")

# TODO: Handle different configurations (Release, Debug, etc.)
# Import target \"${__gtc_namespace}${__gtc_target_name}\" for configuration \"???\"
set_property(TARGET ${__gtc_namespace}${__gtc_target_name} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(${__gtc_namespace}${__gtc_target_name} PROPERTIES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

include_guard()

set(_cpm_impl_dir "cmaize/package_managers/cmake/cmake_package_manager_impl_")

include(${_cpm_impl_dir}/ctor)
include(${_cpm_impl_dir}/generate_package_config)
include(${_cpm_impl_dir}/generate_target_config)
include(${_cpm_impl_dir}/install_package)
include(cmaize/package_managers/cmake/impl_/ctor)
include(cmaize/package_managers/cmake/impl_/generate_package_config)
include(cmaize/package_managers/cmake/impl_/generate_target_config)
include(cmaize/package_managers/cmake/impl_/install_package)
12 changes: 9 additions & 3 deletions cmake/cmaize/package_managers/get_package_manager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ function(get_package_manager_instance _gpmi_result _gpmi_type)
cpp_assert_signature("${ARGV}" desc desc)

cpp_get_global(_gpmi_pm_map __CMAIZE_PACKAGE_MANAGER_MAP__)
cpp_map(HAS_KEY "${_gpmi_pm_map}" _gpmi_has_type "${_gpmi_type}")

if(NOT _gpmi_has_type)
cpp_raise(
PM_NOT_FOUND
"Could not locate a package manager of type '${_gpmi_type}'"
)
endif()
cpp_map(GET "${_gpmi_pm_map}" _gpmi_instance "${_gpmi_type}")

if("${_gpmi_instance}" STREQUAL "")
Expand All @@ -62,9 +69,8 @@ endfunction()
function(register_package_manager _rpm_name _rpm_instance)

cpp_get_global(_rpm_pm_map __CMAIZE_PACKAGE_MANAGER_MAP__)

cpp_map(SET "${_rpm_pm_map}" "${_rpm_name}" "${_rpm_instance}")

cpp_map(HAS_KEY "${_rpm_pm_map}" _rpm_has_name "${_rpm_name}")
ryanmrichard marked this conversation as resolved.
Show resolved Hide resolved
cpp_set_global(__CMAIZE_PACKAGE_MANAGER_MAP__ "${_rpm_pm_map}")

endfunction()
endfunction()
5 changes: 3 additions & 2 deletions cmake/cmaize/package_managers/package_manager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include(cmakepp_lang/cmakepp_lang)

include(cmaize/targets/cmaize_target)
include(cmaize/package_managers/get_package_manager)
include(cmaize/project/package_specification)

#[[[
# Base class for the PackageManager class hierarchy.
Expand Down Expand Up @@ -46,7 +47,7 @@ cpp_class(PackageManager)
# Virtual member function to get the package source and prepare a
# build target.
#]]
cpp_member(fetch_package PackageManager desc PackageSpecification)
cpp_member(get_package PackageManager desc PackageSpecification)
cpp_virtual_member(fetch_package)

#[[[
Expand All @@ -65,7 +66,7 @@ function(_register_package_manager_base_class)

PackageManager(CTOR __package_manager)
register_package_manager("packagemanager" "${__package_manager}")

endfunction()

_register_package_manager_base_class()
1 change: 1 addition & 0 deletions cmake/cmaize/package_managers/package_managers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ include(cmaize/package_managers/get_package_manager)

include(cmaize/package_managers/cmake/cmake)
include(cmaize/package_managers/package_manager)
include(cmaize/package_managers/pip/pip)
59 changes: 59 additions & 0 deletions cmake/cmaize/package_managers/pip/impl_/find_installed.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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/targets/installed_target)

macro(_pip_find_installed self _fi_result _fi_package_specs)

PIPPackageManager(GET "${self}" _fi_py_exe python_executable)

# Unpack the package details we need (for now just the name)
PackageSpecification(GET "${_fi_package_specs}" _fi_name name)

# Ask PIPPackageManager to find a package with the unpacked details. Returns an empty
# string if package matching the details can not be found.
execute_process(
COMMAND "${_fi_py_exe}" "-m" "pip" "list"
COMMAND "grep" "-iw" "${_fi_name}"
ryanmrichard marked this conversation as resolved.
Show resolved Hide resolved
OUTPUT_VARIABLE _fi_matching_modules
)

if("${_fi_matching_modules}" STREQUAL "") # Branch for package not found

set("${_fi_result}" "" PARENT_SCOPE)

else() # Branch for when package is found

if(NOT TARGET "${_fi_name}")
add_library("${_fi_name}" INTERFACE IMPORTED)
endif()

execute_process(
COMMAND "${_fi_py_exe}" "-m" "pip" "show" "${_fi_name}"
COMMAND "grep" "-w" "Location"
ryanmrichard marked this conversation as resolved.
Show resolved Hide resolved
OUTPUT_VARIABLE _fi_install_root
)
string(SUBSTRING "${_fi_install_root}" 10 -1 _fi_install_root)
string(STRIP "${_fi_install_root}" _fi_install_root)

InstalledTarget(
CTOR "${_fi_result}" "${_fi_name}" "${_fi_install_root}"
)
cpp_return("${_fi_result}")

endif()

endmacro()
30 changes: 30 additions & 0 deletions cmake/cmaize/package_managers/pip/impl_/get_package.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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()

macro(_pip_get_package self _gp_result _gp_package_specs)

PIPPackageManager(find_installed "${self}" "${_gp_result}" "${_gp_package_specs}")

if("${_gp_result}" STREQUAL "")
PackageSpecification(GET "${_gp_package_specs}" _gp_name name)
cpp_raise(
PACKAGE_NOT_FOUND "Unable to locate Python module: ${_gp_name}"
)
endif()

cpp_return("${_gp_result}")

endmacro()
26 changes: 26 additions & 0 deletions cmake/cmaize/package_managers/pip/impl_/impl_.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.

#[[[ @module
# Convience module for including the PIP packagemanager's implementations.
#
# Including this module will include the implementations of the PIP class's
# methods. The module is really only intended for inclusion from pip.cmake.
#]]

include_guard()

include(cmaize/package_managers/pip/impl_/find_installed)
include(cmaize/package_managers/pip/impl_/get_package)
include(cmaize/package_managers/pip/impl_/install_package)
26 changes: 26 additions & 0 deletions cmake/cmaize/package_managers/pip/impl_/install_package.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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()

macro(_pip_install_package self _ip_package_specs)

PIPPackageManager(GET "${self}" _ip_py_exe python_executable)
PackageSpecification(GET "${_ip_package_specs}" _ip_name name)
ryanmrichard marked this conversation as resolved.
Show resolved Hide resolved
execute_process(
COMMAND "${_ip_py_exe}" "-m" "pip" "install" "${_ip_name}"
OUTPUT_QUIET
ryanmrichard marked this conversation as resolved.
Show resolved Hide resolved
)

endmacro()
Loading
Loading