Skip to content

Commit c8a9870

Browse files
committed
perf: vcpkg-cmake-module install directories
Signed-off-by: msclock <[email protected]>
1 parent 423a8cc commit c8a9870

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

ports/vcpkg-cmake-module/vcpkg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "vcpkg-cmake-module",
33
"version-date": "2023-10-11",
4+
"port-version": 1,
45
"license": "MIT"
56
}

ports/vcpkg-cmake-module/vcpkg_cmake_module.cmake

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@ function(vcpkg_cmake_module)
2828
set(arg_MODULE_PATH "${arg_PACKAGE_NAME}")
2929
endif()
3030

31-
set(_modules_dir_path "cmake")
31+
set(_modules_dir_path "_modules")
3232
set(_modules_path "${_modules_dir_path}/${arg_MODULE_PATH}")
33+
set(_export_in_vcpkg_cmake_wrapper
34+
"include_guard(GLOBAL)\n\nlist(APPEND CMAKE_MODULE_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_dir_path})\n"
35+
)
36+
string(
37+
APPEND
38+
_export_in_vcpkg_cmake_wrapper
39+
"list(APPEND CMAKE_PREFIX_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_path})\n"
40+
)
3341

3442
if(arg_FILE_LIST)
3543
foreach(_file ${arg_FILE_LIST})
@@ -40,18 +48,51 @@ function(vcpkg_cmake_module)
4048

4149
if(arg_DIRECTORY_LIST)
4250
foreach(_dir "${arg_DIRECTORY_LIST}")
43-
install(
44-
DIRECTORY "${_dir}"
45-
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}/${_modules_path})
51+
if(NOT IS_DIRECTORY ${_dir})
52+
message(
53+
FATAL_ERROR
54+
"DIRECTORY_LIST must pass with directories, error: ${arg_DIRECTORY_LIST}"
55+
)
56+
endif()
57+
58+
get_filename_component(_dir_name ${_dir} NAME_WE)
59+
60+
string(
61+
APPEND
62+
_export_in_vcpkg_cmake_wrapper
63+
"list(APPEND CMAKE_PREFIX_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_path}/${_dir_name})\n"
64+
)
65+
66+
file(
67+
GLOB_RECURSE _dir_itmes
68+
LIST_DIRECTORIES ON
69+
RELATIVE "${_dir}"
70+
"${_dir}/*")
71+
list(FILTER _dir_itmes EXCLUDE REGEX [[^\.]])
72+
message(STATUS ${_dir_itmes})
73+
foreach(_item ${_dir_itmes})
74+
if(IS_DIRECTORY "${_dir}/${_item}")
75+
string(
76+
APPEND
77+
_export_in_vcpkg_cmake_wrapper
78+
"${_export_in_vcpkg_cmake_wrapper}list(APPEND CMAKE_PREFIX_PATH "
79+
"\${CMAKE_CURRENT_LIST_DIR}/${_modules_dir_path}/${_dir_name}/${_item})\n"
80+
)
81+
endif()
82+
endforeach()
83+
84+
# Install as subdir
85+
file(INSTALL ${_dir}
86+
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/${_modules_path}")
87+
4688
endforeach()
4789
endif()
4890

49-
file(
50-
WRITE ${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake
51-
"include_guard(GLOBAL)\n\nlist(APPEND CMAKE_MODULE_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_dir_path})\n"
52-
)
91+
file(WRITE ${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake
92+
${_export_in_vcpkg_cmake_wrapper})
5393

5494
unset(_modules_dir_path)
5595
unset(_modules_path)
96+
unset(_export_in_vcpkg_cmake_wrapper)
5697

5798
endfunction()

versions/baseline.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"vcpkg-cmake-module": {
88
"baseline": "2023-10-11",
9-
"port-version": 0
9+
"port-version": 1
1010
}
1111
}
1212
}

versions/v-/vcpkg-cmake-module.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"versions": [
33
{
44
"version-date": "2023-10-11",
5-
"git-tree": "142c34e22ecfeb0ab76e55fcb196f67e2bbebe25",
6-
"port-version": 0
5+
"git-tree": "852db71c3ded39767390a021f35ff897a16671d9",
6+
"port-version": 1
77
},
88
{
99
"version-date": "2023-10-10",
10-
"git-tree": "5eb5bf9667874adcdf3c454039ac5d693ca314d4",
10+
"git-tree": "852db71c3ded39767390a021f35ff897a16671d9",
1111
"port-version": 0
1212
}
1313
]

0 commit comments

Comments
 (0)