1
1
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
+ ]]
3
15
function (vcpkg_cmake_module )
4
16
# Set options
5
17
set (_opt )
6
18
set (_single_opt PACKAGE_NAME MODULE_PATH )
7
- set (_multi_opt FILE_LIST DIRECTORY_LIST )
19
+ set (_multi_opt PATH_LIST )
8
20
cmake_parse_arguments (PARSE_ARGV 0 "arg" "${_opt} " "${_single_opt} "
9
21
"${_multi_opt} " )
10
22
@@ -15,9 +27,8 @@ function(vcpkg_cmake_module)
15
27
)
16
28
endif ()
17
29
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" )
21
32
endif ()
22
33
23
34
if (NOT arg_PACKAGE_NAME )
@@ -28,76 +39,39 @@ function(vcpkg_cmake_module)
28
39
set (arg_MODULE_PATH "${arg_PACKAGE_NAME} " )
29
40
endif ()
30
41
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} " )
33
44
set (_export_in_vcpkg_cmake_wrapper
34
- "include_guard(GLOBAL)\n\n list(APPEND CMAKE_MODULE_PATH \$ {CMAKE_CURRENT_LIST_DIR}/${_modules_dir_path } )\n "
45
+ "include_guard(GLOBAL)\n\n list(APPEND CMAKE_MODULE_PATH \$ {CMAKE_CURRENT_LIST_DIR}/${_in_shared_dir_name } )\n "
35
46
)
36
47
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} )
61
56
endif ()
62
57
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
-
89
58
# 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 ()
95
66
96
- file (WRITE ${CURRENT_PACKAGES_DIR} /share/${PORT }/vcpkg-cmake-wrapper.cmake
67
+ file (WRITE ${CURRENT_BUILDTREES_DIR } /vcpkg-cmake-wrapper.cmake
97
68
${_export_in_vcpkg_cmake_wrapper} )
98
69
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 )
101
75
unset (_export_in_vcpkg_cmake_wrapper )
102
76
103
77
endfunction ()
0 commit comments