Skip to content

Commit b49c2ee

Browse files
committed
perf: simplify the process of vcpkg-cmake-module
Signed-off-by: msclock <[email protected]>
1 parent e158856 commit b49c2ee

File tree

4 files changed

+47
-68
lines changed

4 files changed

+47
-68
lines changed

ports/vcpkg-cmake-module/vcpkg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vcpkg-cmake-module",
33
"version-date": "2023-10-12",
4-
"port-version": 0,
4+
"port-version": 1,
55
"license": "MIT"
66
}
Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
include_guard(GLOBAL)
2-
2+
#[[
3+
This function install cmake module paths under the target path
4+
share/${PORT}/_modules/${PORT}.
5+
6+
Example:
7+
# some modules under the path `dummy/path`
8+
file(GLOB _paths "dummy/path/*")
9+
vcpkg_cmake_module(PATH_LIST ${_paths})
10+
11+
Note:
12+
Once the function was used, not only path modules would be moved to the
13+
target path, but also a variable ${PORT}_MODULE_PATH would target to it.
14+
]]
315
function(vcpkg_cmake_module)
416
# Set options
517
set(_opt)
618
set(_single_opt PACKAGE_NAME MODULE_PATH)
7-
set(_multi_opt FILE_LIST DIRECTORY_LIST)
19+
set(_multi_opt PATH_LIST)
820
cmake_parse_arguments(PARSE_ARGV 0 "arg" "${_opt}" "${_single_opt}"
921
"${_multi_opt}")
1022

@@ -15,9 +27,8 @@ function(vcpkg_cmake_module)
1527
)
1628
endif()
1729

18-
if(NOT arg_FILE_LIST AND NOT arg_DIRECTORY_LIST)
19-
message(
20-
FATAL_ERROR "Both arg_FILE_LIST and arg_DIRECTORY_LIST cannot be empty")
30+
if(NOT arg_PATH_LIST)
31+
message(FATAL_ERROR "PATH_LIST cannot be empty")
2132
endif()
2233

2334
if(NOT arg_PACKAGE_NAME)
@@ -28,76 +39,39 @@ function(vcpkg_cmake_module)
2839
set(arg_MODULE_PATH "${arg_PACKAGE_NAME}")
2940
endif()
3041

31-
set(_modules_dir_path "_modules")
32-
set(_modules_path "${_modules_dir_path}/${arg_MODULE_PATH}")
42+
set(_in_shared_dir_name "_modules")
43+
set(_modules_root "${_in_shared_dir_name}/${arg_MODULE_PATH}")
3344
set(_export_in_vcpkg_cmake_wrapper
34-
"include_guard(GLOBAL)\n\nlist(APPEND CMAKE_MODULE_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_dir_path})\n"
45+
"include_guard(GLOBAL)\n\nlist(APPEND CMAKE_MODULE_PATH \${CMAKE_CURRENT_LIST_DIR}/${_in_shared_dir_name})\n"
3546
)
3647
string(
37-
APPEND
38-
_export_in_vcpkg_cmake_wrapper
39-
"list(APPEND CMAKE_PREFIX_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_path})\n"
40-
)
41-
42-
if(arg_FILE_LIST)
43-
foreach(_file ${arg_FILE_LIST})
44-
file(INSTALL "${_file}"
45-
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}/${_modules_path})
46-
endforeach()
47-
endif()
48-
49-
if(arg_DIRECTORY_LIST)
50-
# Delete tail "/"
51-
if(arg_DIRECTORY_LIST MATCHES [[(/$)]])
52-
string(REGEX REPLACE [[(/$)]] "" arg_DIRECTORY_LIST ${arg_DIRECTORY_LIST})
53-
endif()
54-
55-
foreach(_dir "${arg_DIRECTORY_LIST}")
56-
if(NOT IS_DIRECTORY ${_dir})
57-
message(
58-
FATAL_ERROR
59-
"DIRECTORY_LIST must pass with directories, error: ${arg_DIRECTORY_LIST}"
60-
)
48+
APPEND _export_in_vcpkg_cmake_wrapper
49+
"set(${PORT}_MODULE_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_root})\n")
50+
51+
foreach(_path ${arg_PATH_LIST})
52+
if(IS_DIRECTORY ${_path})
53+
# Delete tail "/"
54+
if(_path MATCHES [[(/$)]])
55+
string(REGEX REPLACE [[(/$)]] "" _path ${_path})
6156
endif()
6257

63-
get_filename_component(_dir_name ${_dir} NAME_WE)
64-
65-
string(
66-
APPEND
67-
_export_in_vcpkg_cmake_wrapper
68-
"list(APPEND CMAKE_PREFIX_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_path}/${_dir_name})\n"
69-
)
70-
71-
file(
72-
GLOB_RECURSE _dir_itmes
73-
LIST_DIRECTORIES ON
74-
RELATIVE "${_dir}"
75-
"${_dir}/*")
76-
77-
list(FILTER _dir_itmes EXCLUDE REGEX [[^\.]])
78-
79-
foreach(_item ${_dir_itmes})
80-
if(IS_DIRECTORY "${_dir}/${_item}")
81-
string(
82-
APPEND
83-
_export_in_vcpkg_cmake_wrapper
84-
"list(APPEND CMAKE_PREFIX_PATH \${CMAKE_CURRENT_LIST_DIR}/${_modules_path}/${_dir_name}/${_item})\n"
85-
)
86-
endif()
87-
endforeach()
88-
8958
# Install as subdir
90-
file(INSTALL ${_dir}
91-
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/${_modules_path}")
92-
93-
endforeach()
94-
endif()
59+
file(INSTALL ${_path}
60+
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/${_modules_root}")
61+
else()
62+
file(INSTALL "${_path}"
63+
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}/${_modules_root})
64+
endif()
65+
endforeach()
9566

96-
file(WRITE ${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake
67+
file(WRITE ${CURRENT_BUILDTREES_DIR}/vcpkg-cmake-wrapper.cmake
9768
${_export_in_vcpkg_cmake_wrapper})
9869

99-
unset(_modules_dir_path)
100-
unset(_modules_path)
70+
file(INSTALL ${CURRENT_BUILDTREES_DIR}/vcpkg-cmake-wrapper.cmake
71+
DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
72+
73+
unset(_in_shared_dir_name)
74+
unset(_modules_root)
10175
unset(_export_in_vcpkg_cmake_wrapper)
10276

10377
endfunction()

versions/baseline.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"vcpkg-cmake-module": {
1212
"baseline": "2023-10-12",
13-
"port-version": 0
13+
"port-version": 1
1414
}
1515
}
1616
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"versions": [
3+
{
4+
"version-date": "2023-10-12",
5+
"git-tree": "cdf26306382be473de7c7eb6def1047fa532714a",
6+
"port-version": 1
7+
},
38
{
49
"version-date": "2023-10-12",
510
"git-tree": "57601bc2fb34fb23d9d2213dc3b8c58a526d15a7",

0 commit comments

Comments
 (0)