Skip to content

Conversation

Altren
Copy link
Contributor

@Altren Altren commented Oct 3, 2024

This PR based on the #202 changes.
Cuts tests build time by 10% on my machine, no hacks or workarounds, just some simple moves to .cpp

@liuzicheng1987
Copy link
Contributor

Sounds great!

@liuzicheng1987
Copy link
Contributor

@Altren , I think this is a great initiative that makes a lot of sense.

I think a couple of minor changes are still necessary, though:

If we are going to place the JSON code into a source file, we should do the same for all supported formats.

Moreover, we should then determine in the CMakeLists.txt whether we want to compile the source file for a particular format. JSON support is activated by default, but it can be turned off, so we mustn't assume that JSON can be installed.

So I think there should be a source file called reflectcpp_json.cpp, reflectcpp_yaml.cpp, etc

And if the flag for the format is set, the source file will be compiled.

Do you understand what I mean?

@liuzicheng1987
Copy link
Contributor

If you don't want to do this, I can do it myself.

@Altren
Copy link
Contributor Author

Altren commented Oct 4, 2024

If we are going to place the JSON code into a source file, we should do the same for all supported formats.

I agree, I wanted to suggest this change as a next step, since this require more complex changes. But I'm fine doing that in the current PR and will do that.

Moreover, we should then determine in the CMakeLists.txt whether we want to compile the source file for a particular format. JSON support is activated by default, but it can be turned off, so we mustn't assume that JSON can be installed.
So I think there should be a source file called reflectcpp_json.cpp, reflectcpp_yaml.cpp, etc

This would break the idea of having single source file to compile. But I guess we can keep it simple like:
"If you want to compile reflectcpp with yaml support add reflectcpp.cpp and reflectcpp_yaml.cpp into your build"

I'll do some initial implementation that looks good to me, then we can discuss if it have any disadvantages

@Altren
Copy link
Contributor Author

Altren commented Oct 4, 2024

I've added json.cpp implementation. Please review and if everything looks ok for you I'll continue with other formats

@Altren
Copy link
Contributor Author

Altren commented Oct 4, 2024

Also I feel like reflectcpp_json.cpp and reflectcpp.cpp should not be in the same directory where other source files are, but don't know how to organize this.
The motivation here is that it might be confusing which are "real" source files and whilch are used for users and build system convenience.

@liuzicheng1987
Copy link
Contributor

@Altren , looks really great.

One minor thing:

if (REFLECTCPP_JSON)
    list(APPEND REFLECT_CPP_SOURCES
        src/reflectcpp_json.cpp
    )
    if (REFLECTCPP_USE_BUNDLED_DEPENDENCIES)
       ....
    else ()
        find_package(ctre CONFIG REQUIRED)
        ...
    endif ()
endif ()

CTRE is required regardless of whether we need JSON. So this should be outside the condition if (REFLECTCPP_JSON):

  if (REFLECTCPP_USE_BUNDLED_DEPENDENCIES)
      target_include_directories(
          reflectcpp PUBLIC
          $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/rfl/thirdparty>)
  else ()
      find_package(ctre CONFIG REQUIRED)
  endif ()

if (REFLECTCPP_JSON)
   ...
endif()

@Altren
Copy link
Contributor Author

Altren commented Oct 5, 2024

There are only two new commits above (XML to cpp) and squashed changes about ctre

@Altren
Copy link
Contributor Author

Altren commented Oct 5, 2024

Should I continue with other formats in this PR or better do them in a separate on to avoid too big PR?

@Altren
Copy link
Contributor Author

Altren commented Oct 5, 2024

^ rebased onto main to resolve conflicts

@Altren
Copy link
Contributor Author

Altren commented Oct 7, 2024

Just in case, now this is totally complete, unless there are more review comments

@liuzicheng1987 liuzicheng1987 merged commit 9dcd49a into getml:main Oct 8, 2024
7 checks passed
@liuzicheng1987
Copy link
Contributor

@Altren , merged. Thank you for your contribution.

@Altren Altren deleted the cpp_usage branch October 8, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants