-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
995ca43
commit 75815c3
Showing
5 changed files
with
208 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
cmake/cmaize/user_api/dependencies/find_or_build_optional_dependency.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2024 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/user_api/dependencies/impl_/check_optional_flag) | ||
include(cmaize/user_api/dependencies/find_or_build_dependency) | ||
|
||
#[[[ | ||
# Wraps the process of finding, or building, an optional dependency. | ||
# | ||
# This method is largely the same as cmaize_find_optional_dependency, but | ||
# instead wraps a call to ``cmaize_find_or_build_dependency``. | ||
# | ||
# :param name: The name of the dependency. | ||
# :type name: desc | ||
# :param flag: The variable to use as a flag. Used to name the compile | ||
# definition. | ||
# :type flag: desc | ||
# :param kwargs: Keyword arguments to forward to | ||
# ``cmaize_find_or_build_dependency``. See the documentation for | ||
# ``cmaize_find_or_build_dependency`` for the full list. | ||
#]] | ||
function(cmaize_find_or_build_optional_dependency _cfobod_name _cfobod_flag) | ||
|
||
_check_optional_flag("${_cfobod_flag}") | ||
|
||
if("${${_cfobod_flag}}") | ||
|
||
cmaize_find_or_build_dependency("${_cfobod_name}" ${ARGN}) | ||
target_compile_definitions( | ||
"${_cfobod_name}" INTERFACE "${_cfobod_flag}" | ||
) | ||
|
||
elseif(NOT TARGET "${_cfobod_name}") | ||
|
||
add_library("${_cfobod_name}" INTERFACE) | ||
|
||
endif() | ||
|
||
endfunction() |
125 changes: 125 additions & 0 deletions
125
tests/cmaize/user_api/dependencies/test_find_or_build_optional_dependency.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Copyright 2024 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(cmake_test/cmake_test) | ||
include(cmaize/user_api/cmaize_project) | ||
include(cmaize/user_api/dependencies/find_or_build_optional_dependency) | ||
include(cmaize/user_api/dependencies/impl_/get_package_manager) | ||
include(cmaize/utilities/python) | ||
|
||
ct_add_test(NAME "test_find_or_build_optional_dependency") | ||
function("${test_find_or_build_optional_dependency}") | ||
|
||
find_python(py_exe py_version) | ||
create_virtual_env( | ||
venv_dir | ||
"${py_exe}" | ||
"${CMAKE_BINARY_DIR}" | ||
"${test_find_or_build_optional_dependency}" | ||
) | ||
|
||
# Make sure everything is using the venv Python | ||
set(Python3_EXECUTABLE "${venv_dir}/bin/python3") | ||
|
||
ct_add_section(NAME "is_disabled_empty") | ||
function("${is_disabled_empty}") | ||
|
||
ct_assert_target_does_not_exist(not_real_empty) | ||
|
||
set(ENABLE_NOT_REAL "") | ||
cmaize_find_or_build_optional_dependency(not_real_empty ENABLE_NOT_REAL) | ||
|
||
ct_assert_target_exists(not_real_empty) | ||
get_target_property(target_type not_real_empty TYPE) | ||
ct_assert_equal(target_type "INTERFACE_LIBRARY") | ||
|
||
endfunction() | ||
|
||
ct_add_section(NAME "is_disabled_false") | ||
function("${is_disabled_false}") | ||
|
||
ct_assert_target_does_not_exist(not_real_false) | ||
|
||
set(ENABLE_NOT_REAL FALSE) | ||
cmaize_find_or_build_optional_dependency(not_real_false ENABLE_NOT_REAL) | ||
|
||
ct_assert_target_exists(not_real_false) | ||
|
||
# Verify we can call the function multiple times w/o error | ||
cmaize_find_or_build_optional_dependency(not_real_false ENABLE_NOT_REAL) | ||
|
||
endfunction() | ||
|
||
ct_add_section(NAME "is_enabled_and_not_installed") | ||
function("${is_enabled_and_not_installed}") | ||
|
||
# Create a project | ||
set( | ||
proj_name | ||
"test_find_optional_dependency_is_enabled_and_not_installed" | ||
) | ||
project("${proj_name}") | ||
cmaize_project("${proj_name}") | ||
cpp_get_global(proj_obj CMAIZE_TOP_PROJECT) | ||
|
||
# Create the specification for CMinx | ||
PackageSpecification(CTOR cminx_corr) | ||
PackageSpecification(SET "${cminx_corr}" name "cminx") | ||
|
||
set(ENABLE_CMINX TRUE) | ||
|
||
ct_assert_target_does_not_exist(cminx) | ||
|
||
cmaize_find_or_build_optional_dependency( | ||
cminx | ||
ENABLE_CMINX | ||
PACKAGE_MANAGER pip | ||
) | ||
|
||
ct_assert_target_exists(cminx) | ||
|
||
endfunction() | ||
|
||
ct_add_section(NAME "is_enabled_and_installed") | ||
function("${is_enabled_and_installed}") | ||
|
||
# Create a project | ||
set(proj_name "test_find_optional_dependency_is_enabled_and_installed") | ||
project("${proj_name}") | ||
cmaize_project("${proj_name}") | ||
cpp_get_global(proj_obj CMAIZE_TOP_PROJECT) | ||
|
||
# Create the specification for CMinx | ||
PackageSpecification(CTOR cminx_corr) | ||
PackageSpecification(SET "${cminx_corr}" name "cminx") | ||
|
||
# Install CMinx | ||
_fob_get_package_manager(pm "${proj_obj}" "pip") | ||
PackageManager(install_package "${pm}" "${cminx_corr}") | ||
|
||
set(ENABLE_CMINX TRUE) | ||
|
||
ct_assert_target_does_not_exist(cminx) | ||
|
||
cmaize_find_or_build_optional_dependency( | ||
cminx | ||
ENABLE_CMINX | ||
PACKAGE_MANAGER pip | ||
) | ||
|
||
ct_assert_target_exists(cminx) | ||
|
||
endfunction() | ||
|
||
endfunction() |