From 271f51c1b6082eac1722f5206ca64dcd75f1b5f5 Mon Sep 17 00:00:00 2001 From: software-made-easy Date: Wed, 11 Jan 2023 17:16:45 +0100 Subject: [PATCH] Prepare v1.4.0, see CHANGELOG.md for details --- CHANGELOG.md | 7 +++++ CMakeLists.txt | 59 ++++++++++++++++++++++++++++++------------ MANIFEST.in | 2 +- README.md | 13 ++++++++++ cli/main.cpp | 1 - docs/index.md | 14 ++++++++++ html2mdConfig.cmake.in | 6 +++++ include/html2md.h | 2 +- python/README.md | 6 ----- python/pybind11 | 2 +- setup.py | 5 +--- src/html2md.cpp | 2 +- tests/CMakeLists.txt | 5 ++++ tests/main.cpp | 10 ++++--- 14 files changed, 98 insertions(+), 36 deletions(-) create mode 100644 html2mdConfig.cmake.in diff --git a/CHANGELOG.md b/CHANGELOG.md index 3192d5c..f956428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ [TOC] +## v1.4.0 + +- Improved CMake support massively! +- Fixed tests +- Added support for CMake 3.8 +- Fix Python source package + ## v1.3.0 **BREAKING CHANGES!** diff --git a/CMakeLists.txt b/CMakeLists.txt index d4b4e72..e3b740a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,17 @@ -cmake_minimum_required(VERSION 3.12) -project("html2md" VERSION 1.3.0 - DESCRIPTION "Transform your HTML into clean, easy-to-read markdown with html2md" - HOMEPAGE_URL "https://tim-gromeyer.github.io/html2md/" - LANGUAGES CXX) - -# Build type -if (NOT CMAKE_BUILD_TYPE) +cmake_minimum_required(VERSION 3.8) +project(html2md VERSION 1.4.0 + LANGUAGES CXX) + +set(PROJECT_HOMEPAGE_URL "https://tim-gromeyer.github.io/html2md/") +set(html2md_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}") + +set(PROJECT_DESCRIPTION "Transform your HTML into clean, easy-to-read markdown with html2md") +set(html2md_DESCRIPTION "${PROJECT_DESCRIPTION}") + +# If build type not specified we use release +if (NOT DEFINED CMAKE_BUILD_TYPE) message(STATUS "Build type not specified. Release is used.") set(CMAKE_BUILD_TYPE "Release") -else() - message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") endif() # Improve performance @@ -18,7 +20,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release") string(REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() -# Check if it was included +# Check if it was included via `add_subdirectory` get_directory_property(subproject PARENT_DIRECTORY) # Create HTML for webassembly @@ -29,11 +31,10 @@ endif() # Some options if (subproject) option(BUILD_EXE "Build a executable to convert html to markdown." OFF) - option(BUILD_DOC "Build documentation" OFF) else() option(BUILD_EXE "Build a executable to convert html to markdown." ON) - option(BUILD_DOC "Build documentation" ON) endif() +option(BUILD_DOC "Build documentation" OFF) option(BUILD_TEST "Build tests" OFF) option(PYTHON_BINDINGS "Build python bindings" OFF) @@ -90,17 +91,41 @@ if(subproject) endif() include(GNUInstallDirs) +include(CMakePackageConfigHelpers) install(TARGETS html2md - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/html2md + EXPORT html2mdTargets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/html2md +) +install(EXPORT html2mdTargets + FILE html2mdTargets.cmake + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/html2md" ) configure_file(html2md.pc.in html2md.pc @ONLY) install(FILES ${CMAKE_BINARY_DIR}/html2md.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/html2md + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/html2md +) + if (BUILD_EXE) install(TARGETS html2md-exe DESTINATION bin) endif() diff --git a/MANIFEST.in b/MANIFEST.in index f653df3..476068b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include python/README.md COPYING python/pybind11/LICENSE python/pybind11/CMakeLists.txt CMakeLists.txt +include python/README.md COPYING python/pybind11/LICENSE python/pybind11/CMakeLists.txt CMakeLists.txt python/bindings.cpp graft python/pybind11/include graft python/pybind11/tools graft src diff --git a/README.md b/README.md index 96e001a..0f5a09e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,19 @@ html2md is a fast and reliable C++ library for converting HTML content into mark ## How to use this library +### CMake + +Install html2md. Use eighter the prebild packages from [GitHub releases](https://github.com/tim-gromeyer/html2md/releases) or build and install it yourself. + +Afterwards: + +```cmake +find_package(html2md) +target_link_library(your_target PRIVATE html2md) +``` + +### Manually + To use html2md, follow these steps: 1. Clone the library: `git clone https://github.com/tim-gromeyer/html2md` diff --git a/cli/main.cpp b/cli/main.cpp index 6744051..a13de33 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -133,7 +133,6 @@ int main(int argc, const char* argv[]) { continue; } } - } fstream out; diff --git a/docs/index.md b/docs/index.md index 3062913..98d3b7e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,6 +8,20 @@ html2md is a fast and reliable C++ library for converting HTML content into mark ## How to use this library +### CMake + +Install html2md. Either use the pre-built packages found on [GitHub releases](https://github.com/tim-gromeyer/html2md/releases) or build and install it yourself. + + +Afterwards: + +```cmake +find_package(html2md) +target_link_library(your_target PRIVATE html2md) +``` + +### Manually + To use html2md, follow these steps: 1. Clone the library: `git clone https://github.com/tim-gromeyer/html2md` diff --git a/html2mdConfig.cmake.in b/html2mdConfig.cmake.in new file mode 100644 index 0000000..d42c337 --- /dev/null +++ b/html2mdConfig.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + +set(@PROJECT_NAME@_FOUND TRUE) + diff --git a/include/html2md.h b/include/html2md.h index a628661..12680b9 100644 --- a/include/html2md.h +++ b/include/html2md.h @@ -472,7 +472,7 @@ class Converter { std::map tags_; - explicit Converter(std::string *html, Options *options = nullptr); + explicit Converter(std::string *html, struct Options *options = nullptr); void PrepareHtml(); diff --git a/python/README.md b/python/README.md index 0120b3f..84a28d7 100644 --- a/python/README.md +++ b/python/README.md @@ -17,12 +17,6 @@ You can install using pip: pip3 install pyhtml2md ``` -### Manually - -1. Make sure you have a compiler with c++11 and CMake installed on you system -2. Clone html2md: `git clone https://github.com/tim-gromeyer/html2md --recurse-submodules --depth=1` -3. Build and install the python package: `pip3 install ./html2md/` - ## Basic usage Here is an example of how to use the pyhtml2md to convert HTML to markdown: diff --git a/python/pybind11 b/python/pybind11 index a34596b..0694ec6 160000 --- a/python/pybind11 +++ b/python/pybind11 @@ -1 +1 @@ -Subproject commit a34596bfe1947b4a6b0bcc4218e1f72d0c2e9b4c +Subproject commit 0694ec6a15863bff2e0ea5efe07c78de39b9a33c diff --git a/setup.py b/setup.py index 17b39ed..d0e57e2 100644 --- a/setup.py +++ b/setup.py @@ -60,9 +60,6 @@ def build_extension(self, ext: CMakeExtension) -> None: if "CMAKE_ARGS" in os.environ: cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] - # In this example, we pass in the version to C++. You might not need to. - cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"] # type: ignore[attr-defined] - if self.compiler.compiler_type != "msvc": # Using Ninja-build since it a) is available as a wheel and b) # multithreads automatically. MSVC would require all variables be @@ -133,7 +130,7 @@ def build_extension(self, ext: CMakeExtension) -> None: # logic and declaration, and simpler if you include description/version in a file. setup( name="pyhtml2md", - version="1.3.0", + version="1.4.0", author="Tim Gromeyer", author_email="sakul8826@gmail.com", description="Transform your HTML into clean, easy-to-read markdown with pyhtml2md.", diff --git a/src/html2md.cpp b/src/html2md.cpp index 657ce5a..b89696c 100644 --- a/src/html2md.cpp +++ b/src/html2md.cpp @@ -69,7 +69,7 @@ static string Repeat(const string &str, size_t amount) { namespace html2md { Converter::Converter(string *html, Options *options) - : html_(*html), option(options) { + : html_(*html) { options ? option = options : option = new struct Options(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f86d5f1..197ded4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,6 +18,11 @@ target_compile_definitions(test-exe PUBLIC DIR="${CMAKE_CURRENT_LIST_DIR}") set_target_properties(test-exe PROPERTIES OUTPUT_NAME "tests") target_compile_features(test-exe PUBLIC cxx_std_17) # Require at least c++17 + +if (CMAKE_VERSION VERSION_LESS 3.11.0) + return() +endif() + add_custom_target(test COMMAND $ COMMENT Runing tests.. diff --git a/tests/main.cpp b/tests/main.cpp index 9f6281a..2a184e1 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -39,11 +39,11 @@ string toHTML(const string &md) { }; string fromHTML(string &html) { - html2md::options options; + static html2md::Options options; options.splitLines = false; html2md::Converter c(html, &options); - return c.Convert2Md(); + return c.convert(); } } @@ -102,7 +102,7 @@ void runTest(const string& file, short *errorCount) { } } -int main(int argc, char **argv){ +int main(int argc, const char **argv){ // List to store all markdown files in this dir vector files; @@ -132,7 +132,9 @@ int main(int argc, char **argv){ // Redirect errors to error.log FILE* errorFile = freopen(errorFileName, "w", stderr); - if (errorFile) {} + if (!errorFile) + cerr << "Failed to open " << errorFileName << " for whatever reason!\n" + "Errors will be printed to the terminal instead of written to the mentioned file above."; // For measuring time. auto t1 = high_resolution_clock::now();