From e706da5f7ebbdab98098825ff8f7bad89ce06277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Wro=CC=81bel?= Date: Tue, 12 Jul 2022 16:39:58 +0200 Subject: FindOpenSP: Add module to find the OpenSP library OpenSP has not seen a release in seventeen years, so is unlikely to ever provide a CMake package configuration file. Add a find module instead. --- .gitlab/ci/configure_debian10_aarch64_ninja.cmake | 1 + .gitlab/ci/configure_debian10_ninja.cmake | 1 + .gitlab/ci/configure_fedora36_makefiles.cmake | 1 + Copyright.txt | 1 + Help/manual/cmake-modules.7.rst | 1 + Help/module/FindOpenSP.rst | 1 + Help/release/dev/FindOpenSP-module.rst | 4 + Modules/FindOpenSP.cmake | 155 ++++++++++++++++++++++ Tests/CMakeLists.txt | 1 + Tests/FindOpenSP/CMakeLists.txt | 10 ++ Tests/FindOpenSP/Test/CMakeLists.txt | 16 +++ Tests/FindOpenSP/Test/main.cxx | 55 ++++++++ Tests/FindOpenSP/Test/test.sgml | 7 + 13 files changed, 254 insertions(+) create mode 100644 Help/module/FindOpenSP.rst create mode 100644 Help/release/dev/FindOpenSP-module.rst create mode 100644 Modules/FindOpenSP.cmake create mode 100644 Tests/FindOpenSP/CMakeLists.txt create mode 100644 Tests/FindOpenSP/Test/CMakeLists.txt create mode 100644 Tests/FindOpenSP/Test/main.cxx create mode 100644 Tests/FindOpenSP/Test/test.sgml diff --git a/.gitlab/ci/configure_debian10_aarch64_ninja.cmake b/.gitlab/ci/configure_debian10_aarch64_ninja.cmake index 08c1a1a..605f6ba 100644 --- a/.gitlab/ci/configure_debian10_aarch64_ninja.cmake +++ b/.gitlab/ci/configure_debian10_aarch64_ninja.cmake @@ -50,6 +50,7 @@ set(CMake_TEST_FindOpenMP_C "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP_CXX "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP_Fortran "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP "ON" CACHE BOOL "") +set(CMake_TEST_FindOpenSP "ON" CACHE BOOL "") set(CMake_TEST_FindOpenSSL "ON" CACHE BOOL "") set(CMake_TEST_FindPatch "ON" CACHE BOOL "") set(CMake_TEST_FindPNG "ON" CACHE BOOL "") diff --git a/.gitlab/ci/configure_debian10_ninja.cmake b/.gitlab/ci/configure_debian10_ninja.cmake index 12564fa..214828a 100644 --- a/.gitlab/ci/configure_debian10_ninja.cmake +++ b/.gitlab/ci/configure_debian10_ninja.cmake @@ -54,6 +54,7 @@ set(CMake_TEST_FindOpenMP_C "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP_CXX "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP_Fortran "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP "ON" CACHE BOOL "") +set(CMake_TEST_FindOpenSP "ON" CACHE BOOL "") set(CMake_TEST_FindOpenSSL "ON" CACHE BOOL "") set(CMake_TEST_FindPatch "ON" CACHE BOOL "") set(CMake_TEST_FindPNG "ON" CACHE BOOL "") diff --git a/.gitlab/ci/configure_fedora36_makefiles.cmake b/.gitlab/ci/configure_fedora36_makefiles.cmake index 7abc269..11d1a08 100644 --- a/.gitlab/ci/configure_fedora36_makefiles.cmake +++ b/.gitlab/ci/configure_fedora36_makefiles.cmake @@ -53,6 +53,7 @@ set(CMake_TEST_FindOpenMP_C "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP_CXX "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP_Fortran "ON" CACHE BOOL "") set(CMake_TEST_FindOpenMP "ON" CACHE BOOL "") +set(CMake_TEST_FindOpenSP "ON" CACHE BOOL "") set(CMake_TEST_FindOpenSSL "ON" CACHE BOOL "") set(CMake_TEST_FindPatch "ON" CACHE BOOL "") set(CMake_TEST_FindPNG "ON" CACHE BOOL "") diff --git a/Copyright.txt b/Copyright.txt index 2cf1769..bd45dd1 100644 --- a/Copyright.txt +++ b/Copyright.txt @@ -53,6 +53,7 @@ The following individuals and institutions are among the Contributors: * Clement Creusot * Daniel Blezek * Daniel Pfeifer +* Dawid Wróbel * Enrico Scholz * Eran Ifrah * Esben Mose Hansen, Ange Optimization ApS diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst index 9dd623a..d161a28 100644 --- a/Help/manual/cmake-modules.7.rst +++ b/Help/manual/cmake-modules.7.rst @@ -193,6 +193,7 @@ They are normally called through the :command:`find_package` command. /module/FindOpenGL /module/FindOpenMP /module/FindOpenSceneGraph + /module/FindOpenSP /module/FindOpenSSL /module/FindOpenThreads /module/Findosg diff --git a/Help/module/FindOpenSP.rst b/Help/module/FindOpenSP.rst new file mode 100644 index 0000000..1a3da01 --- /dev/null +++ b/Help/module/FindOpenSP.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../Modules/FindOpenSP.cmake diff --git a/Help/release/dev/FindOpenSP-module.rst b/Help/release/dev/FindOpenSP-module.rst new file mode 100644 index 0000000..9df6815 --- /dev/null +++ b/Help/release/dev/FindOpenSP-module.rst @@ -0,0 +1,4 @@ +FindOpenSP-module +----------------- + +* The :module:`FindOpenSP` module was added to find the OpenSP library. diff --git a/Modules/FindOpenSP.cmake b/Modules/FindOpenSP.cmake new file mode 100644 index 0000000..c903ad7 --- /dev/null +++ b/Modules/FindOpenSP.cmake @@ -0,0 +1,155 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindOpenSP +---------- + +Try to find the OpenSP library. + +.. versionadded:: 3.25 + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``OpenSP_FOUND`` + True if (the requested version of) ``OpenSP`` is available + +``OpenSP_VERSION`` + The version of ``OpenSP`` + +``OpenSP_VERSION_MAJOR`` + The major version of ``OpenSP`` + +``OpenSP_VERSION_MINOR`` + The minor version of ``OpenSP`` + +``OpenSP_VERSION_PATCH`` + The patch version of ``OpenSP`` + +``OpenSP_INCLUDE_DIRS`` + The include dirs of ``OpenSP`` with its headers + +``OpenSP_LIBRARIES`` + The OpenSP library for use with target_link_libraries(). + This can be passed to target_link_libraries() instead of + the :prop_tgt:`IMPORTED` ``OpenSP::OpenSP`` target + +``OpenSP_MULTI_BYTE`` + True if ``SP_MULTI_BYTE`` was found to be defined in OpenSP's ``config.h`` + header file, which indicates that the ``OpenSP`` library was compiled with + support for multi-byte characters. The consuming target needs to define the + ``SP_MULTI_BYTE`` to match this value in order to avoid issues with character + decoding. + +IMPORTED Targets +^^^^^^^^^^^^^^^^ + +This module defines the :prop_tgt:`IMPORTED` target ``OpenSP::OpenSP``, if +OpenSP has been found. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``OpenSP_INCLUDE_DIR`` + the OpenSP include directory + +``OpenSP_LIBRARY`` + the absolute path of the osp library + +#]=======================================================================] + +if (NOT OpenSP_INCLUDE_DIR AND NOT OpenSP_LIBRARY) + find_package(PkgConfig) + if (PkgConfig_FOUND) + pkg_check_modules(OpenSP IMPORTED_TARGET GLOBAL opensp) + + if (OpenSP_FOUND) + add_library(OpenSP::OpenSP INTERFACE IMPORTED) + target_link_libraries(OpenSP::OpenSP INTERFACE PkgConfig::OpenSP) + + set(OpenSP_INCLUDE_DIR ${OpenSP_INCLUDE_DIRS}) + set(OpenSP_LIBRARY ${OpenSP_LIBRARIES}) + endif () + endif () +endif () + +if (NOT OpenSP_INCLUDE_DIR) + find_path(OpenSP_INCLUDE_DIR + NAMES ParserEventGeneratorKit.h + PATH_SUFFIXES OpenSP opensp + DOC "The OpenSP include directory" + ) +endif () + +if (NOT OpenSP_LIBRARY) + find_library(OpenSP_LIBRARY_RELEASE + NAMES osp libosp opensp libopensp sp133 libsp + ) + + find_library(OpenSP_LIBRARY_DEBUG + NAMES ospd libospd openspd libopenspd sp133d libspd + ) + + include(SelectLibraryConfigurations) + select_library_configurations(OpenSP) +endif () + +if (OpenSP_INCLUDE_DIR AND OpenSP_LIBRARY) + if (EXISTS "${OpenSP_INCLUDE_DIR}/config.h") + if (NOT OpenSP_VERSION) + file(STRINGS "${OpenSP_INCLUDE_DIR}/config.h" opensp_version_str REGEX "^#define[\t ]+SP_VERSION[\t ]+\".*\"") + string(REGEX REPLACE "^.*SP_VERSION[\t ]+\"([^\"]*)\".*$" "\\1" OpenSP_VERSION "${opensp_version_str}") + unset(opensp_version_str) + endif () + + if (OpenSP_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=]) + set(OpenSP_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(OpenSP_VERSION_MINOR "${CMAKE_MATCH_2}") + set(OpenSP_VERSION_PATCH "${CMAKE_MATCH_3}") + endif () + + include(CheckCXXSymbolExists) + check_cxx_symbol_exists(SP_MULTI_BYTE "${OpenSP_INCLUDE_DIR}/config.h" OpenSP_MULTI_BYTE) + endif () + + if (NOT TARGET OpenSP::OpenSP) + set(OpenSP_INCLUDE_DIRS ${OpenSP_INCLUDE_DIR}) + + add_library(OpenSP::OpenSP UNKNOWN IMPORTED) + set_target_properties(OpenSP::OpenSP PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OpenSP_INCLUDE_DIRS}") + + if (OpenSP_LIBRARY_RELEASE) + set_target_properties(OpenSP::OpenSP PROPERTIES IMPORTED_LOCATION_RELEASE "${OpenSP_LIBRARY_RELEASE}") + set_property(TARGET OpenSP::OpenSP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + endif () + + if (OpenSP_LIBRARY_DEBUG) + set_target_properties(OpenSP::OpenSP PROPERTIES IMPORTED_LOCATION_DEBUG "${OpenSP_LIBRARY_DEBUG}") + set_property(TARGET OpenSP::OpenSP APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + endif () + + if (NOT OpenSP_LIBRARY_RELEASE AND NOT OpenSP_LIBRARY_DEBUG) + set_property(TARGET OpenSP::OpenSP APPEND PROPERTY IMPORTED_LOCATION "${OpenSP_LIBRARY}") + endif () + endif () +endif () + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OpenSP + FOUND_VAR OpenSP_FOUND + REQUIRED_VARS OpenSP_LIBRARY OpenSP_INCLUDE_DIR + VERSION_VAR OpenSP_VERSION + ) + +mark_as_advanced(OpenSP_INCLUDE_DIR OpenSP_LIBRARY OpenSP_MULTI_BYTE) + +include(FeatureSummary) +set_package_properties(OpenSP PROPERTIES + URL "http://openjade.sourceforge.net/doc/index.htm" + DESCRIPTION "An SGML System Conforming to International Standard ISO 8879" + ) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index b7de021..b6fec4d 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1476,6 +1476,7 @@ if(BUILD_TESTING) OpenCL OpenGL OpenMP + OpenSP OpenSSL MPI PNG diff --git a/Tests/FindOpenSP/CMakeLists.txt b/Tests/FindOpenSP/CMakeLists.txt new file mode 100644 index 0000000..26826d3 --- /dev/null +++ b/Tests/FindOpenSP/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindOpenSP.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindOpenSP/Test" + "${CMake_BINARY_DIR}/Tests/FindOpenSP/Test" + ${build_generator_args} + --build-project TestFindOpenSP + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) diff --git a/Tests/FindOpenSP/Test/CMakeLists.txt b/Tests/FindOpenSP/Test/CMakeLists.txt new file mode 100644 index 0000000..d8992d9 --- /dev/null +++ b/Tests/FindOpenSP/Test/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.4) +project(TestFindOpenSP CXX) +include(CTest) + +find_package(OpenSP REQUIRED) + +add_definitions(-DSP_MULTI_BYTE="${OpenSP_MULTI_BYTE}") + +add_executable(test_tgt main.cxx) +target_link_libraries(test_tgt OpenSP::OpenSP) +add_test(NAME test_tgt COMMAND test_tgt) + +add_executable(test_var main.cxx) +target_include_directories(test_var PRIVATE ${OpenSP_INCLUDE_DIRS}) +target_link_libraries(test_var PRIVATE ${OpenSP_LIBRARIES}) +add_test(NAME test_var COMMAND test_var) diff --git a/Tests/FindOpenSP/Test/main.cxx b/Tests/FindOpenSP/Test/main.cxx new file mode 100644 index 0000000..ef8aa2c --- /dev/null +++ b/Tests/FindOpenSP/Test/main.cxx @@ -0,0 +1,55 @@ +#include +#include + +#include "ParserEventGeneratorKit.h" + +std::string CharStringtostring(const SGMLApplication::CharString source) +{ + // The CharString type might have multi-byte characters if SP_MULTI_BYTE was + // defined + std::string result; + result.resize(source.len); + for (size_t i = 0; i < source.len; i++) { + result[i] = static_cast(source.ptr[i]); + } + return result; +} + +class OutlineApplication : public SGMLApplication +{ +public: + OutlineApplication() + : depth_(0) + { + } + void startElement(const StartElementEvent& event) + { + for (unsigned i = 0; i < depth_; i++) + parsedOutput += "\t"; + parsedOutput += CharStringtostring(event.gi); + depth_++; + } + void endElement(const EndElementEvent&) { depth_--; } + std::string parsedOutput; + +private: + unsigned depth_; +}; + +int main() +{ + std::string expectedOutput = "TESTDOC\tTESTELEMENT"; + char file_name[] = "test.sgml"; + char* files[] = { file_name, 0 }; + + ParserEventGeneratorKit parserKit; + EventGenerator* egp = parserKit.makeEventGenerator(1, files); + OutlineApplication app; + unsigned nErrors = egp->run(app); + + assert(nErrors == 0); + assert(app.parsedOutput.compare(expectedOutput) == 0); + + delete egp; + return 0; +} diff --git a/Tests/FindOpenSP/Test/test.sgml b/Tests/FindOpenSP/Test/test.sgml new file mode 100644 index 0000000..bbf0da6 --- /dev/null +++ b/Tests/FindOpenSP/Test/test.sgml @@ -0,0 +1,7 @@ + + +]> + +Hello + -- cgit v0.12