]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #[===[.md: |
2 | # vcpkg_copy_pdbs | |
3 | ||
4 | Automatically locate pdbs in the build tree and copy them adjacent to all DLLs. | |
5 | ||
6 | ```cmake | |
7 | vcpkg_copy_pdbs( | |
8 | [BUILD_PATHS <glob>...]) | |
9 | ``` | |
10 | ||
11 | The `<glob>`s are patterns which will be passed to `file(GLOB_RECURSE)`, | |
12 | for locating DLLs. It defaults to using: | |
13 | ||
14 | - `${CURRENT_PACKAGES_DIR}/bin/*.dll` | |
15 | - `${CURRENT_PACKAGES_DIR}/debug/bin/*.dll` | |
16 | ||
17 | since that is generally where DLLs are located. | |
18 | ||
19 | ## Notes | |
20 | This command should always be called by portfiles after they have finished rearranging the binary output. | |
21 | ||
22 | ## Examples | |
23 | ||
24 | * [zlib](https://github.com/Microsoft/vcpkg/blob/master/ports/zlib/portfile.cmake) | |
25 | * [cpprestsdk](https://github.com/Microsoft/vcpkg/blob/master/ports/cpprestsdk/portfile.cmake) | |
26 | #]===] | |
27 | function(vcpkg_copy_pdbs) | |
28 | cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "" "BUILD_PATHS") | |
29 | ||
30 | if(NOT DEFINED arg_BUILD_PATHS) | |
31 | set( | |
32 | arg_BUILD_PATHS | |
33 | "${CURRENT_PACKAGES_DIR}/bin/*.dll" | |
34 | "${CURRENT_PACKAGES_DIR}/debug/bin/*.dll" | |
35 | ) | |
36 | endif() | |
37 | ||
38 | set(dlls_without_matching_pdbs) | |
39 | ||
40 | if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" AND VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) | |
41 | file(GLOB_RECURSE dlls ${arg_BUILD_PATHS}) | |
42 | ||
43 | set(vslang_backup "$ENV{VSLANG}") | |
44 | set(ENV{VSLANG} 1033) | |
45 | ||
46 | foreach(dll IN LISTS dlls) | |
47 | execute_process(COMMAND dumpbin /PDBPATH ${dll} | |
48 | COMMAND findstr PDB | |
49 | OUTPUT_VARIABLE pdb_line | |
50 | ERROR_QUIET | |
51 | RESULT_VARIABLE error_code | |
52 | ) | |
53 | ||
54 | if(NOT error_code AND pdb_line MATCHES "PDB file found at") | |
55 | string(REGEX MATCH [['.*']] pdb_path "${pdb_line}") # Extract the path which is in single quotes | |
56 | string(REPLACE "'" "" pdb_path "${pdb_path}") # Remove single quotes | |
57 | get_filename_component(dll_dir "${dll}" DIRECTORY) | |
58 | file(COPY "${pdb_path}" DESTINATION "${dll_dir}") | |
59 | else() | |
60 | list(APPEND dlls_without_matching_pdbs "${dll}") | |
61 | endif() | |
62 | endforeach() | |
63 | ||
64 | set(ENV{VSLANG} "${vslang_backup}") | |
65 | ||
66 | list(LENGTH dlls_without_matching_pdbs unmatched_dlls_length) | |
67 | if(unmatched_dlls_length GREATER 0) | |
68 | list(JOIN dlls_without_matching_pdbs "\n " message) | |
69 | message(WARNING "Could not find a matching pdb file for:${message}\n") | |
70 | endif() | |
71 | endif() | |
72 | ||
73 | endfunction() |