diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a0a40d0..52b5555d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,7 +113,9 @@ include(${PROJECT_SOURCE_DIR}/cmake/install_macros.cmake) include(${PROJECT_SOURCE_DIR}/cmake/doc_macros.cmake) include(${PROJECT_SOURCE_DIR}/cmake/add_library_macros.cmake) include(${PROJECT_SOURCE_DIR}/cmake/export_macros.cmake) -include(${PROJECT_SOURCE_DIR}/cmake/topp_tool_macros.cmake) +## The TOPP tool macros (openms_topp_tool(), openms_write_tool_registry(), +## openms_install_tool_registry()) come with the CLI layer of the OpenMS CMake package +## (cmake/find_openms.cmake). #------------------------------------------------------------------------------ # Package type diff --git a/cmake/find_openms.cmake b/cmake/find_openms.cmake index e4cd981d..e928e7b0 100644 --- a/cmake/find_openms.cmake +++ b/cmake/find_openms.cmake @@ -9,7 +9,10 @@ #------------------------------------------------------------------------------ # The dependencies of the GUI layer: # - the installed OpenMS core with its CLI layer (OpenMS::OpenMS, OpenMS::OpenMS_CLI), -# of exactly the version of this repository: the GUI is compiled against its headers +# of exactly the version of this repository: the GUI is compiled against its headers, +# and the TOPP tool macros of that layer (OpenMSToolMacros.cmake: openms_topp_tool(), +# openms_write_tool_registry(), openms_install_tool_registry()) register the GUI TOPP +# tools # - Qt 6 # Point CMAKE_PREFIX_PATH (or OpenMS_DIR) at the OpenMS installation, e.g. the OpenMS SDK. #------------------------------------------------------------------------------ @@ -18,6 +21,15 @@ ## (OpenMS::OpenMS_GUI) as well; this build provides that target itself. set(OpenMS_IGNORE_GUI_LAYER TRUE) find_package(OpenMS ${OPENMS_PACKAGE_VERSION} EXACT CONFIG REQUIRED COMPONENTS CLI) +foreach(_command IN ITEMS openms_reset_topp_tools openms_topp_tool openms_write_tool_registry + openms_install_tool_registry) + if(NOT COMMAND ${_command}) + message(FATAL_ERROR "The OpenMS CMake package in ${OpenMS_DIR} does not provide the TOPP tool macros " + "(OpenMSToolMacros.cmake, ${_command}()), which register the GUI TOPP tools with ToolHandler. " + "Build against an OpenMS that installs them with its CLI layer (OpenMS/OpenMS#11042 and later).") + endif() +endforeach() +unset(_command) ## A core from before the split may have been built with its own GUI library. Its ## imported OpenMS::OpenMS_GUI would clash with the library built here, and its installed diff --git a/cmake/topp_tool_macros.cmake b/cmake/topp_tool_macros.cmake deleted file mode 100644 index 7c004cfd..00000000 --- a/cmake/topp_tool_macros.cmake +++ /dev/null @@ -1,148 +0,0 @@ -# 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 the GUI layer, -# share/OpenMS/TOOLS/OpenMS-GUI.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 the GUI TOPP tools. - -#------------------------------------------------------------------------------ -# 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/openms_gui). -# 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. "Misc". Use one of the categories of the -# OpenMS core (doc/doxygen/public/TOPP.doxygen of OpenMS). -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( [TOOLS ...]) -# -# Write the registry of every tool declared so far. Call it once, after every -# add_subdirectory() that declares tools. -# -# TOOLS restricts the file to the given subset of the declared 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) - cmake_parse_arguments(PARSE_ARGV 1 _registry "" "" "TOOLS") - if(_registry_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "openms_write_tool_registry(${out_file}): unexpected arguments '${_registry_UNPARSED_ARGUMENTS}'") - 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("TOOLS" IN_LIST ARGN) - foreach(_name IN LISTS _registry_TOOLS) - if(NOT _name IN_LIST TOPP_TOOLS) - message(FATAL_ERROR "openms_write_tool_registry(${out_file}): '${_name}' is not a declared tool") - endif() - endforeach() - set(_sorted_names ${_registry_TOOLS}) - endif() - list(LENGTH _sorted_names _tool_count) - 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 of the GUI layer (OpenMS-TOPP-GUI): 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/openms_gui/CMakeLists.txt. The tools of the OpenMS core are in OpenMS.tsv next to it. -# -# 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 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() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4300c43..196f4c3a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,17 +18,14 @@ add_subdirectory(openms_gui) #------------------------------------------------------------------------------ # The tool registry of the GUI layer, OpenMS-GUI.tsv, generated from the -# openms_topp_tool() declarations of src/openms_gui. It is installed into -# share/OpenMS/TOOLS next to the registry of the OpenMS core (OpenMS.tsv); -# ToolHandler reads every *.tsv it finds there. That directory holds registry -# files and nothing else. +# openms_topp_tool() declarations of src/openms_gui. It is installed next to the +# registry of the OpenMS core (OpenMS.tsv), into the directory that OpenMS +# installation keeps its registries in (share/OpenMS/TOOLS by default; +# OPENMS_TOOL_REGISTRY_DESTINATION of its CMake package); ToolHandler reads every +# *.tsv it finds there. That directory holds registry files and nothing else. #------------------------------------------------------------------------------ openms_write_tool_registry("${OPENMS_TOOL_REGISTRY_BUILD_FILE}") -install(FILES "${OPENMS_TOOL_REGISTRY_BUILD_FILE}" - DESTINATION ${INSTALL_SHARE_DIR}/TOOLS - COMPONENT ${OPENMS_GUI_APPLICATIONS_COMPONENT} - PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ -) +openms_install_tool_registry("${OPENMS_TOOL_REGISTRY_BUILD_FILE}" COMPONENT ${OPENMS_GUI_APPLICATIONS_COMPONENT}) #------------------------------------------------------------------------------ # Desktop integration (Linux). The GUI layer installs no other shared data: the style diff --git a/src/tests/topp/check_tool_registry.cmake b/src/tests/topp/check_tool_registry.cmake index ca8264b6..09dc7bbd 100644 --- a/src/tests/topp/check_tool_registry.cmake +++ b/src/tests/topp/check_tool_registry.cmake @@ -12,7 +12,7 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR) ### Checks the generated TOPP tool registry. ### -### The registry is written by openms_write_tool_registry() (cmake/topp_tool_macros.cmake) from +### The registry is written by openms_write_tool_registry() (the TOPP tool macros of OpenMS) from ### the same openms_topp_tool() declarations that produce the executables, so the registry and ### the build cannot describe different sets of tools; that is the point of generating it and ### there is nothing to cross-check. What generating it does not rule out is the generator