Skip to content

Commit

Permalink
updates for header-only targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmrichard committed Jan 4, 2024
1 parent 995ca43 commit 75815c3
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 13 deletions.
28 changes: 17 additions & 11 deletions cmake/cmaize/targets/cxx_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ cpp_class(CXXTarget BuildTarget)

CXXTarget(target "${self}" _scf_tgt_name)
CXXTarget(GET "${self}" _scf_cxx_std cxx_standard)
CXXTarget(_access_level "${self}" _scf_access_level)

if(NOT "${_scf_cxx_std}" STREQUAL "")
# The CXX std will always have PUBLIC access
target_compile_features(
"${_scf_tgt_name}"
PUBLIC "cxx_std_${_scf_cxx_std}"
"${_scf_access_level}" "cxx_std_${_scf_cxx_std}"
)
endif()
endfunction()
Expand Down Expand Up @@ -184,27 +184,30 @@ cpp_class(CXXTarget BuildTarget)
endforeach()

# Set up public includes
CXXTarget(_access_level "${self}" _sid_access_level)
foreach(_sid_inc_dir_i ${_sid_inc_dirs})
target_include_directories(
"${_sid_tgt_name}"
PUBLIC
"${_sid_access_level}"
$<BUILD_INTERFACE:${_sid_inc_dir_i}>
)
endforeach()

# Set up installation includes
target_include_directories(
"${_sid_tgt_name}"
PUBLIC
$<INSTALL_INTERFACE:include>
"${_sid_access_level}"
$<INSTALL_INTERFACE:include>
)

# Set up private header includes
target_include_directories(
"${_sid_tgt_name}"
PRIVATE
if(NOT "${_sid_access_level}" STREQUAL "INTERFACE")
# Set up private header includes
target_include_directories(
"${_sid_tgt_name}"
PRIVATE
"${_sid_src_dir}"
)
)
endif()

endfunction()

Expand All @@ -225,9 +228,12 @@ cpp_class(CXXTarget BuildTarget)
# underlying target name
cmaize_replace_project_targets(_sll_deps ${_sll_deps})

CXXTarget(_access_level "${self}" _sll_access_level)
foreach(_sll_dep_i ${_sll_deps})
message(DEBUG "Registering ${_sll_dep_i} as a dependency of ${_sll_name}.")
target_link_libraries("${_sll_name}" PUBLIC "${_sll_dep_i}")
target_link_libraries(
"${_sll_name}" "${_sll_access_level}" "${_sll_dep_i}"
)
endforeach()

endfunction()
Expand Down
15 changes: 13 additions & 2 deletions cmake/cmaize/user_api/add_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,21 @@ function(cmaize_add_library _cal_tgt_name)

# Actually append the aggregated paths to the current target's
# INSTALL_RPATH
CMaizeTarget(get_property "${_cal_tgt_obj}" _install_rpath INSTALL_RPATH)
set(_install_rpath "")

CMaizeTarget(
has_property "${_cal_tgt_obj}" _has_install_rpath INSTALL_RPATH
)
if(_has_install_rpath)
CMaizeTarget(
get_property "${_cal_tgt_obj}" _install_rpath INSTALL_RPATH
)
endif()
list(APPEND _install_rpath ${_dep_install_path})
list(APPEND _install_rpath ${_dep_install_rpath})
CMaizeTarget(set_property "${_cal_tgt_obj}" INSTALL_RPATH "${_install_rpath}")
CMaizeTarget(
set_property "${_cal_tgt_obj}" INSTALL_RPATH "${_install_rpath}"
)
endforeach()

endfunction()
Expand Down
1 change: 1 addition & 0 deletions cmake/cmaize/user_api/dependencies/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ include_guard()
include(cmaize/user_api/dependencies/find_dependency)
include(cmaize/user_api/dependencies/find_optional_dependency)
include(cmaize/user_api/dependencies/find_or_build_dependency)
include(cmaize/user_api/dependencies/find_or_build_optional_dependency)
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()
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()

0 comments on commit 75815c3

Please sign in to comment.