-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccf_3p.cmake
159 lines (142 loc) · 5.17 KB
/
ccf_3p.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Manages a shallow clone as a submodule for dependencies, and ensures unchanged state on the specified commit
# Use DISABLE_CHECKS when local checks are neccessary.
# Usage:
# ccf_3p(dep_name <COMMIT|TAG> <reference> [DISABLE_CHECKS])
find_package(Git REQUIRED)
macro(_ccf_dep_git_fetch)
if(ref_type MATCHES "TAG")
execute_process(COMMAND ${GIT_EXECUTABLE} fetch --depth 1 origin "refs/tags/${ver}:refs/tags/${ver}"
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}/${dep_directory}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
endif()
if(ref_type MATCHES "COMMIT")
execute_process(COMMAND ${GIT_EXECUTABLE} fetch --depth 1 origin "${ver}"
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}/${dep_directory}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
endif()
if(ref_type MATCHES "BRANCH")
execute_process(COMMAND ${GIT_EXECUTABLE} fetch origin master
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}/${dep_directory}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
endif()
if(NOT "${DEP_RESULT}" EQUAL 0)
message(FATAL_ERROR "GIT fetch failed for dep ${_CCF_DEP_NAME}: ${DEP_ERROR}")
endif()
endmacro()
macro(_ccf_dep_git_status)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule status ${dep_directory}
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}"
RESULT_VARIABLE DEP_RESULT
OUTPUT_VARIABLE DEP_OUTPUT
ERROR_VARIABLE DEP_ERROR
)
endmacro()
macro(_ccf_dep_git_init)
execute_process(COMMAND ${GIT_EXECUTABLE} init
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}/${dep_directory}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
if(NOT "${DEP_RESULT}" EQUAL 0)
message(FATAL_ERROR "GIT init failed for dep ${_CCF_DEP_NAME}: ${DEP_ERROR}")
endif()
execute_process(COMMAND ${GIT_EXECUTABLE} remote rm origin
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}/${dep_directory}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
execute_process(COMMAND ${GIT_EXECUTABLE} remote add origin ${_CCF_DEP_REPOSITORY}
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}/${dep_directory}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
if(NOT "${DEP_RESULT}" EQUAL 0)
message(FATAL_ERROR "GIT remote add origin failed for dep ${_CCF_DEP_NAME}: ${DEP_ERROR}")
endif()
execute_process(COMMAND ${GIT_EXECUTABLE} submodule add ${_CCF_DEP_REPOSITORY} ${dep_directory}
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
if(NOT "${DEP_RESULT}" EQUAL 0)
message(FATAL_ERROR "GIT submodule add failed for dep ${_CCF_DEP_NAME}: ${DEP_ERROR}")
endif()
endmacro()
macro(_ccf_dep_git_update)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --depth 1 "${dep_directory}"
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}"
RESULT_VARIABLE DEP_RESULT
ERROR_VARIABLE DEP_ERROR
)
if(NOT "${DEP_RESULT}" EQUAL 0)
message(FATAL_ERROR "GIT update failed for dep ${_CCF_DEP_NAME}: ${DEP_ERROR}")
endif()
endmacro()
macro(_ccf_dep_git_clean)
execute_process(COMMAND ${GIT_EXECUTABLE} clean -xdf .
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}/${dep_directory}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
if(NOT "${DEP_RESULT}" EQUAL 0)
message(FATAL_ERROR "GIT clean failed for dep ${_CCF_DEP_NAME}: ${DEP_ERROR}")
endif()
endmacro()
macro(_ccf_dep_git_checkout_fetchhead)
execute_process(COMMAND ${GIT_EXECUTABLE} checkout FETCH_HEAD
WORKING_DIRECTORY "${CCF_BUILD_SOURCE_DIR}/${dep_directory}"
OUTPUT_QUIET
ERROR_VARIABLE DEP_ERROR
RESULT_VARIABLE DEP_RESULT
)
if(NOT "${DEP_RESULT}" EQUAL 0)
message(FATAL_ERROR "GIT checkout failed for dep ${_CCF_DEP_NAME}: ${DEP_ERROR}")
endif()
endmacro()
macro(ccf_3p_lib_header_only target)
if(NOT EXISTS "${CCF_BUILD_SOURCE_DIR}/${dep_directory}/")
message(FATAL_ERROR "Third party directory doesn't exists: ${CCF_BUILD_SOURCE_DIR}/${dep_directory}/")
endif()
add_library(${target} INTERFACE)
set(_argn_list "${ARGN}")
foreach(arg IN LISTS _argn_list)
if(NOT EXISTS "${CCF_BUILD_SOURCE_DIR}/${dep_directory}/${arg}")
message(FATAL_ERROR "Third party subdirectory doesn't exists: ${CCF_BUILD_SOURCE_DIR}/${dep_directory}/${arg}")
endif()
target_include_directories(${target} INTERFACE "${CCF_BUILD_SOURCE_DIR}/${dep_directory}/${arg}")
endforeach()
endmacro()
# syntax: name <TAG/COMMIT/BRANCH> <ref>
function(ccf_3p a_dep a_ref_type)
string(TOLOWER "${a_dep}" dep)
string(TOUPPER "${a_ref_type}" ref_type)
if(DEFINED "CCF_DEPENDS_${dep}")
# TODO: version checks!
return()
endif()
set(_allowed_values "TAG;COMMIT;BRANCH;DEFAULT")
if (NOT "${ref_type}" IN_LIST _allowed_values)
message(FATAL_ERROR "Unknown reference type for dependency ${dep}: ${ref_type}")
endif()
macro(_ccf_3p_target_callback)
endmacro()
# load the settings we need
include("3p/${dep}")
set(dep_directory "${CCF_DEPENDENCY_SUBDIR}/${_CCF_DEP_NAME}")
set("CCF_DEPENDS_${dep}" ON PARENT_SCOPE)
_ccf_3p_target_callback()
endfunction()