Skip to content
Merged
13 changes: 7 additions & 6 deletions cmake/cmaize/package_managers/cmake/cmake_package_manager.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,20 @@ 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")
GitHubDependency(CTOR _rd_depend)
else()
message("Creating a Git dependency")
GitDependency(CTOR _rd_depend)
endif()

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}")
Expand Down Expand Up @@ -189,8 +188,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
Expand Down Expand Up @@ -261,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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,16 @@ 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()

# Wasn't found so call find_package to look for it.
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
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions cmake/cmaize/package_managers/cmake/dependency/git.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
11 changes: 11 additions & 0 deletions cmake/cmaize/package_managers/cmake/dependency/github.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
196 changes: 139 additions & 57 deletions cmake/cmaize/package_managers/cmake/impl_/generate_target_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,28 +41,89 @@ 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)
# 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
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
__gtc_file_contents
"
# Create imported target ${__gtc_namespace}${__gtc_target_name}
add_library(${__gtc_namespace}${__gtc_target_name} SHARED IMPORTED)
set_target_properties(${__gtc_namespace}${__gtc_target_name}
PROPERTIES"
)

# 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 \"${__gtc_tgt_obj_interface_compile_features}\""
)
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()

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)
Expand All @@ -78,56 +140,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
Expand Down
2 changes: 1 addition & 1 deletion cmake/cmaize/targets/build_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ cpp_class(BuildTarget CMaizeTarget)
# cpp_attr(BuildTarget system_dependencies)

#[[[
# :type List[CMaizeTarget]
# :type: List[desc]
#
# Targets that are dependencies.
#]]
Expand Down
Loading