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

[vcpkg-cmake-config] Check for CMake package name problems #27568

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions ports/vcpkg-cmake-config/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "vcpkg-cmake-config",
"version-date": "2022-02-06",
"port-version": 1,
"version-date": "2022-10-31",
"documentation": "https://vcpkg.io/en/docs/README.html",
"license": "MIT"
}
24 changes: 24 additions & 0 deletions ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]]
if(remaining_files STREQUAL "")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
endif()

z_vcpkg_cmake_config_fixup_validate("${release_share}")
endfunction()

# Merges link interface library lists for release and debug
Expand Down Expand Up @@ -256,3 +258,25 @@ function(z_vcpkg_cmake_config_fixup_merge out_var release_var debug_var)
endforeach()
set("${out_var}" "${merged_libs}" PARENT_SCOPE)
endfunction()

function(z_vcpkg_cmake_config_fixup_validate prefix)
file(GLOB config_files "${prefix}/*Config.cmake" "${prefix}/*-config.cmake")
foreach(file IN LISTS config_files)
cmake_path(GET file FILENAME filename)
string(REGEX REPLACE "Config.cmake|-config.cmake" "" package_name "${filename}")
string(TOLOWER "${package_name}" expected_stem_lc)
cmake_path(GET file PARENT_PATH parent_path)
cmake_path(GET parent_path FILENAME dir_name)
string(TOLOWER "${dir_name}" dir_name_lc)
string(FIND "${dir_name_lc}" "${expected_stem_lc}" index)
if(NOT index EQUAL "0")
message(SEND_ERROR "Invalid location for CMake package \"${package_name}\": share/${dir_name}/${filename}")
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/usage")
# No warning about vcpkg tool CMake usage heuristics needed if installing proper usage file
elseif(NOT "${dir_name_lc}" STREQUAL "${expected_stem_lc}")
message(WARNING "Valid location for CMake package \"${package_name}\" unsupported by vcpkg CMake usage heuristics: share/${dir_name}/${filename}")
elseif(filename STREQUAL "${package_name}Config.cmake" AND NOT "${dir_name}" STREQUAL "${package_name}")
message(WARNING "Valid location for CMake package \"${package_name}\" unsupported by vcpkg CMake usage heuristics: share/${dir_name}/${filename}")
endif()
endforeach()
endfunction()