include_guard() # # Functions to generate a script that will generate the # mainpage.dox file for Doxygen # # from the list of all targets we get the lists of: # - applications (aka executables) # - scripts # - examples. # # For each case we generate a header section with a bare list of links and # a section with details obtained by executing the binary with -v # option (if/when available) # include(JPPGetTargetLists) # add echo at the start of each line in the input list # except for the lines starting with ":" # for those line ":xxxx" the colon is stripped (i.e. only xxxx is # transmitted to the output lis) # macro(jpp_prefix_with_echo input output) foreach(line ${input}) if(NOT "${line}" MATCHES "^:") list(APPEND ${output} "echo '${line}'") else() string(SUBSTRING "${line}" 1 -1 command) list(APPEND ${output} ${command}) endif() endforeach() endmacro() macro(jpp_generate_mainpage_header output) # the top of the mainpage, with some styling list(APPEND output ":function generate_main_page() {") list(APPEND output "@mainpage") list(APPEND output "@htmlonly") list(APPEND output "") endmacro() function(jpp_get_link element) cmake_parse_arguments(PARSE_ARGV 1 A "" "HREF;NAME;ANCHOR;PREFIX" "") if(A_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS}") endif() if(NOT A_HREF) message(FATAL_ERROR "Missing argument HREF") endif() if(NOT A_ANCHOR) message(FATAL_ERROR "Missing argument ANCHOR") endif() set(anchor) if(TARGET ${element}) jpp_get_target_info(${element} EXE exe) get_property(is_document TARGET ${element} PROPERTY KM3NET_JPP_DOCUMENT) if(is_document) get_property(package TARGET ${element} PROPERTY KM3NET_JPP_PACKAGE) set(href "${package}/${exe}") else() set(anchor "#") set(href "${A_PREFIX}${exe}") endif() if(A_NAME) cmake_path(GET exe FILENAME filename) set(name ${filename}) endif() else() cmake_path(GET element FILENAME source) set(anchor "#") set(href "${element}") if(A_NAME) set(name ${source}) endif() endif() set(${A_HREF} "${href}" PARENT_SCOPE) set(${A_NAME} ${name} PARENT_SCOPE) set(${A_ANCHOR} ${anchor} PARENT_SCOPE) endfunction() # generate a list of links from the list of targets function(jpp_generate_table_of_content) cmake_parse_arguments(PARSE_ARGV 0 A "" "HTML;CLASSNAME;PREFIX" "ITEMS") set(items) if(A_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS}") endif() if(NOT A_CLASSNAME) set(A_CLASSNAME b) endif() list(APPEND items "") set(${A_HTML} ${items} PARENT_SCOPE) endfunction() function(jpp_get_target_info target) cmake_parse_arguments(PARSE_ARGV 1 A "" "EXE;SOURCE;RUN" "") if(A_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS}") endif() get_property(is_script TARGET ${target} PROPERTY KM3NET_JPP_SCRIPT) get_property(is_document TARGET ${target} PROPERTY KM3NET_JPP_DOCUMENT) set(base "$,${CMAKE_SOURCE_DIR}>/") if(is_script OR is_document) set(exe $) set(src "${base}${exe}") set(run "$/${exe} -h | html_escape") else() set(exe "$") set(sources "$") set(src $) set(run "($ -h! 2> /dev/null || $ -h 2> /dev/null) | html_escape") endif() if(A_EXE) set(${A_EXE} ${exe} PARENT_SCOPE) endif() if(A_SOURCE) set(${A_SOURCE} ${src} PARENT_SCOPE) endif() if(A_RUN) set(${A_RUN} ${run} PARENT_SCOPE) endif() endfunction() # generate the details (aka content) part for a list of targets # function(jpp_generate_details) cmake_parse_arguments(PARSE_ARGV 0 A "" "HTML;PREFIX" "TARGETS") if(A_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS}") endif() set(details) list(APPEND details "
") foreach(target IN LISTS A_TARGETS) jpp_get_target_info(${target} SOURCE src EXE exe RUN run) list(APPEND details "

") list(APPEND details "@endhtmlonly") if("${exe}" STREQUAL "${src}") list(APPEND details "${exe}") else() list(APPEND details "${exe} ($)") endif() list(APPEND details "@htmlonly") list(APPEND details "

