From 8bbc77b0466ceb6fa121d7dfad0215c7c1f87a1b Mon Sep 17 00:00:00 2001 From: adamska <2639980868@qq.com> Date: Fri, 30 Aug 2024 23:55:03 +0800 Subject: [PATCH 1/3] feat(cmake): install --- CMakeLists.txt | 21 +++++++++++++++++---- README.md | 24 +++++++++++++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27bbaf2..f5589cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.22) project(myxml VERSION 0.1) -enable_testing() if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) @@ -16,7 +15,21 @@ endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED on) +add_subdirectory(deps/fmt) add_subdirectory(src) -add_subdirectory(tests) -add_subdirectory(deps/Catch2) -add_subdirectory(deps/fmt) \ No newline at end of file + +install(TARGETS myxml + EXPORT myxml + ARCHIVE DESTINATION lib) + +install(DIRECTORY include/ + DESTINATION include) + +option(BUILD_TESTING "Build the testing tree." ON) + +if (BUILD_TESTING) + enable_testing() + + add_subdirectory(deps/Catch2) + add_subdirectory(tests) +endif() diff --git a/README.md b/README.md index 5b4e265..40df82b 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,11 @@ Contributions are welcome! Read [Contribution Guide](./docs/contribution_guide.m - Integrate DTD/XML Schema Validation - Refactor for Zero-Copy Efficiency -## Build +## Setup -The `cmake install` command is not yes implemented. You can include the repo as a sub directory of your project and use `add_subdirectory()` to use the `myxml` target. +### Dependencies -### Dependency - -To fetch Catch2 testing framework, run: +**myxml** uses git submodule to manage dependencies. Run following commands first: ```bash git submodule init @@ -46,17 +44,29 @@ cmake -S . -B build cmake --build build ``` +If you don't want to compile testing, add `-DBUILD_TESING=OFF` to the configure command. + ### Running tests -Ensure Catch2 is installed correctly. In the project directory, run: +In the project directory, run: ```bash ctest --test-dir build/tests/ ``` +### Installation + +In the project directory, run: + +```bash +cmake --install build +``` + +Then your C++ Compiler will be able to find **myxml** directly. + ### Integration -To integrate myxml, add this repo to your project and modify your root `CMakeLists.txt`: +If you want to integrate **myxml** into your CMake project, add this repo to your project and modify your root `CMakeLists.txt`: ```cmake add_subdirectory(myxml) # or `deps/myxml`, as you like From e3a2ff2d81169267bc0883eeedd30d46d7d3d28e Mon Sep 17 00:00:00 2001 From: adamska <2639980868@qq.com> Date: Fri, 30 Aug 2024 23:57:29 +0800 Subject: [PATCH 2/3] feat(ci): add install job --- .github/workflows/cmake-single-platform.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml index 5f867cb..6555b62 100644 --- a/.github/workflows/cmake-single-platform.yml +++ b/.github/workflows/cmake-single-platform.yml @@ -40,4 +40,25 @@ jobs: # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} + + install: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Initialize Git Submodules + run: | + git submodule update --init + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTING=OFF + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Install + run: cmake --install ${{github.workspace}}/build From 5d5d380cb78777224d66208716f686155c1fe4e5 Mon Sep 17 00:00:00 2001 From: adamska <2639980868@qq.com> Date: Fri, 30 Aug 2024 23:59:37 +0800 Subject: [PATCH 3/3] feat(ci): add sudo in install job --- .github/workflows/cmake-single-platform.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml index 6555b62..93b4f62 100644 --- a/.github/workflows/cmake-single-platform.yml +++ b/.github/workflows/cmake-single-platform.yml @@ -61,4 +61,4 @@ jobs: run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - name: Install - run: cmake --install ${{github.workspace}}/build + run: sudo cmake --install ${{github.workspace}}/build diff --git a/README.md b/README.md index 40df82b..22eae9b 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ ctest --test-dir build/tests/ In the project directory, run: ```bash -cmake --install build +cmake --install build # usually requires root permission ``` Then your C++ Compiler will be able to find **myxml** directly.