diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index e0edae9..b27a466 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -8,7 +8,7 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release + BUILD_TYPE: Debug jobs: build: @@ -22,12 +22,12 @@ jobs: - uses: actions/checkout@v2 - name: Install dependencies - run: brew install rapidjson llvm + run: brew install rapidjson llvm@11 - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_PREFIX_PATH=$(brew --prefix llvm) + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_PREFIX_PATH=$(brew --prefix llvm@11) - name: Build # Build your program with the given configuration diff --git a/README.md b/README.md index 3058700..998184b 100644 --- a/README.md +++ b/README.md @@ -9,103 +9,18 @@ Initial idea picked up from this conference by Sergiy Migdalskiy: https://archiv ## Requirements -- Llvm 11 +- MacOS +- Llvm 11 - Llvm 12 is not supported - RapidJson 1.x You might need to give the path to the llvm folder to CMake: ```bash +brew install llvm@11 rapidjson ninja mkdir builds && cd builds -cmake .. -G Ninja -DCMAKE_PREFIX_PATH= +cmake .. -G Ninja -DCMAKE_PREFIX_PATH=$(brew --prefix llvm@11) ninja ``` -With brew you can print the path using: -```bash -brew --prefix llvm -``` -```bash -cmake .. -G Ninja -DCMAKE_PREFIX_PATH="$(brew --prefix llvm)" -``` - -## Example -File test_example.hpp: -```c++ -#ifndef CPP2JSON_TEST_EXAMPLE_HPP -#define CPP2JSON_TEST_EXAMPLE_HPP -#include - -struct Example01 -{ - float m_float; - std::string m_string; - int m_int; -}; -#endif //CPP2JSON_TEST_EXAMPLE_HPP -``` - -Run cpp2json on it: -```bash -$> cpp2json test_example.hpp --pretty -- -``` - -Will give you the following JSON output: -```json -{ - "classes": { - "Example01": { - "fields": [ - { - "name": "m_float", - "type": { - "key": "float", - "expression": "float", - "pointer": false, - "array": false, - "reference": false, - "const": false, - "volatile": false, - "literal": true, - "enum": false - } - }, - { - "name": "m_string", - "type": { - "key": "std::string", - "expression": "std::string", - "pointer": false, - "array": false, - "reference": false, - "const": false, - "volatile": false, - "literal": false, - "enum": false - } - }, - { - "name": "m_int", - "type": { - "key": "int", - "expression": "int", - "pointer": false, - "array": false, - "reference": false, - "const": false, - "volatile": false, - "literal": true, - "enum": false - } - } - ], - "methods": [], - "annotations": [], - "bases": [], - "file": "/Users/iota/projects/tools/cpp2json/sources/tests/resources/test_example.hpp" - } - }, - "enums": {} -} -``` ## Usage ```bash USAGE: cpp2json [options] [... ] diff --git a/sources/core/src/CommandLineHelpers.cpp b/sources/core/src/CommandLineHelpers.cpp index d622eb2..883273b 100644 --- a/sources/core/src/CommandLineHelpers.cpp +++ b/sources/core/src/CommandLineHelpers.cpp @@ -4,8 +4,11 @@ static std::string const LlvmBasePath{LLVM_DIR}; clang::tooling::CommandLineArguments makeLlvmIncludeArguments() { + assert( !LlvmBasePath.empty() ); + std::string const llvmVersion = LlvmBasePath.substr(LlvmBasePath.find_last_of('/')); clang::tooling::CommandLineArguments extraArguments{ + "-std=c++14", "-I" + LlvmBasePath + "/include/c++/v1", "-I" + LlvmBasePath + "/lib/clang/" + llvmVersion + "/include", }; diff --git a/sources/tests/Cpp2JsonVisitorFixture.cpp b/sources/tests/Cpp2JsonVisitorFixture.cpp index 48765f4..52c5ee9 100644 --- a/sources/tests/Cpp2JsonVisitorFixture.cpp +++ b/sources/tests/Cpp2JsonVisitorFixture.cpp @@ -54,7 +54,8 @@ rapidjson::Value::ConstObject Cpp2JsonVisitorFixture::getField(std::string const return field; } } - assert(false); + + throw std::runtime_error("field not found"); } rapidjson::Value::ConstArray Cpp2JsonVisitorFixture::getFieldsOf(const std::string &className) const