| 1 |
# Common code used across the different tests |
| 2 |
|
| 3 |
if(NOT DEFINED CBINDGEN_PATH) |
| 4 |
message(FATAL_ERROR "Path to cbindgen not specified") |
| 5 |
endif() |
| 6 |
|
| 7 |
# Promote to cache |
| 8 |
set(CBINDGEN_PATH "${CBINDGEN_PATH}" CACHE INTERNAL "") |
| 9 |
|
| 10 |
function(add_cbindgen_command custom_target_name header_destination) |
| 11 |
# Place the depfile always at the same location, so the outer test framework can locate the file easily |
| 12 |
set(depfile_destination "${CMAKE_BINARY_DIR}/depfile.d") |
| 13 |
add_custom_command( |
| 14 |
OUTPUT |
| 15 |
"${header_destination}" "${depfile_destination}" |
| 16 |
COMMAND |
| 17 |
"${CBINDGEN_PATH}" |
| 18 |
--output "${header_destination}" |
| 19 |
--depfile "${depfile_destination}" |
| 20 |
${ARGN} |
| 21 |
DEPFILE "${depfile_destination}" |
| 22 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 23 |
COMMENT "Running cbindgen" |
| 24 |
COMMAND_EXPAND_LISTS |
| 25 |
) |
| 26 |
add_custom_target("${custom_target_name}" ALL DEPENDS "${header_destination}") |
| 27 |
endfunction() |