vcpkg子包路径批量获取

获取vcpkg 子包的路径,并拼接为set(CMAKE_PREFIX_PATH “拼接路径” )


import os

def find_directories_with_subdirs(root_dir):
    # 构建根目录下的 "packages" 文件夹路径
    root_packages_dir = os.path.join(root_dir, "packages")
    
    # 如果 "packages" 目录不存在,则提前返回
    if not os.path.isdir(root_packages_dir):
        return

    # 初始化一个列表来存储所有匹配的目录路径
    matching_dirs = []
    
    # 定义要排除的目录名称集合
    exclude_dirs = {"detect_compiler_x64-windows", "vcpkg-cmake_x64-windows", "vcpkg-cmake-config_x64-windows"}
    
    # 定义要包含的子目录名称集合
    include_dirs = {"bin", "debug", "include", "lib"}

    # 遍历 "packages" 目录下的所有顶级条目
    for entry in os.listdir(root_packages_dir):
        # 构建每个顶级条目的完整路径
        entry_path = os.path.join(root_packages_dir, entry)
        
        # 如果当前条目是一个目录,并且不在排除列表中
        if os.path.isdir(entry_path) and entry not in exclude_dirs:
            # 将该顶级目录添加到匹配目录列表中
            matching_dirs.append(entry_path)
            
            # 遍历该顶级目录下的所有子目录
            for subentry in os.listdir(entry_path):
                # 构建子目录的完整路径
                subentry_path = os.path.join(entry_path, subentry)
                
                # 如果当前子目录存在,并且其名称在包含列表中
                if os.path.isdir(subentry_path) and subentry in include_dirs:
                    # 将该子目录添加到匹配目录列表中
                    matching_dirs.append(subentry_path)

    # 使用分号连接所有匹配的目录路径
    joined_paths = ';'.join(matching_dirs)
    
    # 按照 CMake 变量设置的格式输出结果
    print(f'set(CMAKE_PREFIX_PATH "{joined_paths}")')

# 要开始遍历的根目录
root_directory = 'C:/Opensource/vcpkg-master'

# 执行函数,找到包含所有指定子目录的目录并输出结果
find_directories_with_subdirs(root_directory)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丁金金

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值