") list(APPEND details "
")
    list(APPEND details ":${run}")
    list(APPEND details "
") list(APPEND details "Go back to top of page.") endforeach() set(${A_HTML} ${details} PARENT_SCOPE) endfunction() # generate the header and details in a two level structure # e.g. for the list : # category/package/a # category/package/b # category/package/c # will generate a header part with a link to anchor #category/package # and a detail part with details for a, b, c # (where category is software, examples or tests) # function(jpp_generate_header_and_details) cmake_parse_arguments(PARSE_ARGV 0 A "" "TITLE;HEADER;DETAILS;CATEGORY" "TARGETS") if(A_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS}") endif() list(LENGTH A_TARGETS nofTargets) if(NOT A_CATEGORY) set(A_CATEGORY examples/) endif() set(tocCategories) set(header) set(details) set(softdir ${PROJECT_SOURCE_DIR}/software) # get the list of possible packages = subdirectories of software get_property(packages DIRECTORY ${softdir} PROPERTY SUBDIRECTORIES) list(TRANSFORM packages REPLACE "${softdir}/" "") list(APPEND header "
${A_TITLE} (${nofTargets})") foreach(pkg IN LISTS packages) set(pkg_targets) foreach(target IN LISTS A_TARGETS) get_property(target_package TARGET ${target} PROPERTY KM3NET_JPP_PACKAGE) if("${target_package}" STREQUAL "${pkg}") list(APPEND pkg_targets ${target}) endif() endforeach() list(LENGTH pkg_targets nofPkgTargets) if(${nofPkgTargets} GREATER 0) set(id "${A_CATEGORY}${pkg}") list(APPEND tocCategories "${id}") list(APPEND details "
${pkg} (${nofPkgTargets})") set(prefix ${A_CATEGORY}) jpp_generate_table_of_content(ITEMS ${pkg_targets} HTML pkg_header PREFIX ${prefix}) list(APPEND details ${pkg_header}) jpp_generate_details(TARGETS ${pkg_targets} HTML pkg_details PREFIX ${prefix}) list(APPEND details ${pkg_details}) list(APPEND details "
") endif() endforeach() jpp_generate_table_of_content(ITEMS ${tocCategories} HTML htmlTocCategories) list(APPEND header ${htmlTocCategories}) list(APPEND header "
") set(${A_HEADER} ${header} PARENT_SCOPE) set(${A_DETAILS} ${details} PARENT_SCOPE) endfunction() # generate the mainpage script function(jpp_generate_mainpage_script outputdox) set(output) jpp_generate_mainpage_header(output) jpp_get_list_of_documents(documents) list(LENGTH documents nofDocuments) jpp_generate_table_of_content(ITEMS ${documents} HTML doc_header) jpp_get_list_of_applications(apps) list(LENGTH apps nofApps) jpp_generate_table_of_content(ITEMS ${apps} HTML app_header) jpp_generate_details(TARGETS ${apps} HTML app_details) jpp_get_list_of_scripts(scripts) list(LENGTH scripts nofScripts) jpp_generate_table_of_content(ITEMS ${scripts} HTML script_header) jpp_generate_details(TARGETS ${scripts} HTML script_details) jpp_get_list_of_examples(examples) jpp_generate_header_and_details(TITLE Examples TARGETS ${examples} HEADER example_header DETAILS example_details) list(APPEND output "
") list(APPEND output "
Documents (${nofDocuments})") list(APPEND output ${doc_header}) list(APPEND output "
") list(APPEND output "
") list(APPEND output "
Applications (${nofApps})") list(APPEND output ${app_header}) list(APPEND output "
") list(APPEND output "
") list(APPEND output "
Scripts (${nofScripts})") list(APPEND output ${script_header}) list(APPEND output "
") list(APPEND output "
") list(APPEND output ${example_header}) list(APPEND output ${app_details}) list(APPEND output ${script_details}) list(APPEND output ${example_details}) list(APPEND output "@endhtmlonly") list(APPEND output ":}") list(APPEND output ":export JPP_DIR=${KM3NET_JPP_STAGE_DIR}") list(APPEND output ":export PATH=$ENV{PATH}:${KM3NET_JPP_STAGE_DIR}/bin") list(APPEND output ":source ${KM3NET_JPP_STAGE_DIR}/setenv.sh > /dev/null") list(APPEND output ":echo \"/**\" > ${outputdox}") list(APPEND output ":generate_main_page | sed 's/^/ * /' >> ${outputdox}") list(APPEND output ":echo \"**/\" >> ${outputdox}") jpp_prefix_with_echo("${output}" tmp) list(JOIN tmp "\n" lines) set(html_escape [[ function html_escape() { sed 's//\>/g' } ]]) file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mainpage.sh CONTENT "#!/bin/zsh\n${html_escape}\n${lines}\n" FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endfunction() jpp_generate_mainpage_script("${CMAKE_CURRENT_BINARY_DIR}/mainpage.dox")