# Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin # SPDX-License-Identifier: BSD-3-Clause # # -------------------------------------------------------------------------- # $Maintainer: Timo Sachsenberg $ # $Authors: Timo Sachsenberg $ # -------------------------------------------------------------------------- # Declaration of TOPP tools, and generation of the tool registry from those declarations. # # openms_topp_tool( ) is the single place a TOPP tool is declared. It says # both that the tool exists (so the build produces it) and which category TOPPAS groups it # under (so ToolHandler can list it). The registry of this add-on, # share/OpenMS/TOOLS/MetaProSIP.tsv, is written from these declarations by # openms_write_tool_registry() (see src/CMakeLists.txt). ToolHandler reads every *.tsv in # that directory, so installed next to the core's OpenMS.tsv it adds MetaProSIP. # # A copy of cmake/topp_tool_macros.cmake of the OpenMS core, which its installation does not # ship yet (https://github.com/OpenMS/OpenMS/issues/11035). Keep it in step with the core # until the core exports it, then use the exported one instead. #------------------------------------------------------------------------------ # Forget the tools of an earlier configure of this build directory. # # The declarations accumulate in cache variables so that they survive the directory scopes # they are made in (src/topp). # Cache variables also survive a reconfigure, so without this every configure would append # the whole list again. function(openms_reset_topp_tools) set(TOPP_TOOLS "" CACHE INTERNAL "OpenMS' TOPP tools" FORCE) set(TOPP_TOOL_CATEGORIES "" CACHE INTERNAL "TOPPAS category of the entry of TOPP_TOOLS at the same index" FORCE) endfunction() #------------------------------------------------------------------------------ # openms_topp_tool( ) # # @param Name the tool, built from .cpp or from the subdirectory / # @param Category the TOPPAS category, e.g. "Quantitation". Mirror the set of categories in # doc/doxygen/public/TOPP.doxygen. function(openms_topp_tool name category) if(ARGN) message(FATAL_ERROR "openms_topp_tool(${name}): unexpected arguments '${ARGN}'. Usage: openms_topp_tool( )") endif() if("${name}" STREQUAL "") message(FATAL_ERROR "openms_topp_tool(): the tool name may not be empty") endif() if("${category}" STREQUAL "") message(FATAL_ERROR "openms_topp_tool(${name}): a category is required; it is what TOPPAS groups the tool under") endif() if(name IN_LIST TOPP_TOOLS) message(FATAL_ERROR "openms_topp_tool(${name}): this tool is already declared. ToolHandler refuses to start any " "tool when a name is registered twice, so the duplicate is rejected here instead.") endif() ## Some workflow systems read a slash in a category as a subcategory separator. if(category MATCHES "/") message(FATAL_ERROR "openms_topp_tool(${name}): the category '${category}' contains a '/', which some workflow " "systems read as a subcategory separator. Use a plain category name.") endif() ## ';' would split the entry into two list elements and desynchronize it from TOPP_TOOLS. if(category MATCHES ";") message(FATAL_ERROR "openms_topp_tool(${name}): the category '${category}' contains a ';'.") endif() set(TOPP_TOOLS ${TOPP_TOOLS} "${name}" CACHE INTERNAL "OpenMS' TOPP tools" FORCE) set(TOPP_TOOL_CATEGORIES ${TOPP_TOOL_CATEGORIES} "${category}" CACHE INTERNAL "TOPPAS category of the entry of TOPP_TOOLS at the same index" FORCE) endfunction() #------------------------------------------------------------------------------ # openms_write_tool_registry() # # Write the registry of every tool declared so far. Call it once, after every # add_subdirectory() that declares tools. # # Without any tool to list, no file is written and a file an earlier configure of this build # directory left behind is removed: a build of the libraries alone registers nothing. # # The format is the tab-separated one the rest of share/OpenMS uses for tabular data, read # back by ToolHandler through CsvFile: # # # comment # \t[\t;...] # # The third column is the list of '-type' sub-modes a tool offers and is omitted by tools # that have none, which is all of them today. function(openms_write_tool_registry out_file) if(ARGN) message(FATAL_ERROR "openms_write_tool_registry(${out_file}): unexpected arguments '${ARGN}'") endif() list(LENGTH TOPP_TOOLS _tool_count) list(LENGTH TOPP_TOOL_CATEGORIES _category_count) if(NOT _tool_count EQUAL _category_count) message(FATAL_ERROR "The TOPP tool declarations are inconsistent: ${_tool_count} tools but ${_category_count} " "categories. Both lists are only ever appended to by openms_topp_tool().") endif() ## Ordered by tool name, so a reconfigure that declares the same tools produces a ## byte-identical file. Sorting the names themselves rather than "namecategory" pairs: ## any separator sorts somewhere among the letters and would order 'FooBar' before 'Foo'. set(_sorted_names ${TOPP_TOOLS}) if(_tool_count EQUAL 0) file(REMOVE "${out_file}") message(STATUS "TOPP tool registry: no tools, ${out_file} not written") return() endif() list(SORT _sorted_names CASE INSENSITIVE) set(_content "# GENERATED FILE, do not edit and do not commit. # # The TOPP tool registry: what ToolHandler lists, and the category TOPPAS groups each tool # under. Written by openms_write_tool_registry() (cmake/topp_tool_macros.cmake) from the # openms_topp_tool() declarations in src/topp/executables.cmake. To add a tool, declare it # there; it is built and registered by that one declaration. # # A tool describes itself (parameters, formats, documentation) through its own binary, via # -write_ctd, so the registry carries nothing but the name and the category. Tools built # outside this repository (e.g. ExecutePipeline and ImageCreator of OpenMS-TOPP-GUI) register # themselves by installing their own *.tsv alongside this one; a name may be registered only # once across all of them. # # \t ") foreach(_name IN LISTS _sorted_names) ## openms_topp_tool() rejects a duplicate name, so this finds the one declaration. list(FIND TOPP_TOOLS "${_name}" _index) list(GET TOPP_TOOL_CATEGORIES ${_index} _category) string(APPEND _content "${_name}\t${_category}\n") endforeach() ## Only rewrite on a real change, so a reconfigure does not restamp the file. set(_previous "") if(EXISTS "${out_file}") file(READ "${out_file}" _previous) endif() if(NOT _previous STREQUAL _content) file(WRITE "${out_file}" "${_content}") endif() message(STATUS "TOPP tool registry: ${_tool_count} tools -> ${out_file}") endfunction()