├── .github └── workflows │ ├── gh-pags.yml │ ├── linux.yml │ ├── macos.yml │ └── window.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── Dockerfile ├── README.md ├── cmake ├── HunterGate.cmake ├── cmake_option.cmake ├── cppm_install.cmake └── cppm_loader.cmake ├── cppm.toml ├── cppm_demo.gif ├── docs ├── book.toml └── src │ ├── SUMMARY.md │ ├── cppkg_toml.md │ ├── cppm_commands.md │ ├── cppm_guide.md │ ├── cppm_structure.md │ ├── cppm_toml.md │ ├── dependencies.md │ ├── first-steps.md │ ├── getting_started.md │ ├── install.md │ ├── introdution.md │ └── package_layout.md ├── examples ├── boost_filesystem_hunter │ ├── CMakeLists.txt │ ├── cmake │ │ ├── HunterGate.cmake │ │ └── cppm_tool.cmake │ ├── cppm.toml │ └── src │ │ └── main.cpp ├── example.cpp ├── fmt_cppkg │ ├── CMakeLists.txt │ ├── cmake │ │ ├── HunterGate.cmake │ │ └── cppm_tool.cmake │ ├── cppm.toml │ ├── src │ │ └── main.cpp │ └── thirdparty │ │ └── fmt │ │ └── 5.3.0 │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── fmt.cmake.in ├── hello_world │ ├── .gitignore │ ├── CMakeLists.txt │ ├── cmake │ │ └── cppm_tool.cmake │ ├── cppm.toml │ └── src │ │ └── main.cpp └── opencv_hunter │ ├── CMakeLists.txt │ ├── cmake │ ├── HunterGate.cmake │ └── cppm_tool.cmake │ ├── cppm.toml │ └── src │ └── main.cpp ├── include └── cppm │ ├── core │ ├── cmake.hpp │ ├── compiler.hpp │ ├── config.hpp │ ├── cppkg.hpp │ ├── cppm_tool.hpp │ ├── dependency.hpp │ ├── feature.hpp │ ├── hunter.hpp │ ├── package.hpp │ ├── profile.hpp │ ├── target.hpp │ └── workspace.hpp │ ├── cppkg │ ├── cppkg.h │ └── repo.h │ └── util │ ├── algorithm.hpp │ ├── filesystem.h │ ├── hash.hpp │ ├── optional.hpp │ ├── string.hpp │ ├── system.hpp │ ├── toml.hpp │ └── version.h ├── need_to_change.md ├── scripts ├── backup-appveyor.yml └── backup-azure-pipeline.yml ├── src ├── cmake │ ├── cmake.cpp │ └── cmake.h ├── core │ ├── config.cpp │ └── cppm_tool.cpp ├── cppkg │ └── cppkg.cpp ├── cppm_version.h ├── main.cpp ├── option │ ├── add.cpp │ ├── add.h │ ├── base_option.cpp │ ├── base_option.h │ ├── build.cpp │ ├── build.h │ ├── cppkg.cpp │ ├── cppkg.h │ ├── cppkg_init.cpp │ ├── cppkg_init.h │ ├── cppkg_install.cpp │ ├── cppkg_install.h │ ├── cppkg_search.cpp │ ├── cppkg_search.h │ ├── cppm.cpp │ ├── cppm.h │ ├── cppm_config.cpp │ ├── cppm_config.h │ ├── init.cpp │ ├── init.h │ ├── install.cpp │ └── install.h └── util │ ├── algorithm.cpp │ ├── filesystem.cpp │ ├── system.cpp │ └── version.cpp ├── tests ├── test.cpp └── test.h ├── thirdparty ├── Catch2 │ ├── 2.9.1 │ │ ├── Catch2.cmake.in │ │ ├── cppkg.toml │ │ └── dep.cmake │ └── latest │ │ ├── Catch2.cmake.in │ │ └── cppkg.toml ├── ccache │ └── 3.7.9 │ │ ├── ccache.cmake.in │ │ └── cppkg.toml ├── cpptoml │ ├── 0.4.0 │ │ ├── cppkg.toml │ │ └── dep.cmake │ └── git │ │ ├── cppkg.toml │ │ └── dep.cmake ├── ctre │ └── 2.8.1 │ │ ├── cppkg.toml │ │ └── ctre.cmake.in ├── dbg-macro │ └── git │ │ ├── cppkg.toml │ │ ├── dbg-macro.cmake.in │ │ └── dep.cmake ├── fmt │ ├── 6.0.0 │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── fmt.cmake.in │ ├── 6.2.0 │ │ ├── cppkg.toml │ │ └── fmt.cmake.in │ ├── 7.0.3 │ │ ├── cppkg.toml │ │ └── fmt.cmake.in │ ├── 7.1.3 │ │ ├── cppkg.toml │ │ └── fmt.cmake.in │ └── latest │ │ ├── cppkg.toml │ │ └── fmt.cmake.in ├── hash-lib │ └── git │ │ ├── cppkg.toml │ │ └── hash-lib.cmake.in ├── hashpp │ ├── git │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── hashpp.cmake.in │ └── latest │ │ ├── cppkg.toml │ │ └── hashpp.cmake.in ├── md5 │ └── git │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── md5.cmake.in ├── nlohmann_json │ ├── 3.9.1 │ │ ├── cppkg.toml │ │ └── nlohmann_json.cmake.in │ └── latest │ │ ├── cppkg.toml │ │ └── nlohmann_json.cmake.in ├── nlpo │ ├── 0.0.3 │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── nlpo.cmake.in │ └── git │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── nlpo.cmake.in ├── range-v3 │ ├── 0.10.0 │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── range-v3.cmake.in │ ├── 0.11.0 │ │ └── range-v3.cmake.in │ ├── 0.9.0 │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── range-v3.cmake.in │ ├── git │ │ ├── cppkg.toml │ │ ├── dep.cmake │ │ └── range-v3.cmake.in │ └── latest │ │ ├── cppkg.toml │ │ └── range-v3.cmake.in ├── reprocxx │ └── 11.0.0 │ │ ├── cppkg.toml │ │ └── reprocxx.cmake.in ├── serdepp │ └── git │ │ ├── cppkg.toml │ │ └── serdepp.cmake.in └── toml11 │ ├── 3.6.0 │ ├── cppkg.toml │ └── toml11.cmake.in │ └── latest │ ├── cppkg.toml │ └── toml11.cmake.in └── version.h.in /.github/workflows/gh-pags.yml: -------------------------------------------------------------------------------- 1 | name: github pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build-deploy: 10 | runs-on: ubuntu-18.04 11 | steps: 12 | - uses: actions/checkout@v2 13 | 14 | - name: Setup mdBook 15 | uses: peaceiris/actions-mdbook@v1 16 | with: 17 | mdbook-version: '0.3.5' 18 | # mdbook-version: 'latest' 19 | 20 | - run: cd docs && mdbook build 21 | 22 | - name: Deploy 23 | uses: peaceiris/actions-gh-pages@v3 24 | with: 25 | deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} 26 | publish_dir: ./docs/book 27 | -------------------------------------------------------------------------------- /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | name: Linux 2 | 3 | on: [push] 4 | 5 | jobs: 6 | ubuntu-bionic-gcc-11: 7 | runs-on: ubuntu-18.04 8 | steps: 9 | - name: Clone Repository 10 | uses: actions/checkout@master 11 | with: 12 | submodules: true 13 | - name: C++ Setting 14 | run: | 15 | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 16 | sudo apt-get update 17 | sudo apt-get install -yq g++-11 gcc-11 libc++-dev libc++abi-dev build-essential libstdc++-11-dev 18 | - name: Compiler Setting 19 | run: | 20 | echo "CC=gcc-11" >> $GITHUB_ENV 21 | echo "CXX=g++-11" >> $GITHUB_ENV 22 | - name: CMake build 23 | run: cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DUSE_CPPM_PATH=ON . && cd build && cmake --build . --target install --target cppm_link 24 | ubuntu-bionic-llvm-8: 25 | runs-on: ubuntu-18.04 26 | steps: 27 | - name: Clone Repository 28 | uses: actions/checkout@master 29 | with: 30 | submodules: true 31 | - name: C++ Setting 32 | run: | 33 | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 34 | wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - 35 | sudo add-apt-repository -y "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main" 36 | sudo apt-get update 37 | sudo apt-get install -yq clang-8 libc++-dev libc++abi-dev libstdc++-8-dev build-essential 38 | - name: Compiler Setting 39 | run: | 40 | echo "CC=clang-8" >> $GITHUB_ENV 41 | echo "CXX=clang++-8" >> $GITHUB_ENV 42 | - name: CMake build 43 | run: cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DUSE_CPPM_PATH=ON . && cd build && cmake --build . --target install --target cppm_link 44 | 45 | -------------------------------------------------------------------------------- /.github/workflows/macos.yml: -------------------------------------------------------------------------------- 1 | name: MacOS 2 | 3 | on: [push] 4 | 5 | jobs: 6 | macos-clang: 7 | runs-on: macos-latest 8 | steps: 9 | - name: Clone Repository 10 | uses: actions/checkout@master 11 | with: 12 | submodules: true 13 | - name: C++ Setting 14 | run: | 15 | brew install llvm cmake 16 | - name: Compiler Setting 17 | run: | 18 | echo "CC=clang" >> $GITHUB_ENV 19 | echo "CXX=clang++" >> $GITHUB_ENV 20 | - name: CMake build 21 | run: CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DUSE_CPPM_PATH=ON . && cd build && cmake --build . --target install --target cppm_link 22 | 23 | 24 | # runs-on: macos-latest 25 | # strategy: 26 | # matrix: 27 | # c-compiler: [gcc, clang] 28 | # cxx-compiler: [g++, clang++] 29 | # steps: 30 | # - name: Clone Repository 31 | # uses: actions/checkout@master 32 | # - name: Compiler Setting 33 | # run: echo Compiler Setting 34 | # env: 35 | # CC: ${{matrix.compiler}} 36 | # - name: CMake build 37 | # run: cmake -Bbuild . && cd build && cmake --build . 38 | # - name: Cppm build install 39 | # run: cd build && ./cppm build install 40 | -------------------------------------------------------------------------------- /.github/workflows/window.yml: -------------------------------------------------------------------------------- 1 | name: Windows 2 | 3 | on: [push] 4 | 5 | jobs: 6 | windows-msvc: 7 | runs-on: windows-2019 8 | strategy: 9 | matrix: 10 | build-type: ['Release', 'Debug'] 11 | steps: 12 | - name: Clone Repository 13 | uses: actions/checkout@master 14 | with: 15 | submodules: true 16 | - name: CMake build 17 | run: | 18 | cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -DUSE_CPPM_PATH=ON . 19 | cd build 20 | cmake --build . --config ${{matrix.build-type}} --target install --target cppm_link 21 | - name: Cppm build install 22 | run: | 23 | cd build/${{matrix.build-type}} 24 | ./cppm build -h 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .ccls-cache/ 3 | compile_commands.json 4 | docs/book/ 5 | .DS_Store 6 | .vscode/ 7 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "nlpo"] 2 | path = libs/nlpo 3 | url = https://github.com/injae/nlpo.git 4 | [submodule "libs/tomlpp"] 5 | path = libs/tomlpp 6 | url = https://github.com/injae/cpptoml.git 7 | [submodule "cppm-loader"] 8 | path = cmake/cppm-loader 9 | url = https://github.com/injae/cppm-loader.git 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | sudo: required 3 | matrix: 4 | include: 5 | ## Clang 6.0 6 | #- env: COMPILER=clang++-6.0 7 | # addons: &defaults { apt: { packages: ["clang-6.0", "valgrind"], sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-6.0"] } } 8 | 9 | # Clang 8.0 10 | - os: linux 11 | dist: xenial 12 | compiler: clang 13 | env: 14 | - MATRIX_EVAL="CXX=clang++-8" 15 | - SUDO="sudo env \"PATH=$PATH\"" 16 | addons: { apt: { packages: ["clang-8", "libc++-dev", "libc++abi-8-dev", "libstdc++-8-dev", "build-essential", "ccache"], sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-8"] } } 17 | cache: {apt: true, ccache: true, directories: ["$HOME/.hunter"]} 18 | ## GCC 6 19 | #- env: COMPILER=g++-6 20 | # addons: { apt: { packages: ["g++-6", "valgrind"], sources: ["ubuntu-toolchain-r-test"] } } 21 | 22 | # GCC 7 23 | - os: linux 24 | dist: xenial 25 | compiler: gcc 26 | env: 27 | - MATRIX_EVAL="CXX=g++-8" 28 | - SUDO="sudo env \"PATH=$PATH\"" 29 | addons: { apt: { packages: ["g++-8", "libc++-dev", "libc++abi-dev", "build-essential", "libstdc++-8-dev", "ccache"], sources: ["ubuntu-toolchain-r-test"] } } 30 | cache: {apt: true, ccache: true, directories: ["$HOME/.hunter"]} 31 | 32 | #- os: osx 33 | # env: SUDO="" 34 | # #addons: { homebrew: { packages: ["cmake", "ccache"]}} 35 | # osx_image: xcode10 36 | # cache: { directories: "$HOME/Library/Caches/Homebrew"} 37 | 38 | 39 | before_install: 40 | - eval "${MATRIX_EVAL}" 41 | # - if ["TRAVIS_OS_NAME"=="osx"]; then brew update; fi 42 | # - if ["TRAVIS_OS_NAME"=="osx"]; then brew install cmake; fi 43 | # - if ["TRAVIS_OS_NAME"=="osx"]; then brew install ccache; fi 44 | 45 | script: 46 | - eval "${SUDO}" cmake -H. -Bbuild 47 | - cd build && eval "${SUDO}" cmake --build . ; 48 | 49 | #import: 50 | # - docs/.travis.yml 51 | 52 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | set(CPPM_VERSION 0.0.13) 4 | include(cmake/cppm_loader.cmake) 5 | cppm_project() 6 | 7 | project(cppm VERSION 0.0.13 LANGUAGES C CXX) 8 | cppm_setting() 9 | cppm_cxx_standard(17) 10 | cppm_compiler_option(DEFAULT) 11 | 12 | include(cmake/cppm_install.cmake) 13 | find_cppkg(hash-lib git MODULE hash-lib::hash-lib TYPE lib) 14 | find_cppkg(serdepp git MODULE serdepp::serdepp TYPE lib) 15 | find_cppkg(nlpo git MODULE nlpo::nlpo TYPE lib) 16 | find_cppkg(range-v3 git MODULE range-v3::range-v3 TYPE lib) 17 | 18 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 19 | find_cppkg(Catch2 2.9.1 MODULE Catch2::Catch2 TYPE lib) 20 | endif() 21 | 22 | 23 | cppm_target_define(cppm-core INTERFACE) 24 | 25 | cppm_target_define(cppm BINARY 26 | SOURCES 27 | src/core/config.cpp 28 | src/core/cppm_tool.cpp 29 | src/cmake/cmake.cpp 30 | src/util/version.cpp 31 | src/util/filesystem.cpp 32 | src/util/algorithm.cpp 33 | src/util/system.cpp 34 | src/option/cppkg_install.cpp 35 | src/option/cppm.cpp 36 | src/option/cppkg_search.cpp 37 | src/option/base_option.cpp 38 | src/option/cppm_config.cpp 39 | src/option/cppkg_init.cpp 40 | src/option/cppkg.cpp 41 | src/option/init.cpp 42 | src/option/add.cpp 43 | src/option/build.cpp 44 | src/option/install.cpp 45 | src/cppkg/cppkg.cpp 46 | src/main.cpp 47 | ) 48 | 49 | cppm_examples_area() 50 | if(CPPM_BUILD_EXAMPLES) 51 | 52 | cppm_target_define(cppm-core-load BINARY 53 | SOURCES 54 | examples/example.cpp 55 | ) 56 | 57 | endif() 58 | 59 | 60 | set(cppm_global_deps PRIVATE hash-lib nlpo range-v3 61 | PUBLIC serdepp) 62 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 63 | list(APPEND cppm_global_deps PRIVATE Catch2) 64 | endif() 65 | cppm_target_dependencies(cppm-core 66 | ${cppm_global_deps}) 67 | 68 | cppm_target_dependencies(cppm 69 | ${cppm_global_deps} 70 | cppm-core) 71 | 72 | cppm_target_dependencies(cppm-core-load 73 | ${cppm_global_deps} 74 | cppm-core) 75 | 76 | 77 | cppm_target_install(cppm-core) 78 | cppm_target_install(cppm) 79 | cppm_target_install(cppm-core-load) 80 | 81 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | RUN apt-get update && \ 3 | apt-get install -y software-properties-common apt-transport-https \ 4 | ca-certificates gnupg software-properties-common wget 5 | RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y 6 | RUN wget -qO - https://apt.kitware.com/keys/kitware-archive-latest.asc | apt-key add - 7 | RUN apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' 8 | RUN apt-get update 9 | RUN apt-get upgrade -y 10 | RUN apt-get install g++-9 valgrind build-essential git cmake -y 11 | RUN rm -rf /var/lib/apt/lists/* 12 | RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 100 13 | 14 | COPY ./ /app/ 15 | WORKDIR /app 16 | 17 | RUN cmake -H. -Bbuild 18 | RUN cd build && cmake -DUSE_CPPM_PATH=ON -DCMAKE_BUILD_TYPE=Debug .. && cmake --build . --config Debug 19 | RUN cd build/Debug && ./server 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [Cppm](https://injae.github.io/cppm/) ***(BETA)*** [Documents](https://injae.github.io/cppm/) 4 | ======== 5 | |Linux|Windows|MacOS| 6 | |:----|:------|:----| 7 | ![Linux](https://github.com/injae/cppm/workflows/Linux/badge.svg) | ![Windows](https://github.com/injae/cppm/workflows/Windows/badge.svg) | ![MacOS](https://github.com/injae/cppm/workflows/MacOS/badge.svg) | 8 | 9 | ![](cppm_demo.gif) 10 | 11 | ## Dependencies 12 | - c++ compiler (c++17) 13 | - CMake (minimum 3.12) 14 | - Git 15 | - Ccache (optional) 16 | 17 | > My native language is not English. 18 | > Since I used a translator, please let me know if you have any problems with grammar. 19 | > This project was inspired by Rust's Cargo. 20 | > Cppm is a cross platform C++ project manager 21 | > So the configuration of the configuration file is almost similar to Rust's Cargo.toml. 22 | > Using cppm, you can easily create a cross-platform c ++ project. 23 | > Projects made with cppm only need c ++ compiler, cmake and git. 24 | > Projects written in cppm automatically install dependencies. 25 | > Not many libraries are supported by the cppkg yet. But cppkg package make easy 26 | > So cppm made the package of the [Hunter Package Manager](https://github.com/ruslo/hunter) available. 27 | > If there is a library you want to add, please issue a pull request to the [Cppkg repository](https://github.com/injae/cppkg) 28 | > Cppm auto detect vcpkg toolchain. 29 | 30 | ## Easy Config file 31 | ```toml 32 | # cppm project config file 33 | [package] 34 | name = "cppm" 35 | version = "0.0.10" 36 | description = "c++ cmake maker use to toml like Cargo" 37 | git = "https://github.com/injae/cppm.git" 38 | #vcpkg =true # vcpkg auto detect flag, but not recommended option 39 | 40 | [cmake] 41 | include = ["cmake/cppm_install.cmake"] 42 | 43 | [lib] 44 | name = "cppm-core" 45 | source = ["src/core/.*", "src/util/.*", "src/cppkg/.*"] 46 | 47 | [[bin]] 48 | name = "cppm" 49 | source = ["src/cmake/.*","src/option/.*", "src/util/.*", "src/main.cpp"] 50 | 51 | [[test]] 52 | name = "cppm-test-check" 53 | source = ["tests/test.cpp"] 54 | 55 | [[example]] 56 | name = "cppm-core-load" 57 | source = ["examples/example.cpp"] 58 | 59 | [workspace] 60 | member = ["libs/nlpo", "libs/tomlpp"] 61 | 62 | [dependencies] 63 | fmt = "6.2.0" 64 | hashpp = "git" 65 | range-v3 = "git" 66 | 67 | [dev-dependencies] 68 | Catch2 = "2.9.1" 69 | 70 | #[target.x64-unix.dependencies] 71 | #[target.x64-unix.dev-dependencies] 72 | #[target.x64-windows.dependencies] 73 | #[target.windows.dev-dependencies] 74 | ``` 75 | 76 | ## Easy to make Unregistered Package Add 77 | ```console 78 | $ cd {package root}/thirdparty 79 | $ cppm cppkg init -U "https://github.com/fmtlib/fmt/releases/download/6.2.0/fmt-6.2.0.zip" fmt 80 | ``` 81 | ```toml 82 | # fmt/6.2.0/cppkg.toml 83 | [fmt] 84 | version = "6.2.0" 85 | description = "" 86 | module = "fmt::fmt" 87 | url="https://github.com/fmtlib/fmt/releases/download/6.2.0/fmt-6.2.0.zip" 88 | ``` 89 | 90 | ```console 91 | $ cd {package root}/thirdparty 92 | $ cppm cppkg init -U "https://github.com/fmtlib/fmt.git" fmt 93 | ``` 94 | ```toml 95 | # fmt/git/cppkg.toml 96 | [fmt] 97 | version = "git" 98 | description = "" 99 | module = "fmt::fmt" 100 | git="https://github.com/fmtlib/fmt.git" 101 | flags="-DFMT_DOC=OFF -DFMT_TEST=OFF -DFMT_FUZZ=OFF" # (optional) for cmake build fast flags 102 | ``` 103 | 104 | ## Installation 105 | ### Linux 106 | ```console 107 | # install c++17 compiler, cmake and git 108 | git clone --recurse-submodules https://github.com/injae/cppm.git 109 | cd cppm 110 | cmake -Bbuild -DCMAKE_BUILD_TYPE=Release 111 | cd build 112 | cmake --build . --config Release 113 | cd Release 114 | ./cppm build install 115 | # Adding to cppm path 116 | export PATH="$HOME/.cppm/bin:$PATH" 117 | ``` 118 | 119 | 120 | ### Macos 121 | ```console 122 | # AppleClang not working (can't use filesystem and optional) 123 | brew install llvm cmake 124 | # Adding to llvm clang env 125 | # export CC=#llvm clang path 126 | # export CXX=#llvm clang++ path 127 | git clone --recurse-submodules https://github.com/injae/cppm.git 128 | cd cppm 129 | cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DUSE_CPPM_PATH=ON . 130 | cd build 131 | cmake --build . --config Release 132 | cd Release 133 | ./cppm build install 134 | # Adding to cppm path 135 | export PATH="$HOME/.cppm/bin:$PATH" 136 | ``` 137 | ### Windows 138 | ```console 139 | # need visual studio , git , cmake 140 | # scoop install git cmake 141 | git clone --recurse-submodules https://github.com/injae/cppm.git 142 | cd cppm 143 | cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DUSE_CPPM_PATH=ON . 144 | cd build 145 | cmake --build . --config Release --target install --target cppm_link 146 | # Add System Path %USERPROFILE%\.cppm\bin 147 | ``` 148 | 149 | ## Features 150 | - [x] easy configure file (cppm.toml) 151 | - [x] generate build command (cppm build {options}) 152 | - [x] cmake dependencies auto installer (cppkg) 153 | - [x] none cppm base project build (cppm build) (with cppm-toolchain) command 154 | - [x] easy cppkg file generator (cppm cppkg init) 155 | - [x] auto add CMake project uninstall target (cppm build uninstall) (with cppm-toolchain) 156 | - [x] no sudo, package local install path (~/.cppm/) 157 | - [x] unit test option (cppm test) 158 | - [x] Cppkg package search (cppm search) 159 | - [x] cmake project initialize (cppm init {options} {name}) 160 | - [x] cppkg repository update (cppm cppkg update) 161 | - [x] hunter package dependency available 162 | - [x] auto detect vcpkg 163 | - [x] can use hunter package manager 164 | - [x] sub project option (cppm.toml [workspace]) 165 | 166 | ## Document 167 | ### [GitBook](https://injae.github.io/cppm/) 168 | -------------------------------------------------------------------------------- /cmake/cmake_option.cmake: -------------------------------------------------------------------------------- 1 | 2 | # detect operating system 3 | message(STATUS "We are on a ${CMAKE_SYSTEM_NAME} system") 4 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 5 | add_definitions(-DSYSTEM_LINUX) 6 | endif() 7 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") 8 | add_definitions(-DSYSTEM_DARWIN) 9 | endif() 10 | if(${CMAKE_SYSTEM_NAME} STREQUAL "AIX") 11 | add_definitions(-DSYSTEM_AIX) 12 | endif() 13 | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 14 | add_definitions(-DSYSTEM_WINDOWS) 15 | endif() 16 | 17 | # detect host processor 18 | message(STATUS "The host processor is ${CMAKE_HOST_SYSTEM_PROCESSOR}") 19 | -------------------------------------------------------------------------------- /cmake/cppm_install.cmake: -------------------------------------------------------------------------------- 1 | file(MAKE_DIRECTORY ${CPPM_CORE}/cmake) 2 | file(MAKE_DIRECTORY ${CPPM_CORE}/repo) 3 | file(MAKE_DIRECTORY ${CPPM_CORE}/share) 4 | file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake DESTINATION ${CPPM_MODULE}) 5 | file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/cmake/HunterGate.cmake DESTINATION ${CPPM_MODULE}) 6 | 7 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.h.in" 8 | "${CMAKE_CURRENT_SOURCE_DIR}/src/cppm_version.h") 9 | 10 | include(${CPPM_CORE}/cppkg/updater.cmake) 11 | -------------------------------------------------------------------------------- /cmake/cppm_loader.cmake: -------------------------------------------------------------------------------- 1 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")) 2 | set(env_home "$ENV{USERPROFILE}") 3 | else() 4 | set(env_home "$ENV{HOME}") 5 | endif() 6 | string(REPLACE "\\" "/" HOME "${env_home}") 7 | 8 | set(CPPM_ROOT ${HOME}/.cppm) 9 | set(CPPM_LOADER_CACHE ${CPPM_ROOT}/cache/cppm-loader/git) 10 | set(CPPM_LOADER_PATH ${CPPM_ROOT}/cmake/cppm-loader) 11 | 12 | if(NOT DEFINED IS_CPPM_LOADER_LOADED) 13 | set(_install_script "${CPPM_LOADER_CACHE}/install-script") 14 | file(WRITE ${_install_script}/CMakeLists.txt 15 | "cmake_minimum_required(VERSION 3.6) 16 | project(CPPM_LOADER_DOWNLOAD NONE) 17 | include(ExternalProject) 18 | ExternalProject_Add(cppm-loader 19 | GIT_REPOSITORY https://github.com/injae/cppm-loader.git 20 | SOURCE_DIR ${CPPM_LOADER_PATH} 21 | BINARY_DIR ${CPPM_LOADER_CACHE}/build 22 | CONFIGURE_COMMAND \"\" 23 | BUILD_COMMAND \"\" 24 | INSTALL_COMMAND \"\" 25 | )" 26 | ) 27 | execute_process(COMMAND cmake . WORKING_DIRECTORY ${_install_script} OUTPUT_QUIET) 28 | execute_process(COMMAND cmake --build . WORKING_DIRECTORY ${_install_script} OUTPUT_QUIET) 29 | endif() 30 | include(${CPPM_LOADER_PATH}/load.cmake) 31 | -------------------------------------------------------------------------------- /cppm.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cppm" 3 | version = "0.0.13" 4 | description = "c++ cmake maker use to toml like Cargo" 5 | git = "https://github.com/injae/cppm.git" 6 | #tool-version = "dev" 7 | 8 | [cmake] 9 | include = ["cmake/cppm_install.cmake"] 10 | 11 | [features] 12 | default = [ "json", "toml" ] # default flags set ON 13 | json = ["serdepp/json"] 14 | toml = ["serdepp/toml11"] 15 | test = ["$USE_CPPM_TEST"] # default value is OFF 16 | 17 | [lib] 18 | name = "cppm-core" 19 | type ="header-only" 20 | 21 | [[bin]] 22 | name = "cppm" 23 | source = ["src/.*.cpp"] 24 | 25 | [[test]] 26 | name = "cppm-test-check" 27 | source = ["tests/test.cpp"] 28 | 29 | [[example]] 30 | name = "cppm-core-load" 31 | source = ["examples/example.cpp"] 32 | 33 | #[workspace] 34 | # member = ["libs/hashpp"] 35 | 36 | [dependencies] 37 | range-v3 = "git" 38 | nlpo = "git" 39 | #serdepp = {version="git", features=[ "xxx" ], default_features=false} 40 | serdepp = {version="git", link="public", features=["json", "toml"]} 41 | hash-lib = "git" 42 | 43 | [dev-dependencies] 44 | Catch2 = "2.9.1" 45 | 46 | #[target.all-osx-clang.dependencies] 47 | # dbg-macro = "git" -------------------------------------------------------------------------------- /cppm_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/injae/cppm/68c337ee9d7cb73976c83706e5f199406a85e2a9/cppm_demo.gif -------------------------------------------------------------------------------- /docs/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | authors = ["injae"] 3 | language = "en" 4 | multilingual = false 5 | src = "src" 6 | title = "The Cppm Book" 7 | -------------------------------------------------------------------------------- /docs/src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | - [Introdution](./introdution.md) 4 | - [Getting Started](./getting_started.md) 5 | - [Installation](./install.md) 6 | - [First Steps with Cppm](./first-steps.md) 7 | - [Cppm Guide](./cppm_guide.md) 8 | - [Package Layout](./package_layout.md) 9 | - [Cppm Structure](./cppm_structure.md) 10 | - [cppm.toml](./cppm_toml.md) 11 | - [Dependencies](./dependencies.md) 12 | - [Cppm Commands](./cppm_commands.md) 13 | -------------------------------------------------------------------------------- /docs/src/cppkg_toml.md: -------------------------------------------------------------------------------- 1 | ## cppkg.toml 2 | this setting is same [dependency.${dep name}] 3 | ```toml 4 | [${name}] 5 | version = "x.x.x|git|latest(hunter only)" 6 | type = "lib(default)|bin|cmake(incomplete)" 7 | git = "..." # if git version 8 | url = "..." # if x.x.x version 9 | module = "..." # (require) 10 | link = "public(default)|private|interface" 11 | custom = "false(default)|true" # this config table export ${name}.cmake.in 12 | # if you wan't custom ${name}.cmake.in this option set true 13 | repo = "cppkg(default)|hunter" 14 | flags="${cmake build flags}" 15 | components = "..." 16 | ``` 17 | -------------------------------------------------------------------------------- /docs/src/cppm_commands.md: -------------------------------------------------------------------------------- 1 | # Cppm Commands 2 | - ***cppm build *** 3 | - ***cppm cppkg *** 4 | - ***cppm init *** 5 | - ***cppm test *** 6 | - ***cppm update *** 7 | -------------------------------------------------------------------------------- /docs/src/cppm_guide.md: -------------------------------------------------------------------------------- 1 | ## Cppm Guide 2 | * [cppm.toml](./cppm_toml.md) 3 | * [cppkg.toml](./cppkg_toml.md) 4 | -------------------------------------------------------------------------------- /docs/src/cppm_structure.md: -------------------------------------------------------------------------------- 1 | ## Cppm Structure 2 | cppm use cmake toolchain feature 3 | cppm build command use CMakeCache.txt 4 | 5 | ***cppm build*** command search cppm.toml or CMakeLists.txt 6 | ```console 7 | $ cppm build --detail 8 | cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/.cppm/cppkg/cppm-tools-0.0.11/toolchain.cmake -DUSE_CPPM_PATH=ON -DCMAKE_BUILD_TYPE=Debug .. && cmake --build . --config Debug -- -j{your cpu core} 9 | ``` 10 | 11 | ~~~console 12 | ~/.cppm/ 13 | ├── bin # cppm installed binary path (symbolic links) 14 | │ └── cppm # -> ../share/cppm-0.0.10/bin/cppm 15 | ├── cache ... # cmake build cache 16 | ├── cmake # cppm module path 17 | │ ├── HunterGate.cmake # if you use hunter package this file copy your package cmake/HunterGate.cmake 18 | │ └── cppm_tool.cmake 19 | ├── repo # cppkg regiested package installer path 20 | │ └── cppkg 21 | │ ├── Catch2 22 | │ │   ├── 2.9.1 23 | │ │   │   ├── Catch2.cmake.in 24 | │ │   │   └── cppkg.toml 25 | │ │   └── git 26 | │ │   ├── Catch2.cmake.in 27 | │ │   └── cppkg.toml 28 | │ ├── cppm 29 | │ │   └── git 30 | │ .   ├── cppkg.toml 31 | │ .   └── cppm.cmake.in 32 | └── cppkg # cppkg install path 33 | ├── cppm-0.0.11 34 | . ├── bin ... 35 | . ├── include ... 36 | . └── lib ... 37 | 38 | ~~~ 39 | -------------------------------------------------------------------------------- /docs/src/cppm_toml.md: -------------------------------------------------------------------------------- 1 | # cppkg.toml 2 | ```toml 3 | [package] 4 | name = "..." # (require) 5 | version = "..." # (require) 6 | desciprtion = "..." # (require) 7 | standard = "{11|14|17(default)|20}" 8 | git = "..." # this option use to cppm build --export 9 | vcpkg= "false(default)|true" # cppm auto detect vcpkg option 10 | tool-version = "{cppm-tool version | dev | current cppm version(default)}" 11 | ``` 12 | ```toml 13 | [hunter] # (optional) hunter package manager setting option 14 | use = true|false(default) # if you use hunter package this option is default is true 15 | url = "..." # custom hunter version url setting option, [ url, sha1 ] is pair 16 | sha1 = "..." # custom hunter version sha1 setting option, [ url, sha1 ] is pair 17 | ``` 18 | ```toml 19 | [cmake] # (optional) cmake setting option 20 | include = ["xxx.cmake", ...] # this option is include cmake file 21 | version = "..." # minimum cmake version setting option default is 3.12 22 | option = "..." # cmake build option use to command 'cppm build' 23 | toolchains = "..." # (incomplete) cmake toolchains option 24 | ``` 25 | 26 | ```toml 27 | [features] (incomplete) 28 | ``` 29 | 30 | Profiles 31 | Prfiles provide a way alter the compiler settings, 32 | Profile settings can be overridden for specific packages 33 | ```toml 34 | [profile.dev] # this is only debug or test or example mode compiler option 35 | [profile.release] # this is only release mode compiler option 36 | [profile.test] # (incomplete) this is only test mode compiler option 37 | [profile.release.compiler] # this is only release mode compiler option 38 | clang = "..." # compiler option 39 | gcc = "..." # compiler option 40 | msvc = "..." # compiler option 41 | [profile.release.package.{package.name}] # (incomplete) override for specific packages 42 | [profile.release.package.{package_name}.compiler] # (incomplete) this is only release mode compiler option 43 | ``` 44 | ```toml 45 | [[bin]] 46 | name = "..." # target name (require) 47 | sources = ["src/ss/.*", src/xx.cpp, ...] # (require), source files, you can use regex 48 | install = true(default)|false # disable install setting 49 | ``` 50 | ```toml 51 | [lib] 52 | name = "..." # target name, export cmake package name 53 | type = "static(default)|shared|hearder-only" 54 | namespace = "... " (default: [package.name]) # cmake export namespace 55 | sources = ["src/xxx.cpp", ...] # type = "header_only" this option not working 56 | install = true(default)|false # disable install setting 57 | ``` 58 | ```toml 59 | [[test]] 60 | name = "..." # target name, export cmake package name 61 | type = "binary(default)|static|shared|hearder-only" 62 | sources = ["src/xxx.cpp", ...] # use source files, type = "header_only" no nessasery this optio 63 | install = true|false(default) # disable install setting 64 | ``` 65 | ```toml 66 | [[example]] 67 | name = "..." # target name, export cmake package name 68 | type = "binary(default)|static|shared|hearder-only" 69 | sources = ["src/xxx.cpp", ...] # use source files, type = "header_only" no nessasery this option 70 | install = true|false(default) # disable install setting 71 | ``` 72 | ```toml 73 | # sub project setting 74 | [workspace] 75 | member = ["path/", "path"] 76 | ``` 77 | ```toml 78 | [dev-dependency] # this dependency only work debug mode 79 | [dependencies] 80 | # cppkg package add dependency 81 | # name version(require) 82 | ... = "x.x.x|git|latest" # this config find cppkg.toml in ${package root}/thirdparty/${name}/${version}/cppkg.toml 83 | # inline dependency setting 84 | # name (require) (optional) (optional) default is public (optional) package type 85 | ... = {module = "..." , version ="...", components="... ...", link = "public|private|interface", type="lib(default)|bin|cmake(incomplete)", repo="cppkg(default)|hunter", optional=true|false(default) } 86 | # hunter package add dependency 87 | # name (require) (optional) (optional) default is public (require) load hunter package 88 | ... = {module = "..." , version ="latest", components="... ...", link = "public|private|interface" , repo="hunter" } 89 | # none cmake package add dependency 90 | # name (require) (optional) (optional) default is public (require) none cmake package 91 | ... = {module = "...", components="... ...", lnk_type = "public|private|interface", no_module= true } 92 | # module is name that cmake find_package 93 | # matched cmake scirpt 94 | # find_package(${name} ${version} COMPONENTS ${components}) 95 | # target_link_libraries(${target} ${lnk_type} ${module}) 96 | #link.public => this library use header and source , dependency foward 97 | #link.private => this library use source only, dependency not forward 98 | #link.interface => this library use header only, dependency forward 99 | ``` 100 | ```toml 101 | [target.{triplet}.dependencies] 102 | [target.{triplet}.dev-dependencies] 103 | 104 | # triplet types 105 | # {arch}-{platform}-{compiler} 106 | # arch 107 | # x86 or x64 or arm or arm64 or arm64s or arm7s or all(default) 108 | # platform 109 | # ( unix ) ( windows ) 110 | # linux or osx or freebsd or android or uwp or windows 111 | # compiler 112 | # ( clang ) 113 | # clang or clang_cl apple_clang or gnu(gcc) or msvc(cl) or intel or cuda(nvidia) 114 | 115 | ## example 116 | [target.x64-windows-msvc.dependencies] 117 | [target.all-windows-msvc.dependencies] 118 | [target.windows.dependencies] 119 | [target.unix.dependencies] 120 | [target.x64-macos-apple_clang.dependencies] 121 | [target.x64-macos-clang.dependencies] 122 | [target.macos.dependencies] 123 | [target.linux.dependencies] 124 | ``` 125 | ```toml 126 | # (incomplete) 127 | [exclude] 128 | 129 | ``` 130 | ```toml 131 | # (incomplete) 132 | [ci.github_action] 133 | [ci.appveyer] 134 | [ci.azure] 135 | [ci.travis] 136 | ``` 137 | -------------------------------------------------------------------------------- /docs/src/dependencies.md: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | ***[cppkg](https://github.com/injae/cppkg)*** is cppm central package repository 3 | cppm use it by default to find requested packages 4 | if you want to use ***[Hunter Package Manager](https://github.com/cpp-pm/hunter)*** manager set repo="hunter" 5 | cppm auto detect vcpkg (with package.vcpkg config) 6 | you can find package with ***cppm cppkg search*** 7 | ```console 8 | $ cppm cppkg search -h 9 | Usage: 10 | cppm cppkg search [--verbose] 11 | 12 | Option: 13 | --all [-a] :show all package 14 | --help [-h] :show cppm commands and options 15 | --repo [-r] {repo name} :show {repo_name}'s packages # cppkg or hunter 16 | ``` 17 | 18 | ## Adding a Dependency 19 | add ***[dependencies]*** in your ***cppm.toml***file 20 | ```toml 21 | [dependencies] 22 | fmt = "6.2.0" 23 | ``` 24 | Re-run ***cppm build***, and Cppm Search yout package thirdparty directory ***thirdparty/fmt/6.2.0/cppkg.toml*** 25 | if can't find it cppm search from ***[cppkg](https://github.com/injae/cppkg)*** repository and copy to ***thirdparty/fmt/6.2.0/cppkg.toml*** 26 | 27 | You can easily add unregistered packages 28 | 29 | If you want to add unregistered package need to make cppkg.toml file 30 | cmake base unregistered package is only need 3 config ***version*** ***git or url*** *** module *** 31 | no cmake base package need to [custom downloader](#custom-downloader) 32 | cppm provides commands to create cppkg.toml 33 | # cppkg file generate command 34 | ```console 35 | $ cppm run cppkg init -h 36 | Usage: 37 | cppm cppkg init [--verbose] 38 | 39 | Option: 40 | --des [-d] {description} :add description 41 | --flags [-f] {arg} :add cmake build flags 42 | --git [-g] {repo} :add git repo 43 | --git_tag [-t] {tag} :add git tag 44 | --help [-h] :show cppm commands and options 45 | --module [-m] {module} :add module name 46 | --type [-t] {arg} :add type default is lib 47 | --uri [-U] {arg} :auto detect uri or git and version 48 | --url [-u] {url} :add url repo Require --version 49 | --version [-v] {version} :add library version Require --version 50 | ``` 51 | 52 | ### Example fmt library 53 | 6.2.0 version config 54 | ```toml 55 | # thirdparty/fmt/6.2.0/cppkg.toml 56 | [fmt] 57 | version = "6.2.0" 58 | description = "A modern formatting library" 59 | module = "fmt::fmt" 60 | url="https://github.com/fmtlib/fmt/releases/download/6.2.0/fmt-6.2.0.zip" 61 | flags="-DFMT_DOC=OFF -DFMT_TEST=OFF -DFMT_FUZZ=OFF" # (optional) for cmake build fast flags 62 | ``` 63 | 64 | git repository version 65 | git version dependency always version check in CMake build step 66 | ```toml 67 | # thirdparty/fmt/git/cppkg.toml 68 | [fmt] 69 | version = "git" 70 | description = "A modern formatting library" 71 | module = "fmt::fmt" 72 | git="https://github.com/fmtlib/fmt.git" 73 | flags="-DFMT_DOC=OFF -DFMT_TEST=OFF -DFMT_FUZZ=OFF" # (optional) for cmake build fast flags 74 | ``` 75 | 76 | ### Easy Way to use cppkg init command 77 | ```console 78 | # fmt 6.2.0 79 | $ cppm cppkg init -u "https://github.com/fmtlib/fmt/releases/download/6.2.0/fmt-6.2.0.zip" -v "6.2.0" -m "fmt::fmt" fmt 80 | # or (auto detect version) 81 | $ cppm cppkg init -U "https://github.com/fmtlib/fmt/releases/download/6.2.0/fmt-6.2.0.zip" fmt 82 | # fmt git 83 | $ cppm cppkg init -U "https://github.com/fmtlib/fmt.git" fmt 84 | # or (auto detect version) 85 | $ cppm cppkg init -g "https://github.com/fmtlib/fmt.git" -m "fmt::fmt" fmt 86 | # fmt 6.2.0 with cmake flags 87 | $ cppm cppkg init -U "https://github.com/fmtlib/fmt/releases/download/6.2.0/fmt-6.2.0.zip" --flags "-DFMT_DOC=OFF -DFMT_TEST=OFF -DFMT_FUZZ=OFF" fmt 88 | ``` 89 | 90 | Hunter package manager version 91 | ```toml 92 | # cppm.toml 93 | [dependencies] 94 | fmt = {version="latest", module="fmt::fmt", repo="hunter"} 95 | ``` 96 | ### Custom Downloader 97 | ```toml 98 | #thirdparty/fmt/6.2.0/cppkg.toml 99 | [fmt] 100 | version = "6.2.0" 101 | description = "A modern formatting library" 102 | module = "fmt::fmt" 103 | url="https://github.com/fmtlib/fmt/releases/download/6.2.0/fmt-6.2.0.zip" 104 | custom=true 105 | #helper=""(incomplete) 106 | ``` 107 | [ExternalProject_add](https://cmake.org/cmake/help/latest/module/ExternalProject.html) 108 | ```cmake 109 | # Cppkg Base Dependency Downloader 110 | # Almost same cmake ExternalProject_Add 111 | # Other Options: 112 | # - Linux Configures: 113 | # L_CONFIGURE {...}, L_BUILD {...}, L_INSTALL {...} 114 | # - Windows Configures: 115 | # W_CONFIGURE {...}, W_BUILD {...}, W_INSTALL {...} 116 | # - Install Path Options: 117 | # LOCAL(default) GLOBAL 118 | cmake_minimum_required(VERSION 3.6) 119 | project(fmt-6.2.0-install C CXX) 120 | 121 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_tool.cmake) 122 | set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}) 123 | download_package(fmt 6.2.0 URL https://github.com/fmtlib/fmt/releases/download/6.2.0/fmt-6.2.0.zip CMAKE_ARGS ${CMAKE_ARGS} -DFMT_DOC=OFF -DFMT_TEST=OFF -DFMT_FUZZ=OFF) 124 | ``` 125 | 126 | 127 | 128 | 129 | # Dependency Format 130 | ```toml 131 | [${name}] 132 | version = "x.x.x|git|latest(hunter only)" 133 | type = "lib(default)|bin|cmake(incomplete)" 134 | git = "..." # if git version 135 | url = "..." # if x.x.x version 136 | module = "..." # (require) 137 | link = "public(default)|private|interface" 138 | custom = "false(default)|true" # cppm build time cppkg.toml translate ${name}.cmake.in in 139 | # if you want to custom installer(${name}.cmake.in) set true 140 | repo = "cppkg(default)|hunter" 141 | flags="${cmake build flags}" 142 | helper="Find...cmake" (optional) cmake/Modules/Find${package_name}.cmake 143 | components = "..." 144 | ``` 145 | -------------------------------------------------------------------------------- /docs/src/first-steps.md: -------------------------------------------------------------------------------- 1 | ## First Steps with Cppm 2 | To start a new package with Cppm, use ```cppm init``` 3 | ~~~console 4 | $ cppm init -h 5 | Usage: 6 | cppm init [--verbose] 7 | 8 | Option: 9 | --bin [-b] {name} :initialize new c++ binary project 10 | --help [-h] :show cppm commands and options 11 | --lib [-l] {name} :initialize new c++ library project 12 | ~~~ 13 | 14 | New Binary Project 15 | ~~~console 16 | $ cppm init --bin hello_world 17 | ~~~ 18 | 19 | Generated project 20 | ~~~console 21 | $ cd hello_world 22 | $ tree . 23 | . 24 | |-- build # Build directory 25 | | |-- Debug # Debug mode target directory 26 | | `-- Release # Release mode target directory 27 | |-- cmake # cmake module path 28 | | |-- Modules # cmake Find*.cmake path 29 | | `-- cppm_tool.cmake # cppm_tool load tool 30 | |-- cppm.toml 31 | |-- include # public header 32 | |-- src # private header and sources 33 | | `-- main.cpp 34 | `-- thirdparty # cppkg config and file path 35 | `-- ${cppkg_name}/${cppkg_version}/cppkg.toml # cppkg config file 36 | ~~~ 37 | 38 | Cppm project config file 39 | ~~~toml 40 | # cppm.toml 41 | [package] 42 | name = "hello_world" 43 | version = "0.0.1" 44 | description = "" 45 | 46 | [[bin]] 47 | name = "hello_world" 48 | source = ["src/.*"] 49 | ~~~ 50 | 51 | Generated defualt cpp file 52 | ~~~cpp 53 | // src/main.cpp 54 | #include 55 | int main(int argc, char* argv[]) { 56 | std::cout<<"hello world"< origin/0.0.9 67 | -- [cppm] cppm_tools-0.0.9 download to /home-path/.cppm/src/cppm_tools/0.0.9 68 | -- The C compiler identification is Clang 9.0.0 69 | -- The CXX compiler identification is Clang 9.0.0 70 | -- Check for working C compiler: /usr/local/opt/llvm/bin/clang 71 | -- Check for working C compiler: /usr/local/opt/llvm/bin/clang -- works 72 | -- Detecting C compiler ABI info 73 | -- Detecting C compiler ABI info - done 74 | -- Detecting C compile features 75 | -- Detecting C compile features - done 76 | -- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ 77 | -- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ -- works 78 | -- Detecting CXX compiler ABI info 79 | -- Detecting CXX compiler ABI info - done 80 | -- Detecting CXX compile features 81 | -- Detecting CXX compile features - done 82 | -- [cppm] Target: hello_world [Type:debug, Cppm:0.0.9, CMake:3.16.2] 83 | -- [cppm] System: x86_64-Darwin-19.3.0 84 | -- [cppm] Compiler: Clang-9.0.0 85 | -- [cppm] Generator: Unix Makefiles 86 | -- [cppm] Build Cache: ccache 87 | -- [cppm] cppm_root: /path/to/.cppm 88 | -- [cppm] c++ version: 17 89 | -- [cppm] Compiler Option: -std=c++17 -Wall -fPIC -O0 -g 90 | -- Configuring done 91 | -- Generating done 92 | -- Build files have been written to: /path/to/hello_world/build 93 | Scanning dependencies of target hello_world 94 | [ 50%] Building CXX object CMakeFiles/hello_world.dir/src/main.cpp.o 95 | [100%] Linking CXX executable hello_world 96 | [100%] Built target hello_world 97 | ~~~ 98 | And the run it. 99 | ~~~console 100 | $ cd build/Debug 101 | $ ./hello_world 102 | hello world 103 | ~~~ 104 | Easy run command ```cppm run```, default binary name ${[package.name]} 105 | ~~~console 106 | $ cppm run 107 | hello world 108 | ~~~ 109 | Generated ```CMakeLists.txt``` 110 | ~~~cmake 111 | cmake_minimum_required(VERSION 3.12) 112 | 113 | include(cmake/cppm_tool.cmake) 114 | cppm_project() 115 | project(hello_world VERSION 0.0.1 LANGUAGES C CXX) 116 | cppm_setting() 117 | 118 | cppm_cxx_standard(17) 119 | cppm_compiler_option(DEFAULT) 120 | 121 | cppm_target_define(hello_world BINARY 122 | SOURCES 123 | src/main.cpp 124 | ) 125 | 126 | cppm_target_dependencies(hello_world) 127 | 128 | cppm_target_install(hello_world) 129 | ~~~ 130 | 131 | Changed project Directory 132 | ~~~console 133 | $ tree . 134 | . 135 | ├── CMakeLists.txt 136 | ├── build 137 | │   ├── CMakeCache.txt 138 | │   ├── CMakeFiles 139 | │   │   ├── 3.17.1 140 | │   │   │   ├── CMakeCCompiler.cmake 141 | │   │   │   ├── CMakeCXXCompiler.cmake 142 | │   │   │   ├── CMakeDetermineCompilerABI_C.bin 143 | │   │   │   ├── CMakeDetermineCompilerABI_CXX.bin 144 | │   │   │   ├── CMakeSystem.cmake 145 | │   │   │   ├── CompilerIdC 146 | │   │   │   │   ├── CMakeCCompilerId.c 147 | │   │   │   │   ├── a.out 148 | │   │   │   │   └── tmp 149 | │   │   │   └── CompilerIdCXX 150 | │   │   │   ├── CMakeCXXCompilerId.cpp 151 | │   │   │   ├── a.out 152 | │   │   │   └── tmp 153 | │   │   ├── CMakeDirectoryInformation.cmake 154 | │   │   ├── CMakeOutput.log 155 | │   │   ├── CMakeTmp 156 | │   │   ├── Makefile.cmake 157 | │   │   ├── Makefile2 158 | │   │   ├── TargetDirectories.txt 159 | │   │   ├── cmake.check_cache 160 | │   │   ├── progress.marks 161 | │   │   ├── hello_world.dir 162 | │   │   │   ├── CXX.includecache 163 | │   │   │   ├── DependInfo.cmake 164 | │   │   │   ├── build.make 165 | │   │   │   ├── cmake_clean.cmake 166 | │   │   │   ├── depend.internal 167 | │   │   │   ├── depend.make 168 | │   │   │   ├── flags.make 169 | │   │   │   ├── link.txt 170 | │   │   │   ├── progress.make 171 | │   │   │   └── src 172 | │   │   │   └── main.cpp.o 173 | │   │   └── hello_world_info.dir 174 | │   │   ├── DependInfo.cmake 175 | │   │   ├── build.make 176 | │   │   ├── cmake_clean.cmake 177 | │   │   └── progress.make 178 | │   ├── Debug 179 | │   │   └── hello_world # Binary or Library export Directory 180 | │   ├── Makefile 181 | │   ├── cmake_install.cmake 182 | │   └── compile_commands.json 183 | ├── cmake 184 | │   ├── Modules 185 | │   └── cppm_tool.cmake 186 | ├── cppm.toml 187 | ├── include 188 | ├── src 189 | │   └── main.cpp 190 | └── thirdparty 191 | ~~~ 192 | 193 | 194 | -------------------------------------------------------------------------------- /docs/src/getting_started.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | #### To get started with Cppm, Install this Dependency 3 | * **C++ Compiler** (c++17) # can use filesystem.h and optional.h 4 | * **CMake** (3.12) 5 | * ccache (*optional*) # Build cache 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/src/install.md: -------------------------------------------------------------------------------- 1 | ## Installation 2 | ### Install Cppm 3 | cppm install command install defualt prefix is **$HOME/.cppm/bin** 4 | 5 | ## Require 6 | - C++17 Compiler (AppleClang can't build) 7 | - CMake (Minumum 3.12) 8 | - git 9 | - ccache (optional) 10 | 11 | #### Linux and MacOS 12 | ```sh 13 | git clone --recurse-submodules https://github.com/injae/cppm.git 14 | cd cppm 15 | cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DUSE_CPPM_PATH=ON . 16 | cd build 17 | cmake --build . --config Release 18 | cd Release 19 | ./cppm build install 20 | # Add to cppm path 21 | export PATH=$PATH:$HOME/.cppm/bin 22 | ``` 23 | 24 | #### Windows 25 | ```sh 26 | # need visual studio , git , cmake 27 | # scoop install git cmake 28 | git clone --recurse-submodules https://github.com/injae/cppm.git 29 | cd cppm 30 | cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DUSE_CPPM_PATH=ON . 31 | cd build 32 | cmake --build . --config Release --target install --target cppm_link 33 | # Add System Path %USERPROFILE%\.cppm\bin 34 | ``` 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/src/introdution.md: -------------------------------------------------------------------------------- 1 | The Cppm Book (***BETA***) 2 | ================================== 3 | > ***Cppm*** is ***BETA*** Project Please Give Feedback 4 | 5 | Cppm is CMake based Cross Platform C++ package manager 6 | Manage and Downloads C++ dependencies, easy project build, install, 7 | upload to [cppkg](https://github.com/injae/cppkg) 8 | 9 | ## Features 10 | * Easy to use CMake 11 | * Easy Config file than CMakeList.txt 12 | * Generate Cross Platform CMake base C++ Project 13 | * Dependencies auto install in build step 14 | * can use cmake uninstall target 15 | * CMake base project can build with cppm (cppm build) (Use CMake's toolchain feature) 16 | * Manage Depdendency with ***[cppkg](https://github.com/injae/cppkg)*** and ***[Hunter Package Manage](https://github.com/cpp-pm/hunter)*** 17 | * Dependency install only use CMake 18 | 19 | -------------------------------------------------------------------------------- /docs/src/package_layout.md: -------------------------------------------------------------------------------- 1 | ## Cppm Base Project Layout 2 | ~~~console 3 | . 4 | |-- cppm.toml # cppm config file 5 | |-- CMakeLists.txt # <-- generated from cppm.toml 6 | |-- build # Build directory 7 | | |-- Debug # Debug mode target directory 8 | | `-- Release # Release mode target directory 9 | |-- cmake # cmake module path 10 | | |-- Modules # cmake Find*.cmake path 11 | | `-- cppm_tool.cmake # cppm_tool load script (require) 12 | |-- include # public header (export header) 13 | |-- src # private header and sources 14 | | `-- main.cpp 15 | |-- test # test src directory 16 | | `-- test01.cpp 17 | |-- examples # example src directory 18 | | `-- example01.cpp 19 | `-- thirdparty # cppkg config and file path 20 | `-- ${cppkg_name}/${cppkg_version}/cppkg.toml # cppkg config file 21 | ~~~ 22 | -------------------------------------------------------------------------------- /examples/boost_filesystem_hunter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | 3 | include(cmake/cppm_tool.cmake) 4 | cppm_project() 5 | include(HunterGate) 6 | HunterGate( 7 | URL "https://github.com/ruslo/hunter/archive/v0.23.149.tar.gz" 8 | SHA1 "c9f170bd697ac6117e68137a2cffdeca679db67e" 9 | ) 10 | project(boost_filesystem_hunter VERSION 0.0.1 LANGUAGES C CXX) 11 | cppm_setting() 12 | 13 | cppm_cxx_standard(17) 14 | cppm_compiler_option(DEFAULT) 15 | 16 | 17 | find_cppkg(Boost 1.58.0 COMPONENTS system filesystem HUNTER) 18 | 19 | cppm_target_define(boost_filesystem_hunter BINARY 20 | SOURCES 21 | src/main.cpp 22 | ) 23 | 24 | 25 | cppm_target_dependencies(boost_filesystem_hunter 26 | PUBLIC 27 | Boost::filesystem 28 | ) 29 | 30 | cppm_target_install(boost_filesystem_hunter) 31 | 32 | -------------------------------------------------------------------------------- /examples/boost_filesystem_hunter/cmake/cppm_tool.cmake: -------------------------------------------------------------------------------- 1 | string(REPLACE "\\" "/" HOME "$ENV{HOME}") 2 | set(CPPM_ROOT ${HOME}/.cppm) 3 | list(APPEND CMAKE_MODULE_PATH "${HOME}/.cppm/tool") 4 | 5 | macro(cppm_load) 6 | cmake_parse_arguments(_ARG "NIGHTLY" "" "" ${ARGN}) 7 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") 8 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") 9 | 10 | if(NOT EXISTS ${CPPM_ROOT}/tool) 11 | find_package(Git REQUIRED) 12 | if(NOT GIT_FOUND) 13 | message(FATAL_ERROR "git not found!") 14 | endif() 15 | message(STATUS "[cppm] Downloading cppm tool to ${CPPM_ROOT}/tool") 16 | make_directory("${CPPM_ROOT}") 17 | execute_process( 18 | COMMAND ${GIT_EXECUTABLE} clone https://github.com/injae/cppm_tools.git tool 19 | WORKING_DIRECTORY ${CPPM_ROOT} 20 | ) 21 | endif() 22 | 23 | set(CPPM_TOOL_VERSION "master") 24 | if(${ARG_NIGHTLY}) 25 | set(CPPM_TOOL_VERSION "nightly") 26 | endif() 27 | 28 | include(download/git) 29 | git_clone(tool 30 | URL https://github.com/injae/cppm_tools.git 31 | PATH ${CPPM_ROOT} 32 | BRANCH ${CPPM_TOOL_VERSION} QUIET) 33 | git_clone(cppkg 34 | URL https://github.com/injae/cppkg.git 35 | PATH ${CPPM_ROOT}/repo 36 | BRANCH ${CPPM_TOOL_VERSION} QUIET) 37 | endmacro() 38 | 39 | macro(cppm_project) 40 | cmake_parse_arguments(_ARG "" "" "" ${ARGN}) 41 | cppm_load() 42 | include(cppm/cppm_project/1.0.7) 43 | _cppm_project(${_ARG_UNPARSED_ARGUMENTS}) 44 | endmacro() 45 | 46 | macro(cppm_cxx_standard) 47 | cmake_parse_arguments(_ARG "" "" "" ${ARGN}) 48 | include(cppm/cxx_standard/1.0.7) 49 | _cppm_cxx_standard(${_ARG_UNPARSED_ARGUMENTS}) 50 | endmacro() 51 | 52 | 53 | macro(cppm_compiler_option) 54 | include(cppm/compiler_option/1.0.7) 55 | _cppm_compiler_option(${ARGN}) 56 | endmacro() 57 | 58 | macro(cppm_setting) 59 | cmake_parse_arguments(_ARG "" "" "" ${ARGN}) 60 | include(cppm/setting/1.0.7) 61 | _cppm_setting(${_ARG_UNPARSED_ARGUMENTS}) 62 | endmacro() 63 | 64 | macro(find_cppkg) 65 | cmake_parse_arguments(ARG "" "" "" ${ARGN}) 66 | include(cppkg/find/1.0.7) 67 | _find_cppkg(${ARG_UNPARSED_ARGUMENTS}) 68 | endmacro() 69 | 70 | macro(cppm_target_define) 71 | cmake_parse_arguments(ARG "" "" "" ${ARGN}) 72 | include(cppm/target/define/1.0.5) 73 | _cppm_target_define(${ARG_UNPARSED_ARGUMENTS}) 74 | endmacro() 75 | 76 | macro(cppm_target_dependencies) 77 | cmake_parse_arguments(ARG "" "" "" ${ARGN}) 78 | include(cppm/target/dependencies/1.0.5) 79 | _cppm_target_dependencies(${ARG_UNPARSED_ARGUMENTS}) 80 | endmacro() 81 | 82 | macro(cppm_target_install) 83 | cmake_parse_arguments(ARG "" "" "" ${ARGN}) 84 | include(cppm/target/install/1.0.5) 85 | _cppm_target_install(${ARG_UNPARSED_ARGUMENTS}) 86 | endmacro() 87 | 88 | macro(download_package) 89 | cmake_parse_arguments(ARG "" "" "" ${ARGN}) 90 | include(cppkg/download/1.0.7) 91 | _download_package(${ARG_UNPARSED_ARGUMENTS}) 92 | endmacro() 93 | -------------------------------------------------------------------------------- /examples/boost_filesystem_hunter/cppm.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "boost_filesystem_hunter" 3 | version = "0.0.1" 4 | description = "" 5 | 6 | [[bin]] 7 | name = "boost_filesystem_hunter" 8 | source = ["src/.*"] 9 | 10 | [dependencies] 11 | Boost = {module = "Boost::filesystem", version = "1.58.0", components="system filesystem", hunter=true} -------------------------------------------------------------------------------- /examples/boost_filesystem_hunter/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char* argv[]) { 4 | 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/example.cpp: -------------------------------------------------------------------------------- 1 | #include "cppm/core/config.hpp" 2 | 3 | int main(int argc, char* argv[]) { 4 | std::cout << "example test" << std::endl; 5 | cppm::core::Config conig; 6 | 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /examples/fmt_cppkg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | if(NOT IS_CPPM_LOADED) 4 | include(cmake/cppm_tool.cmake) 5 | endif() 6 | cppm_project() 7 | project(fmt_cppkg VERSION 0.0.1 LANGUAGES C CXX) 8 | cppm_setting() 9 | 10 | cppm_cxx_standard(17) 11 | cppm_compiler_option(DEFAULT) 12 | 13 | 14 | find_cppkg(fmt 5.3.0 MODULE fmt::fmt) 15 | 16 | cppm_target_define(fmt_cppkg BINARY 17 | SOURCES 18 | src/main.cpp 19 | ) 20 | 21 | 22 | cppm_target_dependencies(fmt_cppkg 23 | PUBLIC 24 | fmt 25 | ) 26 | 27 | cppm_target_install(fmt_cppkg) 28 | 29 | -------------------------------------------------------------------------------- /examples/fmt_cppkg/cmake/cppm_tool.cmake: -------------------------------------------------------------------------------- 1 | string(REPLACE "\\" "/" HOME "$ENV{HOME}") 2 | set(CPPM_VERSION "nightly") 3 | 4 | set(CPPM_ROOT ${HOME}/.cppm) 5 | set(CPPM_SOURCE ${CPPM_ROOT}/src) 6 | set(CPPM_CACHE ${CPPM_ROOT}/cache) 7 | set(CPPM_CORE ${CPPM_SOURCE}/cppm_tools/${CPPM_VERSION}) 8 | 9 | if(NOT DEFINED IS_CPPM_LOADED) 10 | set(_install_script "${CPPM_CACHE}/cppm-tools/${CPPM_VERSION}/install-script") 11 | file(WRITE ${_install_script}/CMakeLists.txt 12 | "cmake_minimum_required(VERSION 3.6) 13 | project(CPPM_TOOLS_DOWNLOAD NONE) 14 | include(ExternalProject) 15 | ExternalProject_Add(cppm-tools 16 | GIT_REPOSITORY https://github.com/injae/cppm_tools.git 17 | GIT_TAG ${CPPM_VERSION} 18 | SOURCE_DIR ${CPPM_CORE} 19 | BINARY_DIR ${CPPM_CACHE}/cppm-tools/${CPPM_VERSION}/build 20 | CONFIGURE_COMMAND \"\" 21 | BUILD_COMMAND \"\" 22 | INSTALL_COMMAND \"\" 23 | )" 24 | ) 25 | execute_process(COMMAND cmake . WORKING_DIRECTORY ${_install_script} OUTPUT_QUIET) 26 | execute_process(COMMAND cmake --build . WORKING_DIRECTORY ${_install_script} OUTPUT_QUIET) 27 | set(IS_CPPM_LOADED TRUE) 28 | endif() 29 | include(${CPPM_CORE}/core_load.cmake) 30 | 31 | 32 | -------------------------------------------------------------------------------- /examples/fmt_cppkg/cppm.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fmt_cppkg" 3 | version = "0.0.1" 4 | description = "" 5 | 6 | [[bin]] 7 | name = "fmt_cppkg" 8 | source = ["src/.*"] 9 | 10 | [dependencies] 11 | fmt = "5.3.0" -------------------------------------------------------------------------------- /examples/fmt_cppkg/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char* argv[]) { 4 | 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/fmt_cppkg/thirdparty/fmt/5.3.0/cppkg.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fmt" 3 | # if you use git repo, package version is lastest 4 | version = "5.3.0" 5 | description = "c++ format library" 6 | global=false 7 | # library name in cmake, cppm.toml use this value 8 | # [dependencies] 9 | #${library_name} = {module =${value}} 10 | cmake = {name = "fmt::fmt", findlib=""} 11 | # write download value git or url 12 | #download = {git=""} 13 | download = {url="https://github.com/fmtlib/fmt/archive/5.3.0.tar.gz"} 14 | [dependencies] 15 | 16 | [fmt] 17 | version = "5.3.0" 18 | description = "c++ format library" 19 | module = "fmt::fmt" 20 | url="https://github.com/fmtlib/fmt/archive/5.3.0.tar.gz" -------------------------------------------------------------------------------- /examples/fmt_cppkg/thirdparty/fmt/5.3.0/dep.cmake: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/injae/cppm/68c337ee9d7cb73976c83706e5f199406a85e2a9/examples/fmt_cppkg/thirdparty/fmt/5.3.0/dep.cmake -------------------------------------------------------------------------------- /examples/fmt_cppkg/thirdparty/fmt/5.3.0/fmt.cmake.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | project(fmt-5.3.0-install C CXX) 3 | 4 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_tool.cmake) 5 | download_package( 6 | fmt 7 | 5.3.0 8 | URL https://github.com/fmtlib/fmt/archive/5.3.0.tar.gz 9 | LOCAL 10 | CMAKE_ARGS 11 | -DFMT_DOC=OFF 12 | -DFMT_TEST=OFF 13 | -DFMT_FUZZ=OFF 14 | -DFMT_USE_CPP14=OFF 15 | ${CMAKE_ARGS} 16 | ) 17 | 18 | # Other Options: 19 | # - Linux Configures: 20 | # L_CONFIGURE {...}, L_BUILD {...}, L_INSTALL {...} 21 | # - Windows Configures: 22 | # W_CONFIGURE {...}, W_BUILD {...}, W_INSTALL {...} 23 | # - Install Path Options: 24 | # LOCAL(default) GLOBAL 25 | -------------------------------------------------------------------------------- /examples/hello_world/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .ccls-cache 3 | compile_commands.json 4 | -------------------------------------------------------------------------------- /examples/hello_world/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | include(cmake/cppm_tool.cmake) 4 | cppm_project() 5 | project(hello_world VERSION 0.0.1 LANGUAGES C CXX) 6 | cppm_setting() 7 | 8 | cppm_cxx_standard(17) 9 | cppm_compiler_option(DEFAULT) 10 | 11 | 12 | 13 | cppm_target_define(hello_world BINARY 14 | SOURCES 15 | src/main.cpp 16 | ) 17 | 18 | 19 | cppm_target_dependencies(hello_world 20 | ) 21 | 22 | cppm_target_install(hello_world) 23 | 24 | -------------------------------------------------------------------------------- /examples/hello_world/cmake/cppm_tool.cmake: -------------------------------------------------------------------------------- 1 | string(REPLACE "\\" "/" HOME "$ENV{HOME}") 2 | set(CPPM_VERSION "0.0.9") 3 | 4 | set(CPPM_ROOT ${HOME}/.cppm) 5 | set(CPPM_SOURCE ${CPPM_ROOT}/src) 6 | set(CPPM_CACHE ${CPPM_ROOT}/cache) 7 | set(CPPM_CORE ${CPPM_SOURCE}/cppm_tools/${CPPM_VERSION}) 8 | 9 | if(NOT DEFINED IS_CPPM_LOADED) 10 | 11 | set(_cache_path "${CPPM_CACHE}/${name}/${VERSION}") 12 | set(_install_script "${CPPM_CACHE}/${name}/${VERSION}/install-script") 13 | file(WRITE ${_install_script}/CMakeLists.txt 14 | "cmake_minimum_required(VERSION 3.6) 15 | project(cpp-tool-${CPPM_VERSION}-install NONE) 16 | include(ExternalProject) 17 | ExternalProject_Add(cppm-tools-${CPPM_VERSION} 18 | GIT_REPOSITORY https://github.com/injae/cppm_tools.git 19 | GIT_TAG ${CPPM_VERSION} 20 | SOURCE_DIR ${CPPM_CORE} 21 | BINARY_DIR ${_cache_path}/build 22 | CONFIGURE_COMMAND \"\" 23 | BUILD_COMMAND \"\" 24 | INSTALL_COMMAND \"\" 25 | #QUIET 26 | )" 27 | ) 28 | execute_process(COMMAND cmake . WORKING_DIRECTORY ${_install_script} OUTPUT_QUIET) 29 | execute_process(COMMAND cmake --build . WORKING_DIRECTORY ${_install_script} OUTPUT_QUIET) 30 | endif() 31 | set(IS_CPPM_LOADED TRUE) 32 | include(${CPPM_CORE}/core_load.cmake) 33 | 34 | 35 | -------------------------------------------------------------------------------- /examples/hello_world/cppm.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_world" 3 | version = "0.0.1" 4 | description = "" 5 | 6 | [[bin]] 7 | name = "hello_world" 8 | source = ["src/.*"] 9 | -------------------------------------------------------------------------------- /examples/hello_world/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char* argv[]) { 3 | std::cout<<"hello world"< 2 | 3 | int main(int argc, char* argv[]) { 4 | if (argc != 2) { 5 | printf("usage: DisplayImage.out \n"); 6 | return -1; 7 | } 8 | 9 | cv::Mat image; 10 | image = cv::imread(argv[1], 1); 11 | 12 | if (!image.data) { 13 | printf("No image data \n"); 14 | return EXIT_FAILURE; 15 | } 16 | cv::namedWindow("Display Image", cv::WINDOW_AUTOSIZE); 17 | cv::imshow("Display Image", image); 18 | 19 | cv::waitKey(0); 20 | 21 | return EXIT_SUCCESS; 22 | } 23 | -------------------------------------------------------------------------------- /include/cppm/core/cmake.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_CMAKE_HPP__ 4 | #define __CPPM_CORE_CMAKE_HPP__ 5 | 6 | #include 7 | #include 8 | 9 | namespace cppm::core { 10 | struct CMake { 11 | DERIVE_SERDE(CMake, 12 | (&Self::version, "version", default_{"3.12"}) 13 | (&Self::toolchain, "toolchain") 14 | (&Self::include, "include", make_optional) 15 | .no_remain() 16 | ) 17 | 18 | std::string version = "3.12"; 19 | std::optional toolchain; 20 | std::vector include; 21 | }; 22 | } 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/cppm/core/compiler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_COMPILER_HPP__ 4 | #define __CPPM_CORE_COMPILER_HPP__ 5 | 6 | #include 7 | 8 | 9 | namespace cppm::core { 10 | struct Compiler { 11 | DERIVE_SERDE(Compiler, 12 | (&Self::version, "version", value_or_struct) 13 | (&Self::option, "option") 14 | ) 15 | std::string version; 16 | std::string option; 17 | }; 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/cppm/core/config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_CONFIG_HPP__ 4 | #define __CPPM_CORE_CONFIG_HPP__ 5 | 6 | #include 7 | #include 8 | 9 | #include "cppm/core/package.hpp" 10 | #include "cppm/core/cmake.hpp" 11 | #include "cppm/core/workspace.hpp" 12 | #include "cppm/core/feature.hpp" 13 | #include "cppm/core/dependency.hpp" 14 | #include "cppm/core/cppkg.hpp" 15 | #include "cppm/core/profile.hpp" 16 | #include "cppm/core/target.hpp" 17 | #include "cppm/core/hunter.hpp" 18 | 19 | #include "cppm/util/filesystem.h" 20 | 21 | namespace cppm::core { 22 | struct Path 23 | { 24 | inline static Path make(const std::string& root_path) { 25 | Path path; 26 | path.root = root_path; 27 | path.build = path.root/"build"; 28 | path.cmake = path.root/"cmake"; 29 | path.source = path.root/"src"; 30 | path.include = path.root/"include"; 31 | path.thirdparty = path.root/"thirdparty"; 32 | return path; 33 | } 34 | public: 35 | fs::path root; 36 | fs::path build; 37 | fs::path cmake; 38 | fs::path source; 39 | fs::path include; 40 | fs::path thirdparty; 41 | }; 42 | 43 | struct Config { 44 | DERIVE_SERDE(Config, 45 | (&Self::package, "package") 46 | (&Self::cmake, "cmake", default_{CMake{}}) 47 | (&Self::hunter, "hunter") 48 | (&Self::workspace, "workspace") 49 | (&Self::features, "features", make_optional) 50 | (&Self::dependencies, "dependencies", make_optional) 51 | (&Self::dev_dependencies, "dev-dependencies", make_optional) 52 | (&Self::lib, "lib") 53 | (&Self::bins, "bin", make_optional) 54 | (&Self::examples, "example", make_optional) 55 | (&Self::benchmarks, "benchmark", make_optional) 56 | (&Self::tests, "tests", make_optional) 57 | (&Self::profile, "profile", make_optional) 58 | (&Self::target, "target", make_optional) 59 | ) 60 | 61 | Package package; 62 | CMake cmake; 63 | std::optional hunter; 64 | std::optional workspace; 65 | std::unordered_map> features; 66 | std::unordered_map dependencies; 67 | std::unordered_map dev_dependencies; 68 | std::optional lib; 69 | std::vector bins; 70 | std::vector examples; 71 | std::vector tests; 72 | std::vector benchmarks; 73 | std::map profile; 74 | std::map target; 75 | Path path; 76 | 77 | Config& post_processing(const std::string& config_path); 78 | static Config load(fs::path config_path); 79 | }; 80 | 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /include/cppm/core/cppkg.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_CPPKG_HPP__ 4 | #define __CPPM_CORE_CPPKG_HPP__ 5 | 6 | #include 7 | #include 8 | 9 | namespace cppm::core { 10 | enum class cppkg_type { 11 | bin, 12 | lib, 13 | test, 14 | example, 15 | cmake, 16 | }; 17 | enum class cppkg_type_detail { 18 | STATIC, 19 | BINARY, 20 | SHARED, 21 | HEADER_ONLY, 22 | }; 23 | 24 | struct Cppkg { 25 | DERIVE_SERDE(Cppkg, 26 | (&Self::name, "name") 27 | (&Self::namespace_, "namespace") 28 | (&Self::install, "install", default_{true}) 29 | (&Self::source, "source", make_optional) 30 | (&Self::exclude, "flag", default_{false}) 31 | ) 32 | std::string name; 33 | cppkg_type type; 34 | cppkg_type_detail cppkg_type_d; 35 | std::optional namespace_; 36 | bool install; 37 | std::vector source; 38 | std::string exclude_var; 39 | bool exclude; 40 | 41 | virtual ~Cppkg() = default; 42 | }; 43 | 44 | struct CppkgLib : Cppkg { 45 | template 46 | constexpr static void serde(Context& context, CppkgLib& value) { 47 | using namespace serde::attribute; 48 | using Self = CppkgLib; 49 | Cppkg& upcast = static_cast(value); 50 | Cppkg::serde(context, upcast); 51 | serde::serde_struct(context, value) 52 | (&Self::type, "cppkg_type", default_{cppkg_type::lib}) 53 | (&Self::cppkg_type_d, "type", default_{cppkg_type_detail::STATIC}, under_to_dash, to_lower) 54 | ; 55 | } 56 | }; 57 | struct CppkgBin : Cppkg { 58 | template 59 | constexpr static void serde(Context& context, CppkgBin& value) { 60 | using namespace serde::attribute; 61 | using Self = CppkgBin; 62 | Cppkg& upcast = static_cast(value); 63 | Cppkg::serde(context, upcast); 64 | serde::serde_struct(context, value) 65 | (&Self::type, "cppkg_type", default_{cppkg_type::bin}) 66 | (&Self::cppkg_type_d, "type", default_{cppkg_type_detail::BINARY}, under_to_dash, to_lower) 67 | ; 68 | } 69 | }; 70 | struct CppkgExample : Cppkg { 71 | template 72 | constexpr static void serde(Context& context, CppkgExample& value) { 73 | using namespace serde::attribute; 74 | using Self = CppkgExample; 75 | Cppkg& upcast = static_cast(value); 76 | Cppkg::serde(context, upcast); 77 | serde::serde_struct(context, value) 78 | (&Self::type, "cppkg_type", default_{cppkg_type::example}) 79 | (&Self::cppkg_type_d, "type", default_{cppkg_type_detail::BINARY}, under_to_dash, to_lower) 80 | ; 81 | } 82 | }; 83 | 84 | struct CppkgTest : Cppkg { 85 | template 86 | constexpr static void serde(Context& context, CppkgTest& value) { 87 | using namespace serde::attribute; 88 | using Self = CppkgTest; 89 | Cppkg& upcast = static_cast(value); 90 | Cppkg::serde(context, upcast); 91 | serde::serde_struct(context, value) 92 | (&Self::type, "cppkg_type", default_{cppkg_type::test}) 93 | (&Self::cppkg_type_d, "type", default_{cppkg_type_detail::BINARY}, under_to_dash, to_lower) 94 | ; 95 | } 96 | }; 97 | } 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /include/cppm/core/cppm_tool.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_CPPM_TOOL_HPP__ 4 | #define __CPPM_CORE_CPPM_TOOL_HPP__ 5 | 6 | #include 7 | #include "cppm/core/config.hpp" 8 | #include "cppm/util/system.hpp" 9 | 10 | using namespace fmt::literals; 11 | namespace cppm::core { 12 | inline std::string cppm_root() { return "{}.cppm/"_format(cppm::util::system::home_path()); } 13 | std::string cppm_translate(Config& config); 14 | std::string cppm_header(Config& config); 15 | std::string include_cmake_files(Config& config); 16 | std::string find_cppkg(Config& config); 17 | std::string hunter_load(Config& config); 18 | std::string cppm_target_define(Config& config); 19 | std::string cppm_target_dependencies(Config& config); 20 | std::string cppm_target_install(Config& config); 21 | std::string cppm_compiler_option(Config& config); 22 | std::string cppm_download_package(Dependency& dep); 23 | void cppm_features_parse(Config& config); 24 | Dependency cppm_auto_generate_cppkg(fs::path& path); 25 | void install_cppm_download_package(fs::path path, Dependency& dep); 26 | std::string hunter_root(); 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/cppm/core/dependency.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_DEPENDENCY_HPP__ 4 | #define __CPPM_CORE_DEPENDENCY_HPP__ 5 | 6 | #include 7 | #include 8 | 9 | #include "cppm/core/feature.hpp" 10 | #include "cppm/core/cppkg.hpp" 11 | #include 12 | 13 | namespace cppm::core { 14 | 15 | enum class link_type { PUBLIC, PRIVATE, INTERFACE }; 16 | enum class repo_type { cppkg, hunter, system, vcpkg, workspace }; 17 | 18 | struct Dependency { 19 | DERIVE_SERDE(Dependency, 20 | (&Self::version, "version", value_or_struct) 21 | (&Self::description, "description", default_{""}) 22 | (&Self::type, "type", default_{cppkg_type::lib}) 23 | (&Self::repo, "repo", default_{repo_type::cppkg}) 24 | (&Self::link, "link", default_{link_type::PRIVATE}, to_lower) 25 | (&Self::module, "module") 26 | (&Self::features, "feature-map", make_optional) 27 | (&Self::default_feature, "features", make_optional) 28 | (&Self::default_features_flag, "default_features", default_{true}) 29 | (&Self::custom, "custom", default_{false}) 30 | (&Self::no_cmake, "no_module",default_{false}) 31 | (&Self::optional, "optional", default_{false}) 32 | (&Self::components, "components") 33 | (&Self::path, "path") 34 | (&Self::git, "git") 35 | (&Self::branch, "branch") 36 | (&Self::url, "url") 37 | (&Self::sha256, "sha256") 38 | (&Self::helper, "helper") 39 | (&Self::flags, "flags") 40 | ) 41 | 42 | std::string name; 43 | cppkg_type type; 44 | std::string version; 45 | link_type link; 46 | repo_type repo; 47 | std::string description; 48 | std::map> features; 49 | std::vector default_feature; 50 | std::optional components; 51 | std::optional path; 52 | 53 | std::optional git; 54 | std::optional branch; 55 | 56 | std::optional url; 57 | std::optional sha256; 58 | 59 | std::optional helper; 60 | std::optional flags; 61 | 62 | bool custom; 63 | bool no_cmake; 64 | bool optional; 65 | bool default_features_flag; 66 | std::optional module; 67 | 68 | }; 69 | } 70 | 71 | //namespace serde{ 72 | // using cppm::core::link_type; 73 | // template 74 | // struct serde_serializer{ 75 | // inline static auto from(serde_ctx& ctx, link_type& data, std::string_view key) { 76 | // std::string buffer = serialize_at(ctx.adaptor, key); 77 | // std::transform(buffer.begin(), buffer.end(), buffer.begin(), ::toupper); 78 | // data = type::enum_t::from_str(buffer); 79 | // } 80 | // inline static auto into(serde_ctx& ctx, const link_type& data, std::string_view key) { 81 | // std::string buffer = std::string{type::enum_t::to_str(data)}; 82 | // std::transform(buffer.begin(), buffer.end(), buffer.begin(), ::tolower); 83 | // deserialize_by_from(ctx.adaptor, buffer, key); 84 | // } 85 | // }; 86 | //} 87 | 88 | 89 | #endif 90 | 91 | -------------------------------------------------------------------------------- /include/cppm/core/feature.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_FEATURES_HPP__ 4 | #define __CPPM_CORE_FEATURES_HPP__ 5 | 6 | #include 7 | #include 8 | 9 | namespace cppm::core { 10 | enum class FeatureType { 11 | CMAKE_FLAG, 12 | REMOTE, 13 | }; 14 | 15 | struct Feature { 16 | template 17 | constexpr static void serde(Context& context, Feature& value) { 18 | using namespace serde::attribute; 19 | using Self = Feature; 20 | serde::serde_struct(context, value) 21 | (&Self::key, "key", value_or_struct) 22 | (&Self::value, "value", skip) 23 | (&Self::type, "type", skip); 24 | if constexpr(Context::is_serialize) { 25 | if(value.key[0] == '$') { 26 | value.type = FeatureType::CMAKE_FLAG; 27 | value.value = "OFF"; 28 | } 29 | } 30 | } 31 | Feature() = default; 32 | Feature(const std::string& key_) : key(key_){} 33 | 34 | std::string value; 35 | std::string key; 36 | FeatureType type; 37 | }; 38 | } 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/cppm/core/hunter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_HUNTER_HPP__ 4 | #define __CPPM_CORE_HUNTER_HPP__ 5 | 6 | #include 7 | 8 | 9 | namespace cppm::core { 10 | struct Hunter { 11 | DERIVE_SERDE(Hunter, 12 | (&Self::url, "url", default_{"https://github.com/cpp-pm/hunter/archive/v0.23.269.tar.gz"}) 13 | (&Self::sha1, "sha1", default_{"64024b7b95b4c86d50ae05b926814448c93a70a0"}) 14 | (&Self::use, "use", default_{false}) 15 | .no_remain() 16 | ) 17 | std::string url; 18 | std::string sha1; 19 | bool use; 20 | }; 21 | } 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /include/cppm/core/package.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_PACKAGE_HPP__ 4 | #define __CPPM_CORE_PACKAGE_HPP__ 5 | 6 | #include 7 | #include 8 | 9 | namespace cppm::core { 10 | enum class cxx_standard { 11 | cpp_98 = 98, 12 | cpp_11 = 11, 13 | cpp_14 = 14, 14 | cpp_17 = 17, 15 | cpp_20 = 20, 16 | cpp_23 = 23 17 | }; 18 | 19 | struct Package { 20 | DERIVE_SERDE(Package, 21 | (&Self::name, "name") 22 | (&Self::version, "version", default_{"0.0.1"}) 23 | (&Self::tool_version, "tool-version", default_{"0.0.13"}) 24 | (&Self::description, "description", default_{""}) 25 | (&Self::standard, "standard", default_{"17"}) 26 | (&Self::with_vcpkg, "vcpkg", default_{false}) 27 | (&Self::unity_build, "unity", default_{false}) 28 | (&Self::git_repo, "git") 29 | .no_remain()) 30 | std::string name; 31 | std::string version; 32 | std::string tool_version; 33 | std::string description; 34 | std::string standard; 35 | std::optional git_repo; 36 | bool with_vcpkg; 37 | bool unity_build; 38 | }; 39 | } 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/cppm/core/profile.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_PROFILE_HPP__ 4 | #define __CPPM_CORE_PROFILE_HPP__ 5 | 6 | #include 7 | #include "cppm/core/compiler.hpp" 8 | 9 | namespace cppm::core { 10 | struct Profile { 11 | DERIVE_SERDE(Profile, 12 | (&Self::package, "package", make_optional) 13 | (&Self::compiler, "compiler", make_optional) 14 | ) 15 | std::map package; 16 | std::map compiler; 17 | }; 18 | }; 19 | 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/cppm/core/target.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_TARGET_HPP__ 4 | #define __CPPM_CORE_TARGET_HPP__ 5 | 6 | #include 7 | #include "cppm/core/dependency.hpp" 8 | 9 | namespace cppm::core { 10 | struct Target { 11 | DERIVE_SERDE(Target, 12 | (&Self::dependencies, "dependencies", make_optional) 13 | (&Self::dev_dependencies, "dev-dependencies", make_optional) 14 | .no_remain() 15 | ) 16 | 17 | std::unordered_map dependencies; 18 | std::unordered_map dev_dependencies; 19 | }; 20 | } 21 | 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/cppm/core/workspace.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_CORE_WORKSPACE_HPP__ 4 | #define __CPPM_CORE_WORKSPACE_HPP__ 5 | 6 | 7 | #include 8 | #include 9 | 10 | namespace cppm::core { 11 | struct Workspace { 12 | DERIVE_SERDE(Workspace, (&Self::member, "member", make_optional).no_remain()) 13 | std::vector member; 14 | }; 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/cppm/cppkg/cppkg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPKG_CPPKG_H__ 4 | #define __CPPKG_CPPKG_H__ 5 | 6 | #include 7 | #include "cppm/core/config.hpp" 8 | #include "cppm/cppkg/repo.h" 9 | 10 | namespace cppkg { 11 | using dep_in_repo = std::pair; 12 | cppm::core::Dependency parse(const std::string& name, std::string path=""); 13 | // std::string translate(cppm::core::Dependency& dep); 14 | void init(const std::string& name); 15 | void init(cppm::core::Dependency& dep); 16 | Repos list(); 17 | void build(const std::string& name); 18 | void regist(const std::string& name); 19 | dep_in_repo search(const std::string& name, const std::string& version); 20 | void install(cppm::core::Config& config, const dep_in_repo& depr); 21 | cppm::core::Dependency cppkg_auto_gen(std::string& path); 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/cppm/cppkg/repo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPKG_REPO_H__ 4 | #define __CPPKG_REPO_H__ 5 | 6 | #include 7 | #include "cppm/util/version.h" 8 | #include 9 | 10 | namespace cppkg { 11 | struct Pkg 12 | { 13 | public: 14 | std::map versions; 15 | }; 16 | struct Repo 17 | { 18 | public: 19 | std::map pkgs; 20 | }; 21 | using Repos = std::map; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/cppm/util/algorithm.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_UTIL_ALGORITHM_HPP__ 4 | #define __CPPM_UTIL_ALGORITHM_HPP__ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | using namespace ranges; 14 | 15 | namespace cppm::util 16 | { 17 | template 18 | void insert(Collection& src, Collection& des) { 19 | src.insert(src.end(), des.begin(), des.end()); 20 | } 21 | 22 | template 23 | void for_each(Collection& col, Func func) { 24 | std::for_each(col.begin(), col.end(), func); 25 | } 26 | 27 | template 28 | std::string accumulate(Collection stl, std::string token="") { 29 | return ranges::accumulate(stl, std::string{}, 30 | [&token](auto& str, const auto& piece) { return str += (token + piece);}); 31 | } 32 | 33 | namespace str 34 | { 35 | std::string erase(const std::string& target_str, const std::string& erase_str); 36 | } 37 | 38 | // ------------------------------------------------------------------- 39 | // --- Reversed iterable 40 | template 41 | struct reversion_wrapper { T& iterable; }; 42 | 43 | template 44 | auto begin (reversion_wrapper w) { return rbegin(w.iterable); } 45 | 46 | template 47 | auto end (reversion_wrapper w) { return rend(w.iterable); } 48 | 49 | template 50 | reversion_wrapper reverse (T&& iterable) { return { iterable }; } 51 | } 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/cppm/util/filesystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_UTIL_FILESYSTEM_H__ 4 | #define __CPPM_UTIL_FILESYSTEM_H__ 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | namespace fs = std::filesystem; 14 | 15 | template<> 16 | struct fmt::formatter { 17 | constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } 18 | 19 | template 20 | auto format(const fs::path& p, FormatContext& ctx) { 21 | return format_to(ctx.out(), "{}", p.string()); 22 | } 23 | }; 24 | 25 | namespace cppm::util 26 | { 27 | int working_directory(std::string path); 28 | auto file_list(const fs::path& path) -> std::optional>; 29 | auto recursive_file_list(const fs::path& path)-> std::optional>; 30 | auto find_file(const fs::path& path, const std::string& file_name) -> std::optional; 31 | auto reverse_find_file(const fs::path& path, const std::string& file_name) -> std::optional; 32 | void recursive_copy(const fs::path& src, const fs::path&dst); 33 | auto find_files(const std::string& path, std::regex filter, bool is_full_path) -> std::vector; 34 | void over_write_copy_file(const std::string& src, const std::string& des); 35 | void create(const std::string& path); 36 | void write_file(const std::string& path, const std::string& data); 37 | template void write(const std::string& path, T content) { 38 | std::fstream file(path, std::ios::out); 39 | file << content; 40 | file.close(); 41 | } 42 | std::string current_dir(); 43 | std::string read_file_all(const std::string& name); 44 | std::optional find_pattern(const fs::path& path, std::regex filter); 45 | std::string file_hash(const std::string& name); 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /include/cppm/util/hash.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_UTIL_HASH_HPP__ 4 | #define __CPPM_UTIL_HASH_HPP__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace cppm::util 11 | { 12 | constexpr uint64_t mix(char m, uint64_t s) { 13 | return ((s<<7) + ~(s>>3)) + ~m; 14 | } 15 | 16 | constexpr uint64_t hash(const char* m) { 17 | return (*m) ? mix(*m,hash(m+1)) : 0; 18 | } 19 | 20 | inline uint64_t hash(const std::string& str) { 21 | return hash(str.c_str()); 22 | } 23 | 24 | inline constexpr uint64_t operator "" _h(const char* str, std::size_t size) { 25 | return hash(str); 26 | } 27 | 28 | inline constexpr uint64_t operator "" _h(const char* str) { 29 | return hash(str); 30 | } 31 | 32 | } 33 | 34 | namespace utilpp 35 | { 36 | namespace detail { 37 | inline constexpr uint64_t mix(char m, uint64_t s) { return ((s<<7) + ~(s>>3)) + ~m; } 38 | inline constexpr uint64_t hash(const char* m) { return (*m) ? mix(*m,hash(m+1)) : 0; } 39 | } 40 | constexpr uint64_t hash(const std::string_view& str) { return detail::hash(str.data()); } 41 | } 42 | 43 | namespace utilpp::literals { 44 | inline constexpr uint64_t operator ""_h(const char* str, std::size_t) { return hash(str); } 45 | inline constexpr uint64_t operator ""_h(const char* str) { return hash(str); } 46 | } 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /include/cppm/util/optional.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_UTIL_OPTIONAL_HPP 4 | #define __CPPM_UTIL_OPTIONAL_HPP 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | template 17 | struct fmt::formatter> { 18 | constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } 19 | 20 | template 21 | auto format(const std::optional& p, FormatContext& ctx) { 22 | return format_to(ctx.out(), "{}", p.value()); 23 | } 24 | }; 25 | 26 | 27 | namespace cppm::util 28 | { 29 | inline void panic(bool opt, const std::string& message) { if(!opt) { fmt::print(stderr, "{}", message); exit(1); } } 30 | 31 | template 32 | T panic(std::optional opt, const std::string& message) { 33 | if(!opt) { fmt::print(stderr, "{}", message); exit(1); } 34 | return *opt; 35 | } 36 | 37 | template 38 | std::shared_ptr panic(std::shared_ptr opt, const std::string& message) { 39 | if(!opt) { fmt::print(stderr, "{}", message); exit(1); } 40 | return opt; 41 | } 42 | } 43 | 44 | // 45 | //namespace cppm::toml { 46 | // inline std::shared_ptr get_table(std::shared_ptr table, 47 | // const std::string& name) { 48 | // auto tb = table->get_table(name); 49 | // if(!tb) tb = cpptoml::make_table(); 50 | // return tb; 51 | // } 52 | // 53 | // inline std::shared_ptr get_table_array(std::shared_ptr table, 54 | // const std::string& name, 55 | // std::optional)>> func = std::nullopt) { 56 | // auto tb = table->get_table_array(name); 57 | // if(tb && func) std::for_each(tb->begin(), tb->end(), *func); 58 | // return tb; 59 | // 60 | // } 61 | // inline int get(std::shared_ptr table, const std::string& name, int def_v) { 62 | // return table->get_as(name).value_or(def_v); 63 | // } 64 | // 65 | // inline std::string get(std::shared_ptr table, const std::string& name, std::string_view def_v) { 66 | // return table->get_as(name).value_or(std::string{def_v}); 67 | // } 68 | // 69 | // inline bool get_bool(std::shared_ptr table, const std::string& name, bool def_v) { 70 | // return table->get_as(name).value_or(def_v); 71 | // } 72 | // 73 | // template 74 | // std::optional get(std::shared_ptr table, std::string_view name) { 75 | // return table->get_as(std::string{name}); 76 | // } 77 | // 78 | // template 79 | // std::optional get(std::shared_ptr table, const std::string& name) { 80 | // return table->get_as(std::string{name}); 81 | // } 82 | // 83 | // template 84 | // auto panic(std::shared_ptr table, const std::string& name) { 85 | // using namespace fmt::literals; 86 | // return util::panic(get(table, name), "need {} config"_format(name)); 87 | // } 88 | // 89 | // template 90 | // auto get_array(std::shared_ptr table, const std::string& name, Iter& dest) { 91 | // auto arr = table->get_array_of(name); 92 | // if(arr) { std::copy(arr->begin(), arr->end(), std::back_inserter(dest)); } 93 | // return arr; 94 | // } 95 | // 96 | //} 97 | #endif 98 | -------------------------------------------------------------------------------- /include/cppm/util/string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_UTIL_STRING_HPP__ 4 | #define __CPPM_UTIL_STRING_HPP__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace cppm::util::str { 11 | inline std::string quot(const std::string& str) { return "\""+str+"\""; } 12 | inline std::string operator"" _quot(const char* str, std::size_t len) { return quot({str, len}); } 13 | inline std::string str_cut(const std::string& str, size_t size) { 14 | return str.size() > size ? str.substr(0, size-1) + "$" : str; 15 | } 16 | inline bool has_str(const std::string& target, const std::string& str) { 17 | if(target == "") { return false; } 18 | return target.find(str) != std::string::npos; 19 | } 20 | 21 | inline std::vector split(std::string str, char delimiter) { 22 | std::vector result; 23 | std::stringstream ss(str); 24 | std::string temp; 25 | while(getline(ss, temp, delimiter)) { result.push_back(temp); } 26 | return result; 27 | } 28 | 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/cppm/util/system.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_UTIL_SYSTEM_HPP__ 4 | #define __CPPM_UTIL_SYSTEM_HPP__ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace cppm::util::system 12 | { 13 | #if defined(_WIN32) 14 | #define CPPM_PLATFORM_NAME "windows" // Windows 15 | #elif defined(_WIN64) 16 | #define CPPM_PLATFORM_NAME "windows" // Windows 17 | #elif defined(__CYGWIN__) && !defined(_WIN32) 18 | #define CPPM_PLATFORM_NAME "windows" // Windows (Cygwin POSIX under Microsoft Window) 19 | #elif defined(__ANDROID__) 20 | #define CPPM_PLATFORM_NAME "android" // Android (implies Linux, so it must come first) 21 | #elif defined(__linux__) 22 | #define CPPM_PLATFORM_NAME "linux" // Debian, Ubuntu, Gentoo, Fedora, openSUSE, RedHat, Centos and other 23 | #elif defined(__unix__) || defined(__APPLE__) && defined(__MACH__) 24 | #include 25 | #if defined(BSD) 26 | #define CPPM_PLATFORM_NAME "bsd" // FreeBSD, NetBSD, OpenBSD, DragonFly BSD 27 | #endif 28 | #elif defined(__hpux) 29 | #define CPPM_PLATFORM_NAME "hp-ux" // HP-UX 30 | #elif defined(_AIX) 31 | #define CPPM_PLATFORM_NAME "aix" // IBM AIX 32 | #elif defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin) 33 | #include 34 | #if TARGET_IPHONE_SIMULATOR == 1 35 | #define CPPM_PLATFORM_NAME "ios" // Apple iOS 36 | #elif TARGET_OS_IPHONE == 1 37 | #define CPPM_PLATFORM_NAME "ios" // Apple iOS 38 | #elif TARGET_OS_MAC == 1 39 | #define CPPM_PLATFORM_NAME "osx" // Apple OSX 40 | #endif 41 | #elif defined(__sun) && defined(__SVR4) 42 | #define CPPM_PLATFORM_NAME "solaris" // Oracle Solaris, Open Indiana 43 | #else 44 | #define CPPM_PLATFORM_NAME NULL 45 | #endif 46 | 47 | constexpr const char* what() { return (CPPM_PLATFORM_NAME == NULL) ? "" : CPPM_PLATFORM_NAME; } 48 | 49 | constexpr const char* prefix() { 50 | switch(hash(what())) 51 | { 52 | default: 53 | case "linux"_h: 54 | case "osx"_h: 55 | return "/usr/local/"; 56 | case "windows"_h: 57 | return "C:/users/"; 58 | } 59 | } 60 | 61 | std::string home_path(); 62 | 63 | std::string exec(const char* cmd ,const std::function& func = [](auto& str) { fmt::print(str);}); 64 | } 65 | 66 | #if defined(_MSC_VER) 67 | #define COMPILER_NAME "msvc" // visual studio 68 | #define COMPILER_VERSION _MSC_VER 69 | #define USE_MSVC 70 | #elif defined(__GNUC__) 71 | #define COMPILER_NAME "gcc" // gcc 72 | #define COMPILER_VERSION __GNUC__##__GNUC_MINOR__ 73 | #define USE_GCC 74 | #elif defined(__clang__) 75 | #define COMPILER_NAME "clang" // clang 76 | #define COMPILER_VERSION __clang_major__##__clang_minor__##__clang_patchlevel__ 77 | #define USE_CLANG 78 | #elif defined(__EMSCRIPTEN__) 79 | #define COMPILER_NAME "wsm" // web assembly 80 | #define USE_WSM 81 | #elif defined(__MINGW32__) "mingw" 82 | #define COMPILER_NAME "mingw" // mingw 32bit mingw-w64 32bit 83 | #define USE_MINGW32 84 | #elif defined(__MINGW64__) "mingw" 85 | #define COMPILER_NAME "mingw" // mingw-w64 64bit 86 | #define USE_MINGW64 87 | #else 88 | #define COMPILER_NAME NULL // can't find 89 | #endif 90 | 91 | namespace cppm::util::compiler 92 | { 93 | constexpr const char* what() { return (COMPILER_NAME == NULL) ? "" : COMPILER_NAME; } 94 | } 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /include/cppm/util/toml.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef CPPM_UTIL_TOML_HPP 4 | #define CPPM_UTIL_TOML_HPP 5 | 6 | #include 7 | #include "cppm/util/string.hpp" 8 | 9 | namespace cppm::util::toml { 10 | inline ::toml::value find_recursive(const ::toml::value& value, const std::string& key) { 11 | auto keys = str::split(key, '.'); 12 | ::toml::value buf = value; 13 | for(auto key : keys) { 14 | auto temp = ::toml::find(buf, key); 15 | buf = temp; 16 | } 17 | return buf; 18 | } 19 | } 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/cppm/util/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_VERSION_H__ 4 | #define __CPPM_VERSION_H__ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace cppm 12 | { 13 | class Version 14 | { 15 | public: 16 | Version() {}; 17 | Version(std::string version = "latest"); 18 | static Version parse(std::string version_include_string); 19 | bool operator< (const Version& other) const; 20 | bool operator> (const Version& other) const; 21 | bool operator== (const Version& other) const; 22 | Version& operator= (const std::string& str); 23 | std::string str(); 24 | operator std::string() const; 25 | friend std::ostream& operator << (std::ostream& stream, const Version& other); 26 | static std::optional get_latest_version_folder(const std::string& path); 27 | static std::optional find_version_folder(const std::string& path, const std::string& version); 28 | 29 | bool git = false; 30 | bool latest = false; 31 | int major = 0; 32 | int minor = 0; 33 | int revision = 0; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /need_to_change.md: -------------------------------------------------------------------------------- 1 | 2 | # 고쳐야할점 3 | * toml orm export 만들기 4 | * dependency single element 확실히 하기 5 | * workspace dependencies overwrite problem 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /scripts/backup-appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | branches: 3 | only: 4 | - master 5 | - dev 6 | clone_folder: c:\project\cppm 7 | image: 8 | #- Visual Studio 2013 9 | #- Visual Studio 2015 10 | - Visual Studio 2017 11 | configuration: 12 | - Release 13 | - Debug 14 | platform: 15 | - x64 16 | environment: 17 | matrix: 18 | - arch: Win64 19 | # - arch: #does not work, Release|x64 not a valid target 20 | matrix: 21 | fast_finish: true 22 | 23 | 24 | # skip unsupported combinations 25 | init: 26 | - set arch= 27 | - if "%arch%"=="Win64" ( set arch= Win64) 28 | - echo %arch% 29 | - echo %APPVEYOR_BUILD_WORKER_IMAGE% 30 | - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( set generator="Visual Studio 15 2017%arch%" ) 31 | #- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" ( set generator="Visual Studio 14 2015%arch%" ) 32 | #- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" ( set generator="Visual Studio 12 2013%arch%" ) 33 | - echo %generator% 34 | 35 | cache: 36 | # - '%HOME%\.cppm' 37 | # - '%HOME%\.hunter' 38 | 39 | build_script: 40 | - cmake -H. -Bbuild -G %generator% 41 | - cd build 42 | - cmake --build . 43 | 44 | 45 | -------------------------------------------------------------------------------- /scripts/backup-azure-pipeline.yml: -------------------------------------------------------------------------------- 1 | # Starter pipeline 2 | # Start with a minimal pipeline that you can customize to build and deploy your code. 3 | # Add steps that build, run tests, deploy, and more: 4 | # https://aka.ms/yaml 5 | 6 | trigger: 7 | - master 8 | 9 | jobs: 10 | - job: Ubuntu_1604_GCC7 11 | pool: 12 | vmImage: 'Ubuntu 16.04' 13 | steps: 14 | - script: | 15 | sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y 16 | sudo apt -y update 17 | sudo apt install g++-7 ninja-build libc++-dev libc++abi-dev build-essential libstdc++-7-dev ccache -y 18 | sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100 19 | displayName: dependency Install 20 | 21 | - task: CMake@1 22 | inputs: 23 | workingDirectory: $(Build.SourcesDirectory) 24 | cmakeArgs: -G Ninja -DCMAKE_BUILD_TYPE=Debug -H. -Bbuild/Debug 25 | displayName: Initialize CMake Project 26 | - task: CMake@1 27 | inputs: 28 | workingDirectory: build/Debug 29 | cmakeArgs: --build . 30 | displayName: "Build Debug Mode" 31 | 32 | - task: CMake@1 33 | inputs: 34 | workingDirectory: $(Build.SourcesDirectory) 35 | cmakeArgs: -G Ninja -DCMAKE_BUILD_TYPE=RELEASE -H. -Bbuild/Release 36 | displayName: Initialize CMake Project 37 | - task: CMake@1 38 | inputs: 39 | workingDirectory: build/Release 40 | cmakeArgs: ' --build .' 41 | displayName: "Build Release Mode" 42 | - job: Ubuntu_1604_Clang7 43 | pool: 44 | vmImage: 'Ubuntu 16.04' 45 | steps: 46 | - script: | 47 | sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y 48 | wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - 49 | sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main" 50 | sudo apt -y update 51 | sudo apt install clang++-7 ninja-build libc++-dev libc++abi-dev build-essential libstdc++-7-dev ccache -y 52 | sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-7 100 53 | sudo update-alternatives --install /usr/bin/c c /usr/bin/clang-7 100 54 | displayName: dependency Install 55 | 56 | - task: CMake@1 57 | inputs: 58 | workingDirectory: $(Build.SourcesDirectory) 59 | cmakeArgs: -G Ninja -DCMAKE_BUILD_TYPE=Debug -H. -Bbuild/Debug 60 | displayName: Initialize CMake Project 61 | - task: CMake@1 62 | inputs: 63 | workingDirectory: build/Debug 64 | cmakeArgs: ' --build .' 65 | displayName: "Build Debug Mode" 66 | 67 | - task: CMake@1 68 | inputs: 69 | workingDirectory: $(Build.SourcesDirectory) 70 | cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=RELEASE -H. -Bbuild/Release' 71 | displayName: Initialize CMake Project 72 | - task: CMake@1 73 | inputs: 74 | workingDirectory: build/Release 75 | cmakeArgs: ' --build .' 76 | displayName: "Build Release Mode" 77 | 78 | - job: Windows_VS2017_x86 79 | pool: 80 | vmImage: 'vs2017-win2016' 81 | steps: 82 | - script: | 83 | mkdir build 84 | - task: CMake@1 85 | inputs: 86 | workingDirectory: 'build' 87 | cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Debug --build .' 88 | displayName: "Build Debug Mode" 89 | - task: CMake@1 90 | inputs: 91 | workingDirectory: 'build' 92 | cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=RELEASE --build .' 93 | displayName: "Build Release Mode" 94 | 95 | - job: MacOs 96 | pool: 97 | vmImage: 'macOS-10.14' 98 | steps: 99 | - script: | 100 | brew install gcc ninja 101 | displayName: dependency Install 102 | - task: CMake@1 103 | inputs: 104 | workingDirectory: $(Build.SourcesDirectory) 105 | cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -H. -Bbuild/Debug' 106 | displayName: Initialize CMake Project 107 | - task: CMake@1 108 | inputs: 109 | workingDirectory: build/Debug 110 | cmakeArgs: ' --build .' 111 | displayName: "Build Debug Mode" 112 | 113 | - task: CMake@1 114 | inputs: 115 | workingDirectory: $(Build.SourcesDirectory) 116 | cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -H. -Bbuild/Release' 117 | displayName: Initialize CMake Project 118 | - task: CMake@1 119 | inputs: 120 | workingDirectory: build/Release 121 | cmakeArgs: ' --build .' 122 | displayName: "Build Release Mode" 123 | -------------------------------------------------------------------------------- /src/cmake/cmake.cpp: -------------------------------------------------------------------------------- 1 | #include "cmake/cmake.h" 2 | #include "cppm/util/filesystem.h" 3 | #include "cppm/util/optional.hpp" 4 | #include "cppm/util/system.hpp" 5 | #include "cppm/util/string.hpp" 6 | #include "cppm/util/algorithm.hpp" 7 | #include 8 | #include 9 | 10 | namespace cppm::cmake 11 | { 12 | Cache::Cache(std::string path) { 13 | path += "/CMakeCache.txt"; 14 | if(!fs::exists(path)) { exist_file_=false; return; } 15 | auto ss = std::stringstream{util::read_file_all(path)}; 16 | std::string to; 17 | std::regex filter("^(?!#)(.*):(.*)=(.*)$"); 18 | std::smatch what; 19 | while (std::getline(ss, to, '\n')) { 20 | if(std::regex_match(to, what, filter)) { 21 | variables.insert(std::make_pair(what[1], std::make_pair(what[2], what[3])));} 22 | } 23 | } 24 | 25 | bool Cache::exist(const std::string& name, const std::string& value) { 26 | if(auto data = variables.find(name); data != variables.end()) { 27 | if(data->second.second == value) return true; 28 | return false; 29 | } 30 | else { 31 | return false; 32 | } 33 | } 34 | 35 | Cmake Cmake::generator(const std::string& generator) { 36 | auto hook = [generator](auto& cache, auto& cmake_option){ 37 | if(!cache->exist("CMAKE_GENERATOR", generator)) { 38 | if(!cmake_option) cmake_option = ""; 39 | *cmake_option += "-G {} "_format(generator); 40 | } 41 | }; 42 | after_hooks.push(hook); 43 | return *this; 44 | } 45 | 46 | Cmake Cmake::define(const std::string name, const std::string value, const std::string option_type) { 47 | auto hook = [name, value, option_type](auto& cache, auto& cmake_option){ 48 | if(!cache->exist(name, value)) { 49 | if(!cmake_option) cmake_option = ""; 50 | *cmake_option += "-{}{}={} "_format(option_type, name, value); 51 | } 52 | }; 53 | after_hooks.push(hook); 54 | return *this; 55 | } 56 | 57 | Cmake Cmake::set(const std::string name, const std::string value, const std::string option_type) { 58 | if(!cache->exist(name, value)) { 59 | if(!cmake_option) cmake_option = ""; 60 | *cmake_option += "-{}{}={} "_format(option_type, name, value); 61 | } 62 | return *this; 63 | } 64 | 65 | Cmake Cmake::generator_options(const std::string& option) { 66 | if(!generator_option) generator_option = ""; 67 | *generator_option += option; 68 | return *this; 69 | } 70 | 71 | Cmake Cmake::set_target(const std::string& target) { 72 | target_ = target; 73 | return *this; 74 | } 75 | 76 | Cmake Cmake::build(const std::string& root, const std::string& build_path) { 77 | cache = Cache("{}/{}"_format(root, build_path)); 78 | define("CMAKE_BUILD_TYPE", build_type); 79 | if(prefix != "") set("CMAKE_INSTALL_PREFIX", prefix); 80 | if(toolchain) set("CMAKE_TOOLCHAIN_FILE", *toolchain); 81 | while(!after_hooks.empty()) { after_hooks.front()(cache, cmake_option); after_hooks.pop(); } 82 | 83 | auto current = fs::current_path(); 84 | util::working_directory("{}/{}"_format(root, build_path)); 85 | std::string script = (no_cache || cmake_option || !cache->exist_file()) ? 86 | "cmake {}.. && "_format(*cmake_option) : ""; 87 | 88 | auto target_script = target_ ? "--target {} "_format(*target_) : ""; 89 | script += "cmake --build . {}--config {} -- {}"_format(target_script, build_type, *generator_option); 90 | 91 | auto is_sudo = (!(strcmp(util::system::what(), "windows")) && sudo) ? "sudo" : ""; 92 | script += install ? " && {} cmake --install . && cmake --build . --target cppm_link"_format(is_sudo) : ""; 93 | if(detail) fmt::print(script + "\n"); 94 | system(script.c_str()); 95 | util::working_directory(current.string()); 96 | return *this; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/cmake/cmake.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef __CPPM_UTIL_CMAKE_H__ 3 | #define __CPPM_UTIL_CMAKE_H__ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace cppm::cmake 13 | { 14 | using namespace fmt::literals; 15 | inline std::string var(const std::string& str) { return "${{{0}}}"_format(str);} 16 | namespace func { 17 | inline std::string arg(const std::string& name, const std::string& value) { 18 | return name != "" ? "{} {} "_format(name, value) : ""; 19 | } 20 | } 21 | 22 | class Cache{ 23 | public: 24 | Cache(std::string path); 25 | bool exist(const std::string& name, const std::string& value); 26 | inline std::string& operator[](const std::string& name) { return variables[name].second; } 27 | bool exist_file() { return exist_file_; } 28 | using variable = std::pair; 29 | private: 30 | std::map variables; 31 | bool exist_file_=true; 32 | }; 33 | 34 | class Cmake { 35 | public: 36 | using opt_str = std::optional; 37 | Cmake() : cache(std::nullopt) {} 38 | Cmake generator(const std::string& generator); 39 | Cmake set_target(const std::string& target); 40 | Cmake generator_options(const std::string& option); 41 | Cmake define(const std::string name, const std::string value, const std::string option_type="D"); 42 | Cmake set(const std::string name, const std::string value, const std::string option_type="D"); 43 | Cmake build(const std::string& root, const std::string& build_path="build"); 44 | private: 45 | std::optional cache; 46 | opt_str cmake_option=std::nullopt; 47 | opt_str generator_option=std::nullopt; 48 | opt_str target_=std::nullopt; 49 | std::queue&, opt_str&)>> after_hooks; 50 | public: 51 | bool install=false; 52 | std::string prefix=""; 53 | std::string build_type="Debug"; 54 | opt_str toolchain=std::nullopt; 55 | bool no_cache=false; 56 | bool sudo=false; 57 | bool detail=false; 58 | }; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/core/config.cpp: -------------------------------------------------------------------------------- 1 | #include "cppm/core/config.hpp" 2 | #include 3 | #include 4 | #include "cppm/cppkg/cppkg.h" 5 | #include "cppm/core/cppm_tool.hpp" 6 | 7 | #include 8 | 9 | namespace cppm::core { 10 | 11 | Config Config::load(fs::path config_path) { 12 | using namespace fmt::literals; 13 | auto config = serde::serialize(toml::parse((config_path/"cppm.toml").string())); 14 | config.post_processing(config_path.string()); 15 | return config; 16 | } 17 | Config& Config::post_processing(const std::string& config_path) { 18 | using namespace ranges; 19 | using namespace fmt::literals; 20 | path = Path::make(config_path); 21 | if(!fs::exists(path.root/"cppm.toml")) { fmt::print(stderr, "can't find {} file", path.root.string()); } 22 | auto parse_source = [&](auto& source) { 23 | source = source 24 | | views::transform([&](auto it){ 25 | auto files = util::find_files(path.root.string(), std::regex(it), false); 26 | if(files.empty()) { fmt::print(stderr, "can't find {}\n", it); exit(1); } 27 | return files; }) 28 | | views::cache1 29 | | views::join 30 | | to_vector; 31 | }; 32 | 33 | if(lib) { parse_source(lib->source); } 34 | ranges::for_each(bins, [&](auto& it) { parse_source(it.source); }); 35 | ranges::for_each(examples, [&](auto& it) { parse_source(it.source); }); 36 | ranges::for_each(tests, [&](auto& it) { parse_source(it.source); }); 37 | ranges::for_each(benchmarks, [&](auto& it) { parse_source(it.source); }); 38 | 39 | //-------- 40 | 41 | auto load_cppkg = [&](auto& deps) { 42 | for(auto& [name, dep] : deps) { 43 | auto table = serde::deserialize(dep); 44 | if(dep.optional) { 45 | if(features.find(name) == features.end()) features[name] = {}; 46 | features[name].push_back({"$USE_{}_{}"_format(package.name, name) 47 | | copy | actions::transform(::toupper)}); 48 | } 49 | auto _path = path.thirdparty/"{}/{}/cppkg.toml"_format(name, dep.version); 50 | if(!fs::exists(_path) && dep.repo == repo_type::cppkg) { 51 | cppkg::install(*this, cppkg::search(name, dep.version)); 52 | } 53 | auto default_on = dep.default_features_flag; 54 | dep = {}; 55 | serde::serialize_to(toml::parse(_path)[name], dep); 56 | dep.default_feature = default_on ? dep.default_feature : decltype(dep.default_feature){}; 57 | serde::serialize_to(table, deps[name]); 58 | 59 | dep.name = name; 60 | if(!dep.custom) { 61 | auto _path = path.thirdparty/name/(dep.version); 62 | install_cppm_download_package(_path, dep); 63 | } 64 | } 65 | }; 66 | load_cppkg(dependencies); 67 | load_cppkg(dev_dependencies); 68 | 69 | for(auto& [name, tar] : target) { 70 | load_cppkg(tar.dependencies); 71 | load_cppkg(tar.dev_dependencies); 72 | } 73 | 74 | if(workspace) { 75 | std::map dep = workspace->member 76 | | views::transform([&](auto& it){ return Config::load(path.root/it); }) 77 | | views::cache1 78 | | views::filter([](auto&& it){ return it.lib.has_value(); }) 79 | | views::for_each([&](auto&& it) { 80 | Dependency dep; 81 | dep.name = it.lib->name; 82 | dep.version = it.package.version; 83 | dep.type = it.lib->type; 84 | dep.module = it.lib->name; 85 | dep.path.emplace(it.path.root.lexically_relative(path.root).generic_string()); 86 | dep.link = link_type::PUBLIC; 87 | dep.repo = repo_type::workspace; 88 | dep.optional = false; 89 | return yield(std::make_pair(it.lib.value().name, dep)); 90 | }) | to>; 91 | 92 | ranges::insert(dependencies, dep); 93 | } 94 | 95 | 96 | return *this; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/cppkg/cppkg.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace cppkg 12 | { 13 | using namespace fmt::literals; 14 | cppm::core::Dependency parse(const std::string& name, std::string path) { 15 | using namespace cppm; 16 | using deps = std::map; 17 | path = path != "" ? "{}/"_format(path) : ""; 18 | auto dep = serde::serialize(toml::parse("{}cppkg.toml"_format(path))); 19 | dep[name].name = name; 20 | return dep[name]; 21 | } 22 | 23 | void init(const std::string& name) { 24 | using namespace cppm::core; 25 | Dependency dep; 26 | dep.name = name; dep.type = cppkg_type::lib; 27 | init(dep); 28 | } 29 | 30 | void init(cppm::core::Dependency& dep) { 31 | using namespace cppm; 32 | auto value = [](const std::string& str){ return "\"{}\""_format(str); }; 33 | //auto convert = [](const bool flag) { return flag ? "true" : "false"; }; 34 | util::panic(!fs::exists("cppkg.toml"), "existed cppkg.toml"); 35 | auto url_type = dep.git ? "git={}"_format(value(*dep.git)) : "url={}"_format(value(*dep.url)); 36 | auto is_branch = dep.branch ? "" : "#"; 37 | util::create("cppkg.toml"); 38 | util::write("cppkg.toml" 39 | ,"[{}]\n"_format(dep.name) 40 | +"version={} #(require)\n"_format(value(dep.version)) 41 | +"type=\"{}\" #lib(default) | bin | cmake\n"_format(serde::to_string(dep.type)) 42 | +"description={} #(require)\n"_format(value(dep.description)) 43 | +"module={} #(require) if none_module=true -> no require\n"_format(value(*dep.module)) 44 | +"{} #(require)\n"_format(url_type) 45 | +"{}branch={} #(optional & require git)\n"_format(is_branch, value(*dep.branch)) 46 | +"#link=private #default\n" 47 | //+"#components={} #(optional)\n"_format(value(*dep.components)) 48 | //+"#none_module={} #(optional)\n"_format(convert(*dep.none_module)) 49 | //+"#helper={} #(optional)\n"_format(value(dep.helper)) 50 | //+"#load_path={} #(optional) (package_root) + /path/to/"_format(value(dep.load_path)) 51 | ); 52 | } 53 | 54 | void build(const std::string& name) { 55 | using namespace cppm; 56 | auto dep = cppkg::parse(name); 57 | auto dir_name = "{}/{}"_format(dep.name, dep.version); 58 | util::panic(!fs::exists(dir_name), "existed {}"_format(dir_name)); 59 | fs::create_directories(dir_name); 60 | fs::copy("cppkg.toml", dir_name+"/cppkg.toml"); 61 | fs::remove("cppkg.toml"); 62 | auto file = "{}/{}.cmake.in"_format(dir_name,dep.name); 63 | util::write(file, core::cppm_download_package(dep)); 64 | fmt::print("[cppkg] Success to make {} package\n",dep.name); 65 | } 66 | void build() { 67 | //using namespace cppm; 68 | //std::optional> deps; 69 | //toml::orm::parser(deps,"cppkg.toml"); 70 | //if(deps) { 71 | // ranges::for_each(*deps, [](auto it){ 72 | // 73 | // }); 74 | //} 75 | //auto file = "{}/{}.cmake.in"_format(dir_name,dep.name); 76 | //util::write(file, core::cppm_download_package(dep)); 77 | //fmt::print("[cppkg] Success to make {} package\n",dep.name); 78 | } 79 | 80 | void regist(const std::string& name) { 81 | using namespace cppm; 82 | core::Dependency dep; 83 | cppkg::parse(name); 84 | auto local_path = "{0}repo/local"_format(core::cppm_root()); 85 | auto pack_path = "{0}/{1}/{2}"_format(local_path, dep.name, dep.version); 86 | if(!fs::exists(local_path)) fs::create_directories(pack_path); 87 | if(fs::exists(pack_path)) fs::remove_all(pack_path); 88 | util::recursive_copy(name,pack_path); 89 | fmt::print("update {0}/{1} in local-repo [\"{2}\"]\n", dep.name, dep.version, pack_path); 90 | } 91 | 92 | 93 | Repos list() { 94 | using namespace cppm; 95 | auto root_path = "{0}repo"_format(core::cppm_root()); 96 | Repos cppkg_repos; 97 | if(auto repos = util::file_list(root_path)) { 98 | for(auto repo : *repos) { 99 | auto rname = repo.path().filename().generic_string(); 100 | if(auto pkgs = util::file_list("{0}/{1}"_format(root_path,rname))) { 101 | for(auto& pkg : *pkgs) { 102 | auto pname = pkg.path().filename().generic_string(); 103 | if(pname == ".git" || pname == "README.md" || pname == "_cppm_test") continue; 104 | if(auto versions = util::file_list("{0}/{1}/{2}"_format(root_path,rname,pname))) { 105 | for(auto& ver : *versions) { 106 | auto vname = ver.path().filename().generic_string(); 107 | cppkg_repos[rname].pkgs[pname].versions[vname] = "{0}/{1}/{2}/{3}"_format(root_path, rname, pname, vname); 108 | } 109 | } 110 | } 111 | } 112 | } 113 | } 114 | return cppkg_repos; 115 | } 116 | 117 | dep_in_repo search(const std::string& name, const std::string& version) { 118 | using namespace cppm; 119 | auto cppkg_path = "{0}repo"_format(core::cppm_root()); 120 | auto repos = util::panic(util::file_list(cppkg_path), "can't find cppkg repos"); 121 | 122 | std::map find_repos; 123 | for(auto& repo : repos) { 124 | auto repo_name = repo.path().filename().string(); 125 | if(version == "latest") { 126 | auto target = "{0}/{1}/{2}"_format(cppkg_path,repo_name,name); 127 | if(!fs::exists(target)) { continue; } 128 | if(auto latest = Version::get_latest_version_folder(target)) { 129 | find_repos[repo_name] = *latest; 130 | } 131 | } 132 | else { 133 | auto target = "{0}/{1}/{2}/{3}"_format(cppkg_path, repo_name, name, version); 134 | if(fs::exists(target)) { find_repos[repo_name] = target; } 135 | } 136 | } 137 | util::panic(!find_repos.empty(), "can't find {0}/{1} package"_format(name, version)); 138 | std::string path = ""; 139 | 140 | if (find_repos.find("cppkg") != find_repos.end()) path = find_repos["cppkg"]; 141 | else if (find_repos.find("local") != find_repos.end()) path = find_repos["local"]; 142 | else path = find_repos.begin()->second; 143 | auto dep = cppkg::parse(name,path); 144 | return {dep, path}; 145 | } 146 | 147 | void install(cppm::core::Config& config, const dep_in_repo& depr) { 148 | using namespace cppm; 149 | fs::create_directory(config.path.thirdparty); 150 | auto [dep, path] = depr; 151 | if(dep.helper) { 152 | fmt::print("{0}\n",*dep.helper); 153 | fmt::print("Install {0} to {1}/Modules/\n",dep.helper, config.path.cmake); 154 | if(!fs::exists("{0}/Modules/"_format(config.path.cmake))) { 155 | fs::create_directories("{0}/Modules"_format(config.path.cmake)); 156 | } 157 | fs::copy("{0}/{1}"_format(path,dep.helper) 158 | ,"{0}/Modules/{1}"_format(config.path.cmake,dep.helper)); 159 | } 160 | util::recursive_copy(path,"{0}/{1}/{2}"_format( 161 | config.path.thirdparty, dep.name, dep.version)); 162 | fmt::print("Install Cppkg {0}/{1}\n",dep.name, dep.version); 163 | } 164 | 165 | cppm::core::Dependency cppkg_auto_gen(std::string& path) { 166 | cppm::core::Dependency dep; 167 | 168 | return dep; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/cppm_version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_VERSION_H_ 4 | #define __CPPM_VERSION_H_ 5 | 6 | #define CPPM_VERSION "0.0.13" 7 | #define CPPM_TOOLS_VERSION "0.0.12" 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "option/cppm.h" 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | cppm::option::Cppm cppm; 6 | cppm.run(argc, argv); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/option/add.cpp: -------------------------------------------------------------------------------- 1 | #include "option/add.h" 2 | 3 | #include 4 | #include 5 | 6 | using namespace fmt::literals; 7 | 8 | namespace cppm::option 9 | { 10 | Add::Add() { 11 | app_.add_command("toolchain") 12 | .desc("add cmake toolchain #example# cppm add toolchains {toolchain_path}... ") 13 | .args("{path}") 14 | .call_back([&](){ _toolchain(); }); 15 | app_.add_command("cppm_path") 16 | .desc("add cppm path to use cppm update command") 17 | .args("{path}") 18 | .call_back([&](){ _cppm_path(); }); 19 | } 20 | 21 | void Add::_toolchain() { 22 | if(app_.args().empty()) { 23 | fmt::print(stderr, "need argument"); 24 | exit(1); 25 | } 26 | // CppmPackage::add_toolchain(app_.get_arg()); 27 | } 28 | 29 | void Add::_cppm_path() { 30 | if(app_.args().empty()) { 31 | fmt::print(stderr, "need argument"); 32 | exit(1); 33 | } 34 | //CppmPackage::add_cppm_path(app_.get_arg()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/option/add.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_OPTION_ADD_H__ 4 | #define __CPPM_OPTION_ADD_H__ 5 | 6 | #include "option/base_option.h" 7 | 8 | namespace cppm::option 9 | { 10 | class Add : public base_option 11 | { 12 | public: 13 | Add(); 14 | private: 15 | void _toolchain(); 16 | void _cppm_path(); 17 | }; 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /src/option/base_option.cpp: -------------------------------------------------------------------------------- 1 | #include "option/base_option.h" 2 | #include "cppm/util/filesystem.h" 3 | #include "cppm/util/algorithm.hpp" 4 | #include 5 | 6 | namespace cppm::option { 7 | bool base_option::config_load(bool panic) { 8 | fs::path start_position = (start_path_ == "") ? fs::current_path() : fs::path{start_path_}; 9 | auto path = cppm::util::reverse_find_file(start_position, "cppm.toml"); 10 | if(!path) { 11 | if(panic) { 12 | fmt::print("can't find cppm.toml\n"); 13 | exit(1); 14 | } else { 15 | fmt::print("can't find cppm.toml\nbuild with cppm_toolchain\n"); 16 | } 17 | return false; 18 | } 19 | // 나중에 쓸예정 none cppm test 20 | config_ = core::Config::load(path->parent_path()); 21 | return true; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/option/base_option.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_OPTION_BASE_OPTION_H__ 4 | #define __CPPM_OPTION_BASE_OPTION_H__ 5 | 6 | #include 7 | #include 8 | 9 | namespace cppm::option 10 | { 11 | class base_option 12 | { 13 | public: 14 | nlpo::App& app() { return app_; } 15 | virtual ~base_option() {} 16 | bool config_load(bool panic=true); 17 | void start_from(const std::string& path) { start_path_ = path; } 18 | protected: 19 | nlpo::App app_; 20 | std::optional config_; 21 | //Config::ptr config_; 22 | std::string start_path_ = ""; 23 | }; 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/option/build.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "option/build.h" 12 | #include "cppm/util/algorithm.hpp" 13 | #include "cppm/util/filesystem.h" 14 | #include "cppm/cppkg/cppkg.h" 15 | #include "cppm/util/system.hpp" 16 | 17 | #include "cppm/util/string.hpp" 18 | #include "cppm/core/cppm_tool.hpp" 19 | #include "cppm_version.h" 20 | #include "cmake/cmake.h" 21 | 22 | #include "serdepp/adaptor/nlohmann_json.hpp" 23 | #include "serdepp/adaptor/toml11.hpp" 24 | 25 | using namespace fmt::literals; 26 | using namespace std::literals; 27 | using namespace cppm::util::str; 28 | namespace cppm::option 29 | { 30 | Build::Build() { 31 | app_.add_option("Generator").abbr("G").args("{Generator}") 32 | .desc("cmake -G option") 33 | .call_back([&](){ cmake_.generator(app_.get_arg());}); 34 | app_.add_option("ninja").abbr("n") 35 | .desc("ninja use to build this option remove build directory") 36 | .call_back([&](){ cmake_.generator("Ninja"); clean=true; }); 37 | app_.add_option("make").abbr("m") 38 | .desc("Unix make use to build this option remove build directory") 39 | .call_back([&](){ cmake_.generator("Unix Makefiles"_quot); clean = true; }); 40 | app_.add_option("gcc").abbr("g") 41 | .desc("g++ use to compile ") 42 | .call_back([&](){ cmake_.define("CMAKE_CXX_COMPILER", "g++"); }); 43 | app_.add_option("clang").abbr("c") 44 | .desc("clang++ use to compile ") 45 | .call_back([&](){ cmake_.define("CMAKE_CXX_COMPILER", "clang++");}); 46 | app_.add_option("release").abbr("r") 47 | .desc("compile release mode") 48 | .call_back([&](){ cmake_.build_type="Release"; }); 49 | app_.add_option("debug").abbr("d") 50 | .desc("compile debug mode") 51 | .call_back([&](){ cmake_.build_type="Debug"; }); 52 | app_.add_option("clean") 53 | .desc("clean cmake cache") 54 | .call_back([&](){ clean = true; }); 55 | app_.add_option("detail") 56 | .desc("show cppm generate cmake commands") 57 | .call_back([&](){ cmake_.detail = true; }); 58 | app_.add_option("ntc") 59 | .desc("not change CMakeLists.txt test options") 60 | .call_back([&](){ none_tc = true; }); 61 | app_.add_option("tc") 62 | .desc("only change CMakeLists.txt") 63 | .call_back([&](){ only_tc = true; }); 64 | app_.add_option("check") 65 | .desc("dependency check") 66 | .call_back([&](){ cmake_.no_cache=true; }); 67 | app_.add_option("toolchains") 68 | .desc("build with cmake toolchain") 69 | .call_back([&](){ cmake_.toolchain = app_.get_arg(); }); 70 | app_.add_option("Define") 71 | .abbr("D") 72 | .desc("set cmake cache variable, same cmake -D option") 73 | .args("{cache name} {value}") 74 | .call_back([&](){ cmake_.define(app_.get_arg(), app_.get_arg()); }); 75 | app_.add_option("export") 76 | .desc("export cppkg") 77 | .call_back([&](){ config_load(); export_cppkg(); }); 78 | app_.add_option("local") 79 | .desc("install local") 80 | .call_back([&](){ cmake_.prefix = ""; clean=true;}); 81 | app_.add_option("global") 82 | .desc("install global") 83 | .call_back([&](){ cmake_.sudo=true; cmake_.prefix = "/usr/local"; clean = true; }); 84 | app_.add_command("install") 85 | .desc("cmake target install ") 86 | .call_back([&](){ cmake_.install = true; }) 87 | .call_back([&](){ cmake_.build_type="Release"; }); 88 | app_.add_command("uninstall") 89 | .desc("cmake target uninstall") 90 | .call_back([&](){ cmake_.set_target("uninstall"); }); 91 | app_.add_option("prefix") 92 | .desc("cmake install prefix") 93 | .call_back([&](nlpo::arg::One arg){ cmake_.prefix = arg; clean=true; }); 94 | app_.add_option("print") 95 | .desc("print cppm config (fmt or json or toml)") 96 | .call_back([&](nlpo::arg::One arg){ print_format = arg; }); 97 | app_.add_command().args("{builder options}") 98 | .desc("Build command") 99 | .call_back([&](){ 100 | auto is_cppm = config_load(false); 101 | if(!is_cppm) { none_tc = true; } 102 | if(print_format) print_config(); 103 | 104 | auto cmake_script = util::reverse_find_file(fs::current_path() ,"CMakeLists.txt"); 105 | if(!is_cppm && !cmake_script) { fmt::print(stderr,"this package is not cmake project\n"); exit(1); } 106 | 107 | core::Path path = is_cppm ? config_->path : core::Path::make(cmake_script->parent_path().string()); 108 | if(is_cppm && config_->cmake.toolchain) { 109 | cmake_.define("CMAKE_EXTERNAL_TOOLCHAIN_FILE", config_->cmake.toolchain.value()); 110 | } 111 | if(cmake_.toolchain) { cmake_.define("CMAKE_EXTERNAL_TOOLCHAIN_FILE", cmake_.toolchain.value()); } 112 | if(!is_cppm){ 113 | cmake_.toolchain = "{}cmake/cppm-tools-{}/toolchain.cmake"_format(core::cppm_root(), 114 | CPPM_TOOLS_VERSION); 115 | } 116 | if(cmake_.prefix == "") cmake_.define("USE_CPPM_PATH", "ON"); 117 | 118 | fs::create_directories(path.build); 119 | if(!none_tc) { 120 | transcompile(path); 121 | if(only_tc) { exit(1); } 122 | } 123 | if(clean) { 124 | fmt::print("[cppm] Clean {}/CMakeCache.txt\n"_format(path.build)); 125 | fs::remove(config_->path.build/"CMakeCache.txt"); 126 | } 127 | if(!app_.args().empty()) { 128 | cmake_.generator_options(util::str::quot(util::accumulate(app_.args(), " "))); 129 | app_.args().clear(); 130 | } 131 | if(util::compiler::what() != "msvc"s) { 132 | cmake_.generator_options(" -j{} "_format(std::thread::hardware_concurrency())); 133 | } 134 | cmake_.build(path.root.string(), "build"); 135 | }); 136 | } 137 | 138 | void Build::print_config() { 139 | if(*print_format == "fmt") { fmt::print("{}",*config_); } 140 | if(*print_format == "json") { fmt::print("{}", serde::deserialize(*config_).dump(3)); } 141 | if(*print_format == "toml") { std::cout << serde::deserialize(*config_); } 142 | } 143 | 144 | void Build::transcompile(core::Path& path) { 145 | auto tranc_cmake = cppm_translate(config_.value()); 146 | if(util::file_hash("{0}/CMakeLists.txt"_format(path.root)) != hash::MD5{}(tranc_cmake)) { 147 | fmt::print("[cppm] Generate CMakeLists.txt\n"); 148 | util::write_file("{0}/CMakeLists.txt"_format(path.root), tranc_cmake); 149 | } 150 | fs::create_directories(path.cmake); 151 | util::over_write_copy_file("{0}cmake/cppm_loader.cmake"_format(core::cppm_root()) 152 | ,"{0}/cppm_loader.cmake"_format(path.cmake)); 153 | } 154 | 155 | 156 | void Build::export_cppkg() { 157 | core::Dependency pkg; 158 | pkg.name = config_->package.name; 159 | if(config_->lib) { 160 | auto& lib = config_->lib; 161 | pkg.module = 162 | lib->install 163 | ? "{0}::{1} "_format(config_->package.name, lib->name) 164 | : ""; 165 | pkg.type = core::cppkg_type::lib; 166 | } 167 | if (!config_->bins.empty()) pkg.type = core::cppkg_type::bin; 168 | pkg.description = config_->package.description; 169 | pkg.git = *config_->package.git_repo; 170 | pkg.version = "git"; 171 | cppkg::init(pkg); 172 | cppkg::build(pkg.name); 173 | exit(0); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/option/build.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_OPTION_BUILD_H__ 4 | #define __CPPM_OPTION_BUILD_H__ 5 | 6 | #include "option/base_option.h" 7 | #include "cmake/cmake.h" 8 | #include 9 | #include 10 | 11 | namespace cppm::option 12 | { 13 | class Build : public base_option 14 | { 15 | public: 16 | Build(); 17 | private: 18 | void export_cppkg(); 19 | void print_config(); 20 | void transcompile(core::Path& path); 21 | private: 22 | cmake::Cmake cmake_; 23 | bool none_tc = false; 24 | bool only_tc = false; 25 | bool clean = false; 26 | std::optional print_format = std::nullopt; 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/option/cppkg.cpp: -------------------------------------------------------------------------------- 1 | #include "option/cppkg.h" 2 | #include "option/cppkg_init.h" 3 | #include "cppm/core/cppm_tool.hpp" 4 | #include "cppm/cppkg/cppkg.h" 5 | #include "cppm/util/filesystem.h" 6 | #include "cppm/util/string.hpp" 7 | #include "option/cppkg_install.h" 8 | #include "option/cppkg_search.h" 9 | #include 10 | 11 | using namespace fmt::literals; 12 | using namespace cppm::util::str; 13 | 14 | namespace cppm::option 15 | { 16 | Cppkg::Cppkg() { 17 | app_.add_command("init").args("{option} {name}").desc("init cppkg"); 18 | app_.add_command("build").args("{cppkg name}") 19 | .desc("build cppm package file") 20 | .call_back([&](){ _build(); }); 21 | app_.add_command("update") 22 | .desc("update cppkg repo") 23 | .call_back([&](){ _update(); }); 24 | app_.add_command("search").args("{name}").desc("search cppkg repo, default is only cppkg"); 25 | app_.add_command("push").args("{name}") 26 | .desc("push cppkg in local repo") 27 | .is_show(false) 28 | .call_back([&](){ _push(); }); 29 | app_.add_command("install").args("{name}").desc("install cppkg package"); 30 | } 31 | 32 | void Cppkg::_update() { 33 | using namespace fmt::literals; 34 | auto cppkg_path = "{0}repo/cppkg"_format(core::cppm_root()); 35 | if(!fs::exists(cppkg_path)) { 36 | fmt::print("clone cppkg path:{}\n",cppkg_path); 37 | system("git clone https://github.com/injae/cppkg.git {}"_format(cppkg_path).c_str()); 38 | } 39 | 40 | auto command = "cd {0} && git fetch origin && git pull origin master"_format(cppkg_path); 41 | system(command.c_str()); 42 | } 43 | 44 | void Cppkg::_build() { 45 | if(app_.args().empty()) { fmt::print(stderr,"need argument"); exit(1);} 46 | if(app_.args().size() > 1) { fmt::print(stderr,"too many argument"); exit(1);} 47 | cppkg::build(app_.get_arg()); 48 | } 49 | 50 | void Cppkg::_push() { 51 | if(app_.args().empty()) { fmt::print(stderr,"need argument");} 52 | if(app_.args().size() > 1) { fmt::print(stderr,"too many argument");} 53 | cppkg::regist(app_.get_arg()); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/option/cppkg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CPPM_OPTION_CPPKG_H__ 4 | #define __CPPM_OPTION_CPPKG_H__ 5 | 6 | #include "option/base_option.h" 7 | 8 | namespace cppm::option 9 | { 10 | class Cppkg : public base_option 11 | { 12 | public: 13 | Cppkg(); 14 | private: 15 | void _update(); 16 | void _build(); 17 | void _push(); 18 | }; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/option/cppkg_init.cpp: -------------------------------------------------------------------------------- 1 | #include "option/cppkg_init.h" 2 | #include "option/init.h" 3 | #include 4 | #include 5 | #include