From 640857f85ce151d9473493cb73233e93b31e636c Mon Sep 17 00:00:00 2001 From: redcode Date: Tue, 5 Nov 2024 10:31:57 +0100 Subject: [PATCH] CMake find modules update. --- CMake/FindBreathe.cmake | 57 +++++++-- CMake/FindSphinx.cmake | 118 ++++++++++++++--- CMake/FindZeta.cmake | 237 ++++++++++++++++++++++++++--------- documentation/CMakeLists.txt | 10 +- 4 files changed, 329 insertions(+), 93 deletions(-) diff --git a/CMake/FindBreathe.cmake b/CMake/FindBreathe.cmake index ec2d8ca..0877234 100644 --- a/CMake/FindBreathe.cmake +++ b/CMake/FindBreathe.cmake @@ -1,31 +1,62 @@ # FindBreathe.cmake -# Copyright (C) 2021-2023 Manuel Sainz de Baranda y Goñi. -# This "find module" is DISTRIBUTED AS PUBLIC DOMAIN. No restrictions apply. +# Copyright (C) 2021-2024 Manuel Sainz de Baranda y Goñi. +# This "find module" is distributed as public domain software. + +#[=======================================================================[.rst: +FindBreathe +----------- + +Find Breathe. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``Breathe_FOUND`` + ``TRUE`` if Breathe was found. + +``Breathe_APIDOC_VERSION`` + The version of the ``breathe-apidoc`` executable that was found. + +``Breathe_VERSION`` + Same as ``Breathe_APIDOC_VERSION``. + +Cache variables +^^^^^^^^^^^^^^^ + +Search results are saved persistently in CMake cache entries: + +``Breathe_APIDOC_EXECUTABLE`` + The full path to the ``breathe-apidoc`` executable. + +#]=======================================================================] include(FindPackageHandleStandardArgs) find_program( - BREATHE_APIDOC_EXECUTABLE + Breathe_APIDOC_EXECUTABLE NAMES breathe-apidoc - DOC "Breathe extension for Sphinx") + DOC "`breathe-apidoc` executable.") -if(BREATHE_APIDOC_EXECUTABLE) +if(Breathe_APIDOC_EXECUTABLE) execute_process( - COMMAND "${BREATHE_APIDOC_EXECUTABLE}" --version - OUTPUT_VARIABLE _output) + COMMAND "${Breathe_APIDOC_EXECUTABLE}" --version + OUTPUT_VARIABLE _Breathe_output) - if("${_output}" MATCHES ".* ([^\n]+)\n") - set(BREATHE_APIDOC_VERSION "${CMAKE_MATCH_1}") + if("${_Breathe_output}" MATCHES ".* ([0-9]+(\\.[0-9]+(\\.[0-9]+)?)?).*\n") + set(Breathe_APIDOC_VERSION "${CMAKE_MATCH_1}") + set(Breathe_VERSION ${Breathe_APIDOC_VERSION}) endif() - unset(_output) + unset(_Breathe_output) endif() find_package_handle_standard_args( Breathe - REQUIRED_VARS BREATHE_APIDOC_EXECUTABLE - VERSION_VAR BREATHE_APIDOC_VERSION) + REQUIRED_VARS Breathe_APIDOC_EXECUTABLE + VERSION_VAR Breathe_VERSION) -mark_as_advanced(BREATHE_APIDOC_EXECUTABLE) +mark_as_advanced(Breathe_APIDOC_EXECUTABLE) # FindBreathe.cmake EOF diff --git a/CMake/FindSphinx.cmake b/CMake/FindSphinx.cmake index fe2aeab..cc3b010 100644 --- a/CMake/FindSphinx.cmake +++ b/CMake/FindSphinx.cmake @@ -1,31 +1,115 @@ # FindSphinx.cmake -# Copyright (C) 2021-2023 Manuel Sainz de Baranda y Goñi. -# This "find module" is DISTRIBUTED AS PUBLIC DOMAIN. No restrictions apply. +# Copyright (C) 2021-2024 Manuel Sainz de Baranda y Goñi. +# This "find module" is distributed as public domain software. -include(FindPackageHandleStandardArgs) +#[=======================================================================[.rst: +FindSphinx +---------- + +Find the Sphinx documentation tools. + +Optional components +^^^^^^^^^^^^^^^^^^^ + +This module supports 4 optional ``COMPONENTS``: + +``apidoc`` + Looks for the ``sphinx-apidoc`` executable. + +``autogen`` + Looks for the ``sphinx-autogen`` executable. + +``build`` + Looks for the ``sphinx-build`` executable. This component is used by default + if no components are specified. + +``quickstart`` + Looks for the ``sphinx-quickstart`` executable. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``Sphinx_FOUND`` + ``TRUE`` if all requested Sphinx tools were found. + +``Sphinx__VERSION`` + The version of the ``sphinx-`` executable that was found, where + ```` and ```` are the uppercase and lowercase names of + the component, respectively. + +``Sphinx_VERSION`` + The version of Sphinx that was found. It is the same as + ``Sphinx_BUILD_VERSION`` if the ``build`` component was requested; otherwise, + it is the same as the first one requested. + +Cache variables +^^^^^^^^^^^^^^^ -find_program( - SPHINX_BUILD_EXECUTABLE - NAMES sphinx-build - DOC "Sphinx Documentation Builder") +Search results are saved persistently in CMake cache entries: -if(SPHINX_BUILD_EXECUTABLE) - execute_process( - COMMAND "${SPHINX_BUILD_EXECUTABLE}" --version - OUTPUT_VARIABLE _output) +``Sphinx__EXECUTABLE`` + The full path to the ``sphinx-`` executable, where ```` + and ```` are the uppercase and lowercase names of the component, + respectively. - if("${_output}" MATCHES ".* ([^\n]+)\n") - set(SPHINX_BUILD_VERSION "${CMAKE_MATCH_1}") +#]=======================================================================] + +set(_Sphinx_required_vars) + +if(NOT Sphinx_FIND_COMPONENTS) + set(Sphinx_FIND_COMPONENTS build) +endif() + +foreach(_Sphinx_tool IN LISTS Sphinx_FIND_COMPONENTS) + if(NOT _Sphinx_tool MATCHES "^(apidoc|autogen|build|quickstart)$") + message(FATAL_ERROR "Invalid components: ${Sphinx_FIND_COMPONENTS}") + endif() + + string(TOUPPER ${_Sphinx_tool} _Sphinx_tool_uppercase) + set(_Sphinx_tool_executable_var Sphinx_${_Sphinx_tool_uppercase}_EXECUTABLE) + + if(NOT DEFINED ${_Sphinx_tool_executable_var}) + find_program( + ${_Sphinx_tool_executable_var} + NAMES sphinx-${_Sphinx_tool} + DOC "`sphinx-${_Sphinx_tool}` executable.") + + if(${_Sphinx_tool_executable_var}) + execute_process( + COMMAND "${${_Sphinx_tool_executable_var}}" --version + OUTPUT_VARIABLE _Sphinx_output) + + if("${_Sphinx_output}" MATCHES ".* ([0-9]+(\\.[0-9]+(\\.[0-9]+)?)?).*\n") + list(APPEND _Sphinx_required_vars ${_Sphinx_tool_executable_var}) + mark_as_advanced(${_Sphinx_tool_executable_var}) + set(Sphinx_${_Sphinx_tool_uppercase}_VERSION "${CMAKE_MATCH_1}") + + if(NOT DEFINED Sphinx_VERSION) + set(Sphinx_VERSION ${Sphinx_${_Sphinx_tool_uppercase}_VERSION}) + endif() + endif() + + unset(_Sphinx_output) + endif() endif() - unset(_output) + unset(_Sphinx_tool_executable_var) + unset(_Sphinx_tool_uppercase) +endforeach() + +if(DEFINED Sphinx_BUILD_VERSION) + set(Sphinx_VERSION ${Sphinx_BUILD_VERSION}) endif() +include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( Sphinx - REQUIRED_VARS SPHINX_BUILD_EXECUTABLE - VERSION_VAR SPHINX_BUILD_VERSION) + REQUIRED_VARS ${_Sphinx_required_vars} + VERSION_VAR Sphinx_VERSION) -mark_as_advanced(SPHINX_BUILD_EXECUTABLE) +unset(_Sphinx_required_vars) # FindSphinx.cmake EOF diff --git a/CMake/FindZeta.cmake b/CMake/FindZeta.cmake index 6210f93..0ffb665 100644 --- a/CMake/FindZeta.cmake +++ b/CMake/FindZeta.cmake @@ -1,73 +1,191 @@ -# Zeta - FindZeta.cmake +# FindZeta.cmake # ______ ______________ ___ # |__ / | ___|___ ___|/ \ # / /__| __| | | / - \ # /______|_____| |__| /__/ \__\ # Copyright (C) 2006-2024 Manuel Sainz de Baranda y Goñi. -# This "find module" is DISTRIBUTED AS PUBLIC DOMAIN. No restrictions apply. +# This "find module" is distributed as public domain software. + +#[=======================================================================[.rst: +FindZeta +-------- + +Find the Zeta library. + +Search behavior +^^^^^^^^^^^^^^^ + +By default, this module will search for Zeta in the directory specified by the +``ZETA_DIR`` environment variable. If this variable is not defined, it will +search in ``PROJECT_BINARY_DIR`` and the following paths relative to +``PROJECT_SOURCE_DIR`` (in the listed order): + +* :file:`.` +* :file:`3rd` +* :file:`3rd-party` +* :file:`3rd-parties` +* :file:`3rd_party` +* :file:`3rd_parties` +* :file:`3rdparty` +* :file:`3rdparties` +* :file:`third-party` +* :file:`third-parties` +* :file:`third_party` +* :file:`third_parties` +* :file:`thirdparty` +* :file:`thirdparties` +* :file:`dependencies` +* :file:`deps` +* :file:`extern` +* :file:`external` +* :file:`externals` +* :file:`..` + +Finally, if the relaive search is unsuccessful, the module will search for the +headers of the Zeta library in system include directories. + +Input variables +^^^^^^^^^^^^^^^ + +The search process can be controlled by using the following variables: + +``Zeta_IGNORE_ZETA_DIR`` + Set this variable to ``TRUE`` to ignore the ``ZETA_DIR`` environment variable. + +``Zeta_SKIP_RELATIVE_SEARCH`` + If set to ``TRUE``, the module will not search in ``PROJECT_BINARY_DIR`` and + paths relative to ``PROJECT_BINARY_DIR`` before trying system include + directories. + +``Zeta_SKIP_SYSTEM_SEARCH`` + If set to ``TRUE``, the module will not search in system include directories. + +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the following ``INTERFACE IMPORTED`` target: + +``Zeta`` + The Zeta library, if found. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``Zeta_FOUND`` + ``TRUE`` if the Zeta library was found. + +``Zeta_INCLUDE_DIRS`` + The include directory needed to use Zeta. + +``Zeta_VERSION`` + The version of the Zeta library that was found. + +``Zeta_VERSION_MAJOR`` + First version number component of the ``Zeta_VERSION`` variable. + +``Zeta_VERSION_MINOR`` + Second version number component of the ``Zeta_VERSION`` variable. + +``Zeta_VERSION_MICRO`` + Third version number component of the ``Zeta_VERSION`` variable. + +``Zeta_VERSION_PATCH`` + Same as ``Zeta_VERSION_MICRO``. + +Cache Variables +^^^^^^^^^^^^^^^ + +Search results are saved persistently in CMake cache entries: + +``Zeta_INCLUDE_DIR`` + Same as ``Zeta_INCLUDE_DIRS``. + +Hints +^^^^^ + +The user can set the ``ZETA_DIR`` environment variable to specify the include +directory of the Zeta library or the directory where its tarball has been +extracted. However, if this variable is defined and Zeta is not found in the +specified directory, the module will fail and will not look anywhere else. + +#]=======================================================================] include(FindPackageHandleStandardArgs) -if(NOT DEFINED Zeta_FIND_RELATIVE OR Zeta_FIND_RELATIVE) +if( DEFINED ENV{ZETA_DIR} AND + (NOT DEFINED Zeta_IGNORE_ZETA_DIR OR NOT Zeta_IGNORE_ZETA_DIR) +) find_path( Zeta_INCLUDE_DIR "Z/version.h" - PATHS "${PROJECT_BINARY_DIR}/Zeta/API" - "${PROJECT_BINARY_DIR}" - "${PROJECT_SOURCE_DIR}/Zeta/API" - "${PROJECT_SOURCE_DIR}" - "${PROJECT_SOURCE_DIR}/3rd/Zeta/API" - "${PROJECT_SOURCE_DIR}/3rd" - "${PROJECT_SOURCE_DIR}/3rd-party/Zeta/API" - "${PROJECT_SOURCE_DIR}/3rd-party" - "${PROJECT_SOURCE_DIR}/3rd-parties/Zeta/API" - "${PROJECT_SOURCE_DIR}/3rd-parties" - "${PROJECT_SOURCE_DIR}/3rd_party/Zeta/API" - "${PROJECT_SOURCE_DIR}/3rd_party" - "${PROJECT_SOURCE_DIR}/3rd_parties/Zeta/API" - "${PROJECT_SOURCE_DIR}/3rd_parties" - "${PROJECT_SOURCE_DIR}/3rdparty/Zeta/API" - "${PROJECT_SOURCE_DIR}/3rdparty" - "${PROJECT_SOURCE_DIR}/3rdparties/Zeta/API" - "${PROJECT_SOURCE_DIR}/3rdparties" - "${PROJECT_SOURCE_DIR}/third-party/Zeta/API" - "${PROJECT_SOURCE_DIR}/third-party" - "${PROJECT_SOURCE_DIR}/third-parties/Zeta/API" - "${PROJECT_SOURCE_DIR}/third-parties" - "${PROJECT_SOURCE_DIR}/third_party/Zeta/API" - "${PROJECT_SOURCE_DIR}/third_party" - "${PROJECT_SOURCE_DIR}/third_parties/Zeta/API" - "${PROJECT_SOURCE_DIR}/third_parties" - "${PROJECT_SOURCE_DIR}/thirdparty/Zeta/API" - "${PROJECT_SOURCE_DIR}/thirdparty" - "${PROJECT_SOURCE_DIR}/thirdparties/Zeta/API" - "${PROJECT_SOURCE_DIR}/thirdparties" - "${PROJECT_SOURCE_DIR}/dependencies/Zeta/API" - "${PROJECT_SOURCE_DIR}/dependencies" - "${PROJECT_SOURCE_DIR}/deps/Zeta/API" - "${PROJECT_SOURCE_DIR}/deps" - "${PROJECT_SOURCE_DIR}/extern/Zeta/API" - "${PROJECT_SOURCE_DIR}/extern" - "${PROJECT_SOURCE_DIR}/external/Zeta/API" - "${PROJECT_SOURCE_DIR}/external" - "${PROJECT_SOURCE_DIR}/externals/Zeta/API" - "${PROJECT_SOURCE_DIR}/externals" - "${PROJECT_SOURCE_DIR}/../zeta-src/API" - "${PROJECT_SOURCE_DIR}/../Zeta/API" - "${PROJECT_SOURCE_DIR}/.." + PATHS "$ENV{ZETA_DIR}" NO_DEFAULT_PATH) -endif() -find_path( - Zeta_INCLUDE_DIR "Z/version.h" - HINTS ENV CPATH - ENV C_INCLUDE_PATH - ENV CPLUS_INCLUDE_PATH - ENV OBJC_INCLUDE_PATH) +else() + if(NOT DEFINED Zeta_SKIP_RELATIVE_SEARCH OR NOT Zeta_SKIP_RELATIVE_SEARCH) + find_path( + Zeta_INCLUDE_DIR "Z/version.h" + PATHS "${PROJECT_BINARY_DIR}/Zeta/API" + "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/Zeta/API" + "${PROJECT_SOURCE_DIR}" + "${PROJECT_SOURCE_DIR}/3rd/Zeta/API" + "${PROJECT_SOURCE_DIR}/3rd" + "${PROJECT_SOURCE_DIR}/3rd-party/Zeta/API" + "${PROJECT_SOURCE_DIR}/3rd-party" + "${PROJECT_SOURCE_DIR}/3rd-parties/Zeta/API" + "${PROJECT_SOURCE_DIR}/3rd-parties" + "${PROJECT_SOURCE_DIR}/3rd_party/Zeta/API" + "${PROJECT_SOURCE_DIR}/3rd_party" + "${PROJECT_SOURCE_DIR}/3rd_parties/Zeta/API" + "${PROJECT_SOURCE_DIR}/3rd_parties" + "${PROJECT_SOURCE_DIR}/3rdparty/Zeta/API" + "${PROJECT_SOURCE_DIR}/3rdparty" + "${PROJECT_SOURCE_DIR}/3rdparties/Zeta/API" + "${PROJECT_SOURCE_DIR}/3rdparties" + "${PROJECT_SOURCE_DIR}/third-party/Zeta/API" + "${PROJECT_SOURCE_DIR}/third-party" + "${PROJECT_SOURCE_DIR}/third-parties/Zeta/API" + "${PROJECT_SOURCE_DIR}/third-parties" + "${PROJECT_SOURCE_DIR}/third_party/Zeta/API" + "${PROJECT_SOURCE_DIR}/third_party" + "${PROJECT_SOURCE_DIR}/third_parties/Zeta/API" + "${PROJECT_SOURCE_DIR}/third_parties" + "${PROJECT_SOURCE_DIR}/thirdparty/Zeta/API" + "${PROJECT_SOURCE_DIR}/thirdparty" + "${PROJECT_SOURCE_DIR}/thirdparties/Zeta/API" + "${PROJECT_SOURCE_DIR}/thirdparties" + "${PROJECT_SOURCE_DIR}/dependencies/Zeta/API" + "${PROJECT_SOURCE_DIR}/dependencies" + "${PROJECT_SOURCE_DIR}/deps/Zeta/API" + "${PROJECT_SOURCE_DIR}/deps" + "${PROJECT_SOURCE_DIR}/extern/Zeta/API" + "${PROJECT_SOURCE_DIR}/extern" + "${PROJECT_SOURCE_DIR}/external/Zeta/API" + "${PROJECT_SOURCE_DIR}/external" + "${PROJECT_SOURCE_DIR}/externals/Zeta/API" + "${PROJECT_SOURCE_DIR}/externals" + "${PROJECT_SOURCE_DIR}/../zeta-src/API" + "${PROJECT_SOURCE_DIR}/../Zeta/API" + "${PROJECT_SOURCE_DIR}/.." + NO_DEFAULT_PATH) + endif() + + if(NOT DEFINED Zeta_SKIP_SYSTEM_SEARCH OR NOT Zeta_SKIP_SYSTEM_SEARCH) + find_path( + Zeta_INCLUDE_DIR "Z/version.h" + HINTS ENV CPATH + ENV C_INCLUDE_PATH + ENV CPLUS_INCLUDE_PATH + ENV OBJC_INCLUDE_PATH) + endif() +endif() if(Zeta_INCLUDE_DIR AND EXISTS "${Zeta_INCLUDE_DIR}/Z/version.h") - file(READ "${Zeta_INCLUDE_DIR}/Z/version.h" _) + file(READ "${Zeta_INCLUDE_DIR}/Z/version.h" _Zeta_Z_version_h) - if(_ MATCHES ".*Z_LIBRARY_VERSION_STRING \"([^\n]*)\".*") + if(_Zeta_Z_version_h MATCHES ".*Z_LIBRARY_VERSION_STRING \"([^\n]*)\".*") set(Zeta_VERSION ${CMAKE_MATCH_1}) if(Zeta_VERSION MATCHES "^([0-9]+)\\.([0-9]+)") @@ -75,23 +193,26 @@ if(Zeta_INCLUDE_DIR AND EXISTS "${Zeta_INCLUDE_DIR}/Z/version.h") set(Zeta_VERSION_MINOR ${CMAKE_MATCH_2}) if(Zeta_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)") - set(Zeta_VERSION_PATCH ${CMAKE_MATCH_3}) + set(Zeta_VERSION_MICRO ${CMAKE_MATCH_3}) + set(Zeta_VERSION_PATCH ${Zeta_VERSION_MICRO}) else() + set(Zeta_VERSION_MICRO 0) set(Zeta_VERSION_PATCH 0) endif() endif() endif() - unset(_) + unset(_Zeta_Z_version_h) endif() find_package_handle_standard_args( Zeta FOUND_VAR Zeta_FOUND - REQUIRED_VARS Zeta_INCLUDE_DIR Zeta_VERSION + REQUIRED_VARS Zeta_INCLUDE_DIR VERSION_VAR Zeta_VERSION) if(Zeta_FOUND AND NOT TARGET Zeta) + set(Zeta_INCLUDE_DIRS "${Zeta_INCLUDE_DIR}") add_library(Zeta INTERFACE IMPORTED) if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_LESS 3.11) diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index f3c49be..d9c809c 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -59,8 +59,8 @@ if(${PROJECT_NAME}_WITH_HTML_DOCUMENTATION) endif() add_custom_command( - OUTPUT "${_html_documentation_output}" - COMMAND "${SPHINX_BUILD_EXECUTABLE}" + OUTPUT "${_html_documentation_output}" + COMMAND "${Sphinx_BUILD_EXECUTABLE}" -b html "-Dproject=${PROJECT_NAME}" "-Dversion=${PROJECT_VERSION}" @@ -92,8 +92,8 @@ if(${PROJECT_NAME}_WITH_PDF_DOCUMENTATION) set(_latex_documentation_output "${CMAKE_CURRENT_BINARY_DIR}/LaTeX") add_custom_command( - OUTPUT "${_latex_documentation_output}" - COMMAND "${SPHINX_BUILD_EXECUTABLE}" + OUTPUT "${_latex_documentation_output}" + COMMAND "${Sphinx_BUILD_EXECUTABLE}" -b latex "-Dproject=${PROJECT_NAME}" "-Dversion=${PROJECT_VERSION}" @@ -116,7 +116,7 @@ if(${PROJECT_NAME}_WITH_PDF_DOCUMENTATION) set(_pdf_documentation_output "${_latex_documentation_output}/${_pdf_documentation_output}.pdf") add_custom_command( - OUTPUT "${_pdf_documentation_output}" + OUTPUT "${_pdf_documentation_output}" COMMAND "${CMAKE_MAKE_PROGRAM}" MAIN_DEPENDENCY "${_latex_documentation_output}" WORKING_DIRECTORY "${_latex_documentation_output}"