From d29646e31904b2b041bba4e2327b8084444e79e9 Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:01:04 -0600 Subject: [PATCH 01/12] Add more verbose outputs to help track CMaize actions --- .../package_managers/cmake/cmake_package_manager.cmake | 7 +++---- .../user_api/dependencies/impl_/find_dependency.cmake | 3 +++ cmake/cmaize/utilities/fetch_and_available.cmake | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake b/cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake index f24b2cb0..8466366d 100644 --- a/cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake +++ b/cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake @@ -132,9 +132,8 @@ cpp_class(CMakePackageManager PackageManager) cpp_map(GET "${_rd_dependencies}" _rd_temp "${_rd_key}") endforeach() + message(VERBOSE "Registering dependency to package manager: ${_rd_pkg_name}") 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") @@ -147,6 +146,8 @@ cpp_class(CMakePackageManager PackageManager) Dependency(init "${_rd_depend}" NAME "${_rd_pkg_name}" ${ARGN}) cpp_map(SET "${_rd_dependencies}" "${_rd_pkg_name}" "${_rd_depend}") + else() + message(VERBOSE "Dependency already registered to package manager: ${_rd_pkg_name}") endif() set("${_rd_result}" "${_rd_depend}") @@ -189,8 +190,6 @@ cpp_class(CMakePackageManager PackageManager) PackageSpecification(GET "${_fi_package_specs}" _fi_pkg_name name) - message(STATUS "Looking for ${_fi_pkg_name}") - CMakePackageManager(register_dependency "${self}" _fi_depend diff --git a/cmake/cmaize/user_api/dependencies/impl_/find_dependency.cmake b/cmake/cmaize/user_api/dependencies/impl_/find_dependency.cmake index 52327d2f..08164bc3 100644 --- a/cmake/cmaize/user_api/dependencies/impl_/find_dependency.cmake +++ b/cmake/cmaize/user_api/dependencies/impl_/find_dependency.cmake @@ -53,12 +53,15 @@ function(_cmaize_find_dependency _fd_tgt _fd_pm _fd_package_specs _fd_project _f _fob_get_package_manager(_fd_pm_tmp "${_fd_project}" "${_fd_pm_name}") message(STATUS "Attempting to find installed ${_fd_name}") + list(APPEND CMAKE_MESSAGE_INDENT " ") # Check if the package is already installed PackageManager(find_installed "${_fd_pm_tmp}" _fd_tgt_tmp "${_fd_package_specs_tmp}" ${ARGN} ) + list(POP_BACK CMAKE_MESSAGE_INDENT) + if(NOT "${_fd_tgt_tmp}" STREQUAL "") message(STATUS "${_fd_name} installation found") CMaizeProject(add_target diff --git a/cmake/cmaize/utilities/fetch_and_available.cmake b/cmake/cmaize/utilities/fetch_and_available.cmake index b598eb63..54dd143a 100644 --- a/cmake/cmaize/utilities/fetch_and_available.cmake +++ b/cmake/cmaize/utilities/fetch_and_available.cmake @@ -31,6 +31,8 @@ include(FetchContent) #]] macro(cmaize_fetch_and_available _faa_name) + message(VERBOSE "Fetching and making \"${_faa_name}\" available") + FetchContent_Declare("${_faa_name}" ${ARGN}) FetchContent_MakeAvailable("${_faa_name}") From 1b11913f0a0c4a92f64baff6995ab749f762a0fc Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:03:11 -0600 Subject: [PATCH 02/12] Update some debug output --- .../package_managers/cmake/cmake_package_manager.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake b/cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake index 8466366d..99adb124 100644 --- a/cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake +++ b/cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake @@ -136,10 +136,8 @@ cpp_class(CMakePackageManager PackageManager) if("${_rd_depend}" STREQUAL "") set(_rd_depend "") if("${ARGN}" MATCHES "github") - message("Creating a GitHub dependency") GitHubDependency(CTOR _rd_depend) else() - message("Creating a Git dependency") GitDependency(CTOR _rd_depend) endif() @@ -260,9 +258,13 @@ cpp_class(CMakePackageManager PackageManager) # Alias the build target as the find_target to unify the API if(NOT TARGET "${_gp_find_target}") + message(DEBUG "Find target does not exist: ${_gp_find_target}") if(NOT "${_gp_find_target}" STREQUAL "${_gp_build_target}") + message(DEBUG "Aliasing build target \"${_gp_build_target}\" as find target \"${_gp_find_target}\"") add_library("${_gp_find_target}" ALIAS "${_gp_build_target}") endif() + else() + message(DEBUG "Find target exists: ${_gp_find_target}") endif() cpp_return("${_gp_result}") From d302f0afca6650c6691ed5f146015910d8b28c0c Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:05:43 -0600 Subject: [PATCH 03/12] Fix type --- cmake/cmaize/targets/build_target.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cmaize/targets/build_target.cmake b/cmake/cmaize/targets/build_target.cmake index 8caa8bcd..352b4b37 100644 --- a/cmake/cmaize/targets/build_target.cmake +++ b/cmake/cmaize/targets/build_target.cmake @@ -64,7 +64,7 @@ cpp_class(BuildTarget CMaizeTarget) # cpp_attr(BuildTarget system_dependencies) #[[[ - # :type List[CMaizeTarget] + # :type: List[desc] # # Targets that are dependencies. #]] From 31e7198243a3e8910dce30a12f0b3135b9dd1820 Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:06:29 -0600 Subject: [PATCH 04/12] Begin abstracting out library details from the CXX targets --- .../targets/cmaize_interface_library.cmake | 58 +++++++++++++++++++ cmake/cmaize/targets/cmaize_library.cmake | 51 ++++++++++++++++ cmake/cmaize/targets/cmaize_target.cmake | 1 + .../targets/cxx_interface_library.cmake | 30 ++++------ cmake/cmaize/targets/cxx_library.cmake | 15 ++++- cmake/cmaize/targets/targets.cmake | 2 + 6 files changed, 135 insertions(+), 22 deletions(-) create mode 100644 cmake/cmaize/targets/cmaize_interface_library.cmake create mode 100644 cmake/cmaize/targets/cmaize_library.cmake diff --git a/cmake/cmaize/targets/cmaize_interface_library.cmake b/cmake/cmaize/targets/cmaize_interface_library.cmake new file mode 100644 index 00000000..d386ff42 --- /dev/null +++ b/cmake/cmaize/targets/cmaize_interface_library.cmake @@ -0,0 +1,58 @@ +# Copyright 2025 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(cmakepp_lang/cmakepp_lang) +include(cmaize/targets/cmaize_target) + + +#[[[ +# Base class for all CMaize libraries. +#]] +cpp_class(CMaizeInterfaceLibrary CMaizeLibrary) + + #[[[ + # Creates a ``CMaizeInterfaceLibrary`` object to manage a target of the given name. + # + # .. note:: + # + # This does not create a corresponding CMake target, + # so any call that should interact with a target will fail if the + # target does not already exist. As a base class with no concrete + # analog, ``CMaizeInterfaceLibrary`` really shouldn't be instantiated aside from + # testing purposes. Instead, create a child with a concrete target + # analog and instantiate that. + # + # :param self: CMaizeInterfaceLibrary object constructed. + # :type self: CMaizeInterfaceLibrary + # :param tgt_name: Name of the target. This should not duplicate any other + # target name already in scope. + # :type tgt_name: desc or target + # + # :returns: ``self`` will be set to the newly constructed ``CMaizeInterfaceLibrary`` + # object. + # :rtype: CMaizeInterfaceLibrary + #]] + cpp_constructor(CTOR CMaizeInterfaceLibrary str) + function("${CTOR}" self _ctor_name) + message(DEBUG "CTOR of CMaizeInterfaceLibrary called for \"${_ctor_name}\"") + + # Set the library type + CMaizeLibrary(CTOR "${self}" "${_ctor_name}") + CMaizeInterfaceLibrary(SET "${self}" type "INTERFACE") + + endfunction() + +cpp_end_class() + diff --git a/cmake/cmaize/targets/cmaize_library.cmake b/cmake/cmaize/targets/cmaize_library.cmake new file mode 100644 index 00000000..8c6ffe70 --- /dev/null +++ b/cmake/cmaize/targets/cmaize_library.cmake @@ -0,0 +1,51 @@ +# Copyright 2025 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(cmakepp_lang/cmakepp_lang) +include(cmaize/targets/cmaize_target) + + +#[[[ +# Base class for all CMaize libraries. +#]] +cpp_class(CMaizeLibrary CMaizeTarget) + + #[[[ + # :type: desc + # + # Library type as defined by in CMake's `add_library + # `__ + # command. + # + # Defaults to the value of BUILD_SHARED_LIBS + #]] + cpp_attr(CMaizeLibrary type "${BUILD_SHARED_LIBS}") + + cpp_constructor(CTOR CMaizeLibrary str) + function("${CTOR}" self _ctor_name) + message(DEBUG "CTOR of CMaizeLibrary called for \"${_ctor_name}\"") + + CMaizeTarget(CTOR "${self}" "${_ctor_name}") + + if(BUILD_SHARED_LIBS) + CMaizeLibrary(SET "${self}" type "SHARED") + else() + CMaizeLibrary(SET "${self}" type "STATIC") + endif() + + endfunction() + +cpp_end_class() + diff --git a/cmake/cmaize/targets/cmaize_target.cmake b/cmake/cmaize/targets/cmaize_target.cmake index 516839f0..08018e7b 100644 --- a/cmake/cmaize/targets/cmaize_target.cmake +++ b/cmake/cmaize/targets/cmaize_target.cmake @@ -51,6 +51,7 @@ cpp_class(CMaizeTarget) #]] cpp_constructor(CTOR CMaizeTarget str) function("${CTOR}" self _ctor_name) + message(DEBUG "CTOR of CMaizeTarget called for \"${_ctor_name}\"") CMaizeTarget(SET "${self}" _name "${_ctor_name}") diff --git a/cmake/cmaize/targets/cxx_interface_library.cmake b/cmake/cmaize/targets/cxx_interface_library.cmake index f8996dd5..11125cf7 100644 --- a/cmake/cmaize/targets/cxx_interface_library.cmake +++ b/cmake/cmaize/targets/cxx_interface_library.cmake @@ -13,9 +13,18 @@ # limitations under the License. include_guard() +include(cmaize/targets/cmaize_interface_library) include(cmaize/targets/cxx_library) -cpp_class(CXXInterfaceLibrary CXXLibrary) +cpp_class(CXXInterfaceLibrary CXXLibrary CMaizeInterfaceLibrary) + + cpp_constructor(CTOR CXXInterfaceLibrary str) + function("${CTOR}" self _ctor_name) + message(DEBUG "CTOR of CMaizeLibrary called for \"${_ctor_name}\"") + + CXXLibrary(CTOR "${self}" "${_ctor_name}") + CMaizeInterfaceLibrary(CTOR "${self}" "${_ctor_name}") + endfunction() #[[[ # Get the access level for the target. @@ -40,25 +49,6 @@ cpp_class(CXXInterfaceLibrary CXXLibrary) endfunction() - #[[[ - # Creates the interface library target with ``add_library()``. - # - # .. note:: - # - # Overrides ``BuildTarget(_create_target``. - # - # :param self: CXXInterfaceLibrary object - # :type self: CXXInterfaceLibrary - #]] - cpp_member(_create_target CXXInterfaceLibrary) - function("${_create_target}" self) - - CXXInterfaceLibrary(target "${self}" _it_name) - - add_library("${_it_name}" INTERFACE) - - endfunction() - #[[[ # CMake doesn't let interface libraries set their public headers, so # this function is a no-op. diff --git a/cmake/cmaize/targets/cxx_library.cmake b/cmake/cmaize/targets/cxx_library.cmake index 258f3a4d..6072d965 100644 --- a/cmake/cmaize/targets/cxx_library.cmake +++ b/cmake/cmaize/targets/cxx_library.cmake @@ -13,9 +13,18 @@ # limitations under the License. include_guard() +include(cmaize/targets/cmaize_library) include(cmaize/targets/cxx_target) -cpp_class(CXXLibrary CXXTarget) +cpp_class(CXXLibrary CXXTarget CMaizeLibrary) + + cpp_constructor(CTOR CXXLibrary str) + function("${CTOR}" self _ctor_name) + message(DEBUG "CTOR of CMaizeLibrary called for \"${_ctor_name}\"") + + CXXTarget(CTOR "${self}" "${_ctor_name}") + CMaizeLibrary(CTOR "${self}" "${_ctor_name}") + endfunction() #[[[ # Creates the library target with ``add_library()``. @@ -34,8 +43,10 @@ cpp_class(CXXLibrary CXXTarget) function("${_create_target}" self) CXXLibrary(target "${self}" _ct_name) + CXXLibrary(GET "${self}" _ct_lib_type type) + message(DEBUG "Library type of \"${_ct_name}\" is \"${_ct_lib_type}\"") - add_library("${_ct_name}") + add_library("${_ct_name}" "${_ct_lib_type}") endfunction() diff --git a/cmake/cmaize/targets/targets.cmake b/cmake/cmaize/targets/targets.cmake index 78112cfc..6122731a 100644 --- a/cmake/cmaize/targets/targets.cmake +++ b/cmake/cmaize/targets/targets.cmake @@ -16,6 +16,8 @@ include_guard() include(cmaize/targets/build_target) include(cmaize/targets/cmaize_target) +include(cmaize/targets/cmaize_library) +include(cmaize/targets/cmaize_interface_library) include(cmaize/targets/cxx_executable) include(cmaize/targets/cxx_interface_library) include(cmaize/targets/cxx_library) From f8aee784ad134052d0f41f7feff9744555a68818 Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:07:20 -0600 Subject: [PATCH 05/12] Add verbose dependency outputs --- .../cmake/dependency/dependency_class.cmake | 12 +++++++++++- .../package_managers/cmake/dependency/git.cmake | 12 ++++++++++++ .../package_managers/cmake/dependency/github.cmake | 11 +++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cmake/cmaize/package_managers/cmake/dependency/dependency_class.cmake b/cmake/cmaize/package_managers/cmake/dependency/dependency_class.cmake index c39dd40f..51e1373d 100644 --- a/cmake/cmaize/package_managers/cmake/dependency/dependency_class.cmake +++ b/cmake/cmaize/package_managers/cmake/dependency/dependency_class.cmake @@ -102,8 +102,8 @@ 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}}") + message(STATUS "Dependency already found") cpp_return("${_fd_found}") endif() @@ -111,6 +111,7 @@ cpp_class(Dependency) Dependency(_SEARCH_PATHS "${self}" _fd_paths) Dependency(GET "${self}" _fd_name name) Dependency(GET "${self}" _fd_version version) + message(VERBOSE "Searching via find_package...") find_package( "${_fd_name}" CONFIG @@ -169,6 +170,15 @@ cpp_class(Dependency) Dependency(SET "${self}" build_target "${_i_BUILD_TARGET}") Dependency(SET "${self}" find_target "${_i_FIND_TARGET}") + message(VERBOSE "Created Dependency") + list(APPEND CMAKE_MESSAGE_INDENT " ") + message(VERBOSE "Name: ${_i_NAME}") + message(VERBOSE "URL: ${_i_URL}") + message(VERBOSE "Version: ${_i_VERSION}") + message(VERBOSE "Build Target: ${_i_BUILD_TARGET}") + message(VERBOSE "Find Target: ${_i_FIND_TARGET}") + list(POP_BACK CMAKE_MESSAGE_INDENT) + endfunction() #[[[ Computes a list of path prefixes which should be used when searching. diff --git a/cmake/cmaize/package_managers/cmake/dependency/git.cmake b/cmake/cmaize/package_managers/cmake/dependency/git.cmake index 5ca97509..8eb74365 100644 --- a/cmake/cmaize/package_managers/cmake/dependency/git.cmake +++ b/cmake/cmaize/package_managers/cmake/dependency/git.cmake @@ -59,6 +59,8 @@ cpp_class(GitDependency Dependency) set("${_bd_var}" "${_bd_val}" CACHE BOOL "" FORCE) endforeach() + message(VERBOSE "Adding \"${_bd_name}\" to build system") + cmaize_fetch_and_available( "${_bd_name}" GIT_REPOSITORY "${_bd_url}.git" @@ -118,6 +120,16 @@ cpp_class(GitDependency Dependency) GitDependency(SET "${self}" find_target "${_i_FIND_TARGET}") GitDependency(SET "${self}" cmake_args "${_i_CMAKE_ARGS}") + message(VERBOSE "Created Git Dependency") + list(APPEND CMAKE_MESSAGE_INDENT " ") + message(VERBOSE "Name: ${_i_NAME}") + message(VERBOSE "URL: ${_i_URL}") + message(VERBOSE "Version: ${_i_VERSION}") + message(VERBOSE "Build Target: ${_i_BUILD_TARGET}") + message(VERBOSE "Find Target: ${_i_FIND_TARGET}") + message(VERBOSE "CMake Args: ${_i_CMAKE_ARGS}") + list(POP_BACK CMAKE_MESSAGE_INDENT) + endfunction() cpp_end_class() diff --git a/cmake/cmaize/package_managers/cmake/dependency/github.cmake b/cmake/cmaize/package_managers/cmake/dependency/github.cmake index 73e40569..465d4528 100644 --- a/cmake/cmaize/package_managers/cmake/dependency/github.cmake +++ b/cmake/cmaize/package_managers/cmake/dependency/github.cmake @@ -166,6 +166,17 @@ cpp_class(GitHubDependency GitDependency) Dependency(SET "${self}" cmake_args "${_i_CMAKE_ARGS}") + message(VERBOSE "Created Git Dependency") + list(APPEND CMAKE_MESSAGE_INDENT " ") + message(VERBOSE "Name: ${_i_NAME}") + message(VERBOSE "URL: ${_i_URL}") + message(VERBOSE "Version: ${_i_VERSION}") + message(VERBOSE "Private: ${_i_PRIVATE}") + message(VERBOSE "Build Target: ${_i_BUILD_TARGET}") + message(VERBOSE "Find Target: ${_i_FIND_TARGET}") + message(VERBOSE "CMake Args: ${_i_CMAKE_ARGS}") + list(POP_BACK CMAKE_MESSAGE_INDENT) + endfunction() cpp_end_class() From db09d57f39b1b6afc1986acb26151419ce6c29ff Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:08:06 -0600 Subject: [PATCH 06/12] Change find_dependency in install config to use the NAME argument --- .../cmake/impl_/generate_package_config.cmake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake/cmaize/package_managers/cmake/impl_/generate_package_config.cmake b/cmake/cmaize/package_managers/cmake/impl_/generate_package_config.cmake index 024aa872..5558c2b2 100644 --- a/cmake/cmaize/package_managers/cmake/impl_/generate_package_config.cmake +++ b/cmake/cmaize/package_managers/cmake/impl_/generate_package_config.cmake @@ -123,19 +123,22 @@ macro( Dependency(GET "${__gpc_dep_obj}" __gpc_dep_build_tgt_name build_target ) + Dependency(GET + "${__gpc_dep_obj}" __gpc_tgt_dep_name name + ) # This determines how the find_dependency call in the config # file should be formatted, based on whether the dependency is # a component of a package or not - if("${__gpc_tgt_deps_i}" STREQUAL "${__gpc_dep_build_tgt_name}") + if("${__gpc_tgt_dep_name}" STREQUAL "${__gpc_dep_build_tgt_name}") string(APPEND __gpc_file_contents - "find_dependency(${__gpc_tgt_deps_i})\n" + "find_dependency(${__gpc_tgt_dep_name})\n" ) else() string(APPEND __gpc_file_contents - "find_dependency(${__gpc_tgt_deps_i} COMPONENTS ${__gpc_dep_build_tgt_name})\n" + "find_dependency(${__gpc_tgt_dep_name} COMPONENTS ${__gpc_dep_build_tgt_name})\n" ) endif() From 4046c0decdab3324bdd194eb549632a7c298c5ca Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:08:47 -0600 Subject: [PATCH 07/12] Add interface library install config generation handling --- .../cmake/impl_/generate_target_config.cmake | 158 +++++++++++------- 1 file changed, 101 insertions(+), 57 deletions(-) diff --git a/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake b/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake index 582a45b4..a01719cf 100644 --- a/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake +++ b/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake @@ -30,8 +30,9 @@ macro(_cpm_generate_target_config_impl __gtc_file_contents " if(TARGET ${__gtc_namespace}${__gtc_target_name}) -return() -endif()") + return() +endif()" + ) string(APPEND __gtc_file_contents "\n\n") string(APPEND @@ -40,28 +41,51 @@ endif()") "\"\${CMAKE_CURRENT_LIST_DIR}/../../..\" ABSOLUTE)\n" ) - BuildTarget(GET "${__gtc_tgt_obj}" __gtc_dep_list depends) - CXXTarget(GET "${__gtc_tgt_obj}" __gtc_cxx_std cxx_standard) - CMaizeTarget(get_property "${__gtc_tgt_obj}" __gtc_version VERSION) - CMaizeTarget(get_property "${__gtc_tgt_obj}" __gtc_so_version SOVERSION) - + # Create IMPORTED library of the correct type + CMaizeLibrary(GET "${__gtc_tgt_obj}" __gtc_lib_type type) string(APPEND __gtc_file_contents " # Create imported target ${__gtc_namespace}${__gtc_target_name} -add_library(${__gtc_namespace}${__gtc_target_name} SHARED IMPORTED) +add_library(${__gtc_namespace}${__gtc_target_name} ${__gtc_lib_type} IMPORTED) +") + + # ----- Start collecting interface target properties ----- + string(APPEND + __gtc_file_contents + " +set_target_properties(${__gtc_namespace}${__gtc_target_name} + PROPERTIES" + ) + + # Add compile features + CXXTarget(GET "${__gtc_tgt_obj}" __gtc_cxx_std cxx_standard) + if(NOT "${__gtc_cxx_std}" STREQUAL "") + string(APPEND + __gtc_file_contents + " + INTERFACE_COMPILE_FEATURES \"cxx_std_${__gtc_cxx_std}\"" + ) + endif() -if(NOT \"${__gtc_cxx_std}\" STREQUAL \"\") - set_target_properties(${__gtc_namespace}${__gtc_target_name} PROPERTIES - INTERFACE_COMPILE_FEATURES \"cxx_std_${__gtc_cxx_std}\" + # Add include directories + # TODO: This should not be hard coded! + string(APPEND + __gtc_file_contents + " + INTERFACE_INCLUDE_DIRECTORIES \"\${PACKAGE_PREFIX_DIR}/include\"" ) -endif() -set_target_properties(${__gtc_namespace}${__gtc_target_name} PROPERTIES -INTERFACE_INCLUDE_DIRECTORIES \"\${PACKAGE_PREFIX_DIR}/include\" -INTERFACE_LINK_LIBRARIES " + string(APPEND + __gtc_file_contents + " + # TODO: Handle different configurations (Release, Debug, etc.) + # Import target \"${__gtc_namespace}${__gtc_target_name}\" for configuration \"???\" + IMPORTED_CONFIGURATIONS RELEASE" ) + # Collect interface link libraries + BuildTarget(GET "${__gtc_tgt_obj}" __gtc_dep_list depends) set(__gtc_interface_link_libraries) foreach(__gtc_dep_i ${__gtc_dep_list}) CMakePackageManager(GET "${self}" __gtc_dep_map dependencies) @@ -78,56 +102,76 @@ INTERFACE_LINK_LIBRARIES " list(APPEND __gtc_interface_link_libraries ${__gtc_dep_find_tgt_name}) endforeach() - string(APPEND - __gtc_file_contents - "\"${__gtc_interface_link_libraries}\" -)\n" - ) - - # Based on the shared library suffix, generate the correct versioned - # library name and soname that CMake will install - if ("${CMAKE_SHARED_LIBRARY_SUFFIX}" STREQUAL ".so") - set(__gtc_libname_w_version - "lib${__gtc_target_name}.so.${__gtc_version}" - ) - set(__gtc_soname "lib${__gtc_target_name}.so.${__gtc_so_version}") - elseif("${CMAKE_SHARED_LIBRARY_SUFFIX}" STREQUAL ".dylib") - set(__gtc_libname_w_version - "lib${__gtc_target_name}.${__gtc_version}.dylib" - ) - set(__gtc_soname - "lib${__gtc_target_name}.${__gtc_so_version}.dylib" - ) - elseif("${CMAKE_SHARED_LIBRARY_SUFFIX}" STREQUAL ".dll") - set(__gtc_libname_w_version - "${__gtc_target_name}.${__gtc_version}.dll" - ) - set(__gtc_soname - "${__gtc_target_name}.${__gtc_so_version}.dll" - ) - else() - string(APPEND __gtc_msg "Shared libraries with the") - string(APPEND __gtc_msg "${CMAKE_SHARED_LIBRARY_SUFFIX} suffix") - string(APPEND __gtc_msg "are not supported yet.") - cpp_raise( - UnsupportedLibraryType - "${__gtc_msg}" + # Add interface link libraries + list(LENGTH __gtc_interface_link_libraries __gtc_link_library_count) + if("${__gtc_link_library_count}" GREATER 0) + string(APPEND + __gtc_file_contents + " + INTERFACE_LINK_LIBRARIES \"${__gtc_interface_link_libraries}\"" ) endif() - CMakePackageManager(GET "${self}" __gtc_lib_prefix library_prefix) + # ----- End of collecting interface properties ----- string(APPEND __gtc_file_contents " +)" + ) + + # TODO: Are there other library types allowed here? Should this condition + # instead be 'NOT "${__gtc_lib_type}" STREQUAL "INTERFACE"'? + if("${__gtc_lib_type}" STREQUAL "SHARED" OR "${__gtc_lib_type}" STREQUAL "STATIC") + # Based on the shared library suffix, generate the correct versioned + # library name and soname that CMake will install + CMaizeTarget(get_property "${__gtc_tgt_obj}" __gtc_version VERSION) + CMaizeTarget(get_property "${__gtc_tgt_obj}" __gtc_so_version SOVERSION) + + if ("${CMAKE_SHARED_LIBRARY_SUFFIX}" STREQUAL ".so") + set(__gtc_libname_w_version + "lib${__gtc_target_name}.so.${__gtc_version}" + ) + set(__gtc_soname "lib${__gtc_target_name}.so.${__gtc_so_version}") + elseif("${CMAKE_SHARED_LIBRARY_SUFFIX}" STREQUAL ".dylib") + set(__gtc_libname_w_version + "lib${__gtc_target_name}.${__gtc_version}.dylib" + ) + set(__gtc_soname + "lib${__gtc_target_name}.${__gtc_so_version}.dylib" + ) + elseif("${CMAKE_SHARED_LIBRARY_SUFFIX}" STREQUAL ".dll") + set(__gtc_libname_w_version + "${__gtc_target_name}.${__gtc_version}.dll" + ) + set(__gtc_soname + "${__gtc_target_name}.${__gtc_so_version}.dll" + ) + else() + string(APPEND __gtc_msg "Shared libraries with the") + string(APPEND __gtc_msg "${CMAKE_SHARED_LIBRARY_SUFFIX} suffix") + string(APPEND __gtc_msg "are not supported yet.") + cpp_raise( + UnsupportedLibraryType + "${__gtc_msg}" + ) + endif() + endif() + + # Populate properties about exported objects if any are created + if("${__gtc_lib_type}" STREQUAL "SHARED" OR "${__gtc_lib_type}" STREQUAL "STATIC") + CMakePackageManager(GET "${self}" __gtc_lib_prefix library_prefix) + string(APPEND + __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 -IMPORTED_LOCATION_RELEASE \"\${_CMAIZE_IMPORT_LOCATION}\" -IMPORTED_SONAME_RELEASE \"${__gtc_soname}\" + +set_target_properties(${__gtc_namespace}${__gtc_target_name} + PROPERTIES + IMPORTED_LOCATION_RELEASE \"\${_CMAIZE_IMPORT_LOCATION}\" + IMPORTED_SONAME_RELEASE \"${__gtc_soname}\" )\n" - ) + ) + endif() string(APPEND __gtc_file_contents From 2d2779a52a601026260bee45abc16c7ec7407eb7 Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 4 Aug 2025 18:57:14 -0600 Subject: [PATCH 08/12] Remove debug statements and add docstring todos --- cmake/cmaize/targets/cmaize_interface_library.cmake | 1 - cmake/cmaize/targets/cmaize_library.cmake | 2 +- cmake/cmaize/targets/cmaize_target.cmake | 1 - cmake/cmaize/targets/cxx_interface_library.cmake | 3 ++- cmake/cmaize/targets/cxx_library.cmake | 3 ++- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake/cmaize/targets/cmaize_interface_library.cmake b/cmake/cmaize/targets/cmaize_interface_library.cmake index d386ff42..5a62c293 100644 --- a/cmake/cmaize/targets/cmaize_interface_library.cmake +++ b/cmake/cmaize/targets/cmaize_interface_library.cmake @@ -46,7 +46,6 @@ cpp_class(CMaizeInterfaceLibrary CMaizeLibrary) #]] cpp_constructor(CTOR CMaizeInterfaceLibrary str) function("${CTOR}" self _ctor_name) - message(DEBUG "CTOR of CMaizeInterfaceLibrary called for \"${_ctor_name}\"") # Set the library type CMaizeLibrary(CTOR "${self}" "${_ctor_name}") diff --git a/cmake/cmaize/targets/cmaize_library.cmake b/cmake/cmaize/targets/cmaize_library.cmake index 8c6ffe70..1b5fe5a5 100644 --- a/cmake/cmaize/targets/cmaize_library.cmake +++ b/cmake/cmaize/targets/cmaize_library.cmake @@ -33,9 +33,9 @@ cpp_class(CMaizeLibrary CMaizeTarget) #]] cpp_attr(CMaizeLibrary type "${BUILD_SHARED_LIBS}") + # TODO: Function doc cpp_constructor(CTOR CMaizeLibrary str) function("${CTOR}" self _ctor_name) - message(DEBUG "CTOR of CMaizeLibrary called for \"${_ctor_name}\"") CMaizeTarget(CTOR "${self}" "${_ctor_name}") diff --git a/cmake/cmaize/targets/cmaize_target.cmake b/cmake/cmaize/targets/cmaize_target.cmake index 08018e7b..516839f0 100644 --- a/cmake/cmaize/targets/cmaize_target.cmake +++ b/cmake/cmaize/targets/cmaize_target.cmake @@ -51,7 +51,6 @@ cpp_class(CMaizeTarget) #]] cpp_constructor(CTOR CMaizeTarget str) function("${CTOR}" self _ctor_name) - message(DEBUG "CTOR of CMaizeTarget called for \"${_ctor_name}\"") CMaizeTarget(SET "${self}" _name "${_ctor_name}") diff --git a/cmake/cmaize/targets/cxx_interface_library.cmake b/cmake/cmaize/targets/cxx_interface_library.cmake index 11125cf7..91c5f2e7 100644 --- a/cmake/cmaize/targets/cxx_interface_library.cmake +++ b/cmake/cmaize/targets/cxx_interface_library.cmake @@ -18,12 +18,13 @@ include(cmaize/targets/cxx_library) cpp_class(CXXInterfaceLibrary CXXLibrary CMaizeInterfaceLibrary) + # TODO: Function doc cpp_constructor(CTOR CXXInterfaceLibrary str) function("${CTOR}" self _ctor_name) - message(DEBUG "CTOR of CMaizeLibrary called for \"${_ctor_name}\"") CXXLibrary(CTOR "${self}" "${_ctor_name}") CMaizeInterfaceLibrary(CTOR "${self}" "${_ctor_name}") + endfunction() #[[[ diff --git a/cmake/cmaize/targets/cxx_library.cmake b/cmake/cmaize/targets/cxx_library.cmake index 6072d965..d8b34186 100644 --- a/cmake/cmaize/targets/cxx_library.cmake +++ b/cmake/cmaize/targets/cxx_library.cmake @@ -18,12 +18,13 @@ include(cmaize/targets/cxx_target) cpp_class(CXXLibrary CXXTarget CMaizeLibrary) + # TODO: Function doc cpp_constructor(CTOR CXXLibrary str) function("${CTOR}" self _ctor_name) - message(DEBUG "CTOR of CMaizeLibrary called for \"${_ctor_name}\"") CXXTarget(CTOR "${self}" "${_ctor_name}") CMaizeLibrary(CTOR "${self}" "${_ctor_name}") + endfunction() #[[[ From de6f202fe48d9dc60177d1f3a0b88b652f419cfe Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Tue, 5 Aug 2025 19:42:45 -0600 Subject: [PATCH 09/12] Add compile definitions to the install config --- .../cmake/impl_/generate_target_config.cmake | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake b/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake index a01719cf..71ad176a 100644 --- a/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake +++ b/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake @@ -68,6 +68,17 @@ set_target_properties(${__gtc_namespace}${__gtc_target_name} ) endif() + # Get interface compile definitions + CMaizeTarget(has_property "${__gtc_tgt_obj}" __gtc_has_interface_compile_definitions INTERFACE_COMPILE_DEFINITIONS) + if(__gtc_has_interface_compile_definitions) + CMaizeTarget(get_property "${__gtc_tgt_obj}" __gtc_interface_compile_definitions INTERFACE_COMPILE_DEFINITIONS) + string(APPEND + __gtc_file_contents + " + INTERFACE_COMPILE_DEFINITIONS \"${__gtc_interface_compile_definitions}\"" + ) + endif() + # Add include directories # TODO: This should not be hard coded! string(APPEND From 0f87e55d5353ab8a31f26845f195304174ec012a Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Fri, 3 Oct 2025 15:48:34 -0600 Subject: [PATCH 10/12] Fix add_library vs add_executable usage in install config --- .../cmake/impl_/generate_target_config.cmake | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake b/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake index 71ad176a..332f278b 100644 --- a/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake +++ b/cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake @@ -41,14 +41,32 @@ endif()" "\"\${CMAKE_CURRENT_LIST_DIR}/../../..\" ABSOLUTE)\n" ) + # Determine library or executable + cpp_type_of(__gtc_tgt_obj_type "${__gtc_tgt_obj}") + cpp_implicitly_convertible( + __gtc_tgt_obj_is_lib "${__gtc_tgt_obj_type}" CMaizeLibrary + ) + # Create IMPORTED library of the correct type - CMaizeLibrary(GET "${__gtc_tgt_obj}" __gtc_lib_type type) - string(APPEND - __gtc_file_contents - " -# Create imported target ${__gtc_namespace}${__gtc_target_name} + if(__gtc_tgt_obj_is_lib) + CMaizeLibrary(GET "${__gtc_tgt_obj}" __gtc_lib_type type) + string(APPEND + __gtc_file_contents + " +# Create imported library target ${__gtc_namespace}${__gtc_target_name} add_library(${__gtc_namespace}${__gtc_target_name} ${__gtc_lib_type} IMPORTED) -") +" + ) + # Assume it is an executable if it isn't a library + else() + string(APPEND + __gtc_file_contents + " +# Create imported executable target ${__gtc_namespace}${__gtc_target_name} +add_executable(${__gtc_namespace}${__gtc_target_name} IMPORTED) +" + ) + endif() # ----- Start collecting interface target properties ----- string(APPEND @@ -58,13 +76,22 @@ set_target_properties(${__gtc_namespace}${__gtc_target_name} PROPERTIES" ) - # Add compile features - CXXTarget(GET "${__gtc_tgt_obj}" __gtc_cxx_std cxx_standard) - if(NOT "${__gtc_cxx_std}" STREQUAL "") + # Add interface compile features + CMaizeTarget(has_property + "${__gtc_tgt_obj}" + __gtc_tgt_obj_has_interface_compile_features + INTERFACE_COMPILE_FEATURES + ) + if(__gtc_tgt_obj_has_interface_compile_features) + CMaizeTarget(get_property + "${__gtc_tgt_obj}" + __gtc_tgt_obj_interface_compile_features + INTERFACE_COMPILE_FEATURES + ) string(APPEND __gtc_file_contents " - INTERFACE_COMPILE_FEATURES \"cxx_std_${__gtc_cxx_std}\"" + INTERFACE_COMPILE_FEATURES \"${__gtc_tgt_obj_interface_compile_features}\"" ) endif() @@ -76,7 +103,7 @@ set_target_properties(${__gtc_namespace}${__gtc_target_name} __gtc_file_contents " INTERFACE_COMPILE_DEFINITIONS \"${__gtc_interface_compile_definitions}\"" - ) + ) endif() # Add include directories From d0121ed27937b44a8df8af1ce203edc7e30f7c0e Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Tue, 21 Oct 2025 16:36:34 -0600 Subject: [PATCH 11/12] Fix typo [no ci] --- cmake/cmaize/user_api/add_library.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/cmaize/user_api/add_library.cmake b/cmake/cmaize/user_api/add_library.cmake index 21bce626..39a555df 100644 --- a/cmake/cmaize/user_api/add_library.cmake +++ b/cmake/cmaize/user_api/add_library.cmake @@ -84,8 +84,8 @@ function(cmaize_add_library _cal_tgt_name) INSTALL_PATH "${_cal_install_path}" ) - # Loop over each dependency. This is currenjtly done by looking - # up the dependencies by name from the CMaizeProect, but later + # Loop over each dependency. This is currently done by looking + # up the dependencies by name from the CMaizeProject, but later # we should make each CMaize target hold references to its # dependencies cpp_get_global(_cal_top_proj CMAIZE_TOP_PROJECT) From 8c5da7a090e024f4147acaf94e9d2705cc097faa Mon Sep 17 00:00:00 2001 From: zachcran <15938371+zachcran@users.noreply.github.com> Date: Mon, 27 Oct 2025 09:54:54 -0600 Subject: [PATCH 12/12] Update docstrings --- .../targets/cmaize_interface_library.cmake | 17 +++++++------ cmake/cmaize/targets/cmaize_library.cmake | 24 +++++++++++++++++-- .../targets/cxx_interface_library.cmake | 14 ++++++++++- cmake/cmaize/targets/cxx_library.cmake | 14 ++++++++++- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/cmake/cmaize/targets/cmaize_interface_library.cmake b/cmake/cmaize/targets/cmaize_interface_library.cmake index 5a62c293..e0e12abb 100644 --- a/cmake/cmaize/targets/cmaize_interface_library.cmake +++ b/cmake/cmaize/targets/cmaize_interface_library.cmake @@ -14,11 +14,13 @@ include_guard() include(cmakepp_lang/cmakepp_lang) -include(cmaize/targets/cmaize_target) +include(cmaize/targets/cmaize_library) #[[[ -# Base class for all CMaize libraries. +# Base class for CMaize interface libraries. Intended to be used as a parent or +# mixin to provide general, programming language-agnostic features for managing +# interface library targets. #]] cpp_class(CMaizeInterfaceLibrary CMaizeLibrary) @@ -26,13 +28,10 @@ cpp_class(CMaizeInterfaceLibrary CMaizeLibrary) # Creates a ``CMaizeInterfaceLibrary`` object to manage a target of the given name. # # .. note:: - # - # This does not create a corresponding CMake target, - # so any call that should interact with a target will fail if the - # target does not already exist. As a base class with no concrete - # analog, ``CMaizeInterfaceLibrary`` really shouldn't be instantiated aside from - # testing purposes. Instead, create a child with a concrete target - # analog and instantiate that. + # + # This does not create a corresponding CMake target, so any call that + # should interact with a target will fail if the target does not + # already exist. # # :param self: CMaizeInterfaceLibrary object constructed. # :type self: CMaizeInterfaceLibrary diff --git a/cmake/cmaize/targets/cmaize_library.cmake b/cmake/cmaize/targets/cmaize_library.cmake index 1b5fe5a5..1a429b87 100644 --- a/cmake/cmaize/targets/cmaize_library.cmake +++ b/cmake/cmaize/targets/cmaize_library.cmake @@ -18,7 +18,9 @@ include(cmaize/targets/cmaize_target) #[[[ -# Base class for all CMaize libraries. +# Base class for all CMaize libraries. Intended to be used as a parent or +# mixin to provide general, programming language-agnostic features for managing +# library targets. #]] cpp_class(CMaizeLibrary CMaizeTarget) @@ -33,7 +35,25 @@ cpp_class(CMaizeLibrary CMaizeTarget) #]] cpp_attr(CMaizeLibrary type "${BUILD_SHARED_LIBS}") - # TODO: Function doc + #[[[ + # Creates a ``CMaizeLibrary`` object to manage a target of the given name. + # + # .. note:: + # + # This does not create a corresponding CMake target, so any call that + # should interact with a target will fail if the target does not + # already exist. + # + # :param self: CMaizeLibrary object constructed. + # :type self: CMaizeLibrary + # :param tgt_name: Name of the target. This should not duplicate any other + # target name already in scope. + # :type tgt_name: desc or target + # + # :returns: ``self`` will be set to the newly constructed ``CMaizeLibrary`` + # object. + # :rtype: CMaizeLibrary + #]] cpp_constructor(CTOR CMaizeLibrary str) function("${CTOR}" self _ctor_name) diff --git a/cmake/cmaize/targets/cxx_interface_library.cmake b/cmake/cmaize/targets/cxx_interface_library.cmake index 91c5f2e7..7c4e4d37 100644 --- a/cmake/cmaize/targets/cxx_interface_library.cmake +++ b/cmake/cmaize/targets/cxx_interface_library.cmake @@ -18,7 +18,19 @@ include(cmaize/targets/cxx_library) cpp_class(CXXInterfaceLibrary CXXLibrary CMaizeInterfaceLibrary) - # TODO: Function doc + #[[[ + # Creates a ``CXXInterfaceLibrary`` object to manage the named target. + # + # :param self: CXXInterfaceLibrary object constructed. + # :type self: CXXInterfaceLibrary + # :param tgt_name: Name of the target. This should not duplicate any other + # target name already in scope. + # :type tgt_name: desc or target + # + # :returns: ``self`` will be set to the newly constructed + # ``CXXInterfaceLibrary`` object. + # :rtype: CXXInterfaceLibrary + #]] cpp_constructor(CTOR CXXInterfaceLibrary str) function("${CTOR}" self _ctor_name) diff --git a/cmake/cmaize/targets/cxx_library.cmake b/cmake/cmaize/targets/cxx_library.cmake index d8b34186..c12bab34 100644 --- a/cmake/cmaize/targets/cxx_library.cmake +++ b/cmake/cmaize/targets/cxx_library.cmake @@ -18,7 +18,19 @@ include(cmaize/targets/cxx_target) cpp_class(CXXLibrary CXXTarget CMaizeLibrary) - # TODO: Function doc + #[[[ + # Creates a ``CXXLibrary`` object to manage the named target. + # + # :param self: CXXLibrary object constructed. + # :type self: CXXLibrary + # :param tgt_name: Name of the target. This should not duplicate any other + # target name already in scope. + # :type tgt_name: desc or target + # + # :returns: ``self`` will be set to the newly constructed + # ``CXXLibrary`` object. + # :rtype: CXXLibrary + #]] cpp_constructor(CTOR CXXLibrary str) function("${CTOR}" self _ctor_name)