WSJT-X/samples/CMakeLists.txt
Bill Somerville 7e8579594f Some helpful developer documentation
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6310 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
2015-12-24 13:19:54 +00:00

123 lines
3.5 KiB
CMake

set (SAMPLE_FILES
JT9+JT65/130610_2343.wav
JT9/130418_1742.wav
)
set_directory_properties (PROPERTIES EXCLUDE_FROM_ALL ON)
set (contents_file_ ${CMAKE_CURRENT_BINARY_DIR}/contents_${WSJTX_VERSION_MAJOR}.${WSJTX_VERSION_MINOR}.json)
function (indent_)
foreach (temp_ RANGE ${level_})
file (APPEND ${contents_file_} " ")
endforeach ()
endfunction ()
function (end_entry_)
file (APPEND ${contents_file_} "\n")
set(first_ 0 PARENT_SCOPE)
math (EXPR level_ "${level_} - 1")
indent_ ()
file (APPEND ${contents_file_} "]\n")
math (EXPR level_ "${level_} - 2")
indent_ ()
file (APPEND ${contents_file_} "}")
string (FIND "${dirs_}" "${cwd_}" pos_)
set (level_ ${level_} PARENT_SCOPE)
endfunction ()
file (WRITE ${contents_file_} "[")
set (cwd_)
set (level_ 0)
set (first_ 1)
list (SORT SAMPLE_FILES)
foreach (sample_ IN LISTS SAMPLE_FILES)
string (REGEX MATCHALL "[^/]*/" dirs_ "${sample_}")
string (REPLACE "/" "" dirs_ "${dirs_}")
string (REGEX MATCH "[^/]*$" name_ "${sample_}")
string (FIND "${dirs_}" "${cwd_}" pos_)
list (LENGTH cwd_ cwd_count_)
if (${pos_} EQUAL 0)
# same root
while (${cwd_count_} GREATER 0)
list (REMOVE_AT dirs_ 0)
math (EXPR cwd_count_ "${cwd_count_} - 1")
endwhile ()
else ()
# reduce cwd_ until matched
while ((NOT ${pos_} EQUAL 0) AND ${cwd_count_} GREATER 0)
math (EXPR cwd_count_ "${cwd_count_} - 1")
list (REMOVE_AT cwd_ ${cwd_count_})
end_entry_ ()
endwhile ()
# back to same root
while (${cwd_count_} GREATER 0)
list (REMOVE_AT dirs_ 0)
math (EXPR cwd_count_ "${cwd_count_} - 1")
endwhile ()
endif ()
list (LENGTH cwd_ cwd_count_)
list (LENGTH dirs_ path_count_)
while (${path_count_} GREATER 0)
list (GET dirs_ 0 dir_)
list (APPEND cwd_ "${dir_}")
list (REMOVE_AT dirs_ 0)
if (${first_})
file (APPEND ${contents_file_} "\n")
set (first 0)
else ()
file (APPEND ${contents_file_} ",\n")
endif ()
indent_ ()
file (APPEND ${contents_file_} "{\n")
math (EXPR level_ "${level_} + 1")
indent_ ()
file (APPEND ${contents_file_} "\"type\": \"directory\",\n")
indent_ ()
file (APPEND ${contents_file_} "\"name\": \"${dir_}\",\n")
indent_ ()
file (APPEND ${contents_file_} "\"entries\": [")
set (first_ 1)
math (EXPR level_ "${level_} + 2")
math (EXPR path_count_ "${path_count_} - 1")
endwhile ()
file (COPY ${sample_} DESTINATION web/samples/${cwd_})
if (${first_})
file (APPEND ${contents_file_} "\n")
set (first 0)
else ()
file (APPEND ${contents_file_} ",\n")
endif ()
indent_ ()
file (APPEND ${contents_file_} "{\n")
math (EXPR level_ "${level_} + 1")
indent_ ()
file (APPEND ${contents_file_} "\"type\": \"file\",\n")
indent_ ()
file (APPEND ${contents_file_} "\"name\": \"${name_}\"\n")
math (EXPR level_ "${level_} - 1")
indent_ ()
file (APPEND ${contents_file_} "}")
set (first_ 0)
endforeach ()
if (${level_} GREATER 1)
end_entry_ ()
endif ()
file (APPEND ${contents_file_} "\n]\n")
file (COPY ${contents_file_} DESTINATION web/samples)
find_program (RSYNC_EXECUTABLE rsync)
if (RSYNC_EXECUTABLE)
add_custom_command (
OUTPUT upload.timestamp
COMMAND ${RSYNC_EXECUTABLE} ARGS -avz --progress ${CMAKE_CURRENT_BINARY_DIR}/web/samples ${PROJECT_SAMPLES_UPLOAD_DEST}
COMMAND ${CMAKE_COMMAND} ARGS -E touch upload.timestamp
DEPENDS ${contents_file_} ${SAMPLE_FILES}
COMMENT "Uploading WSJT-X samples to web server"
)
add_custom_target (upload-samples DEPENDS upload.timestamp)
endif ()