Skip to content

Plan for precompiled mode #338

Closed
@henryiii

Description

@henryiii

Current idea:

  • All non-templated function/method bodies move to new files, such as option_fwd.inl.
  • inline gets replaced by CLI11_INLINE_DEF
  • If CLI11_COMPILE is not defined, CLI11_INLINE_DEF is inline and the .inl files get included at the end of option.hpp
  • If CLI11_COMPILE is defined, CLI11_INLINE_DEF is nothing. 0 or 1 selects whether this is the compiled file or a user.
  • The generation scripts need to be adjusted to handle this correctly; the .icc part will be wrapped in #ifs.

The CMake files will automatically compile each header with an icc file, and link to that. A user not using CMake can add a file like this:

#def CLI11_COMPILE 1
#include "CLI11.hpp"

Then use CLI11 like this:

#def CLI11_COMPILE 0
#include "CLI11.hpp"

And get the benefits of compilation. If nothing is done, nothing changes and everything is header only.


// option.hpp

#include "option_fwd.hpp"
#ifndef CLI11_COMPILE || CLI11_COMPILE==1
#include "option.inl"
#endif
// option_fwd.hpp

// Minimal required includes 
// [cli11:preinc:includes]
#include <fwd>
// [cli11:preinc:end]

// All files need this (has inline, etc)
#include "macros.hpp"

// Includes for other files in CLI11 (fwd only)
#include "app_fwd.hpp"

namespace CLI {
// [cli11:app_fwd:code]

class Option {
   // Definitions and templated functions only
};
CLI11_INLINE void f();

// [cli11:app_fwd:end]
}  // namespace CLI
// option.inl

// Currently not planning to include fwd here, since it is an inline file (depending on IDEs, possibly)

// Compile only includes
// [cli11:inc:includes]
#include <algorithm>
// [cli11:inc:end]

namespace CLI {
// [cli11:option_inl:code]
Option::Option() {} // Definitions
CLI11_INLINE void f() {} 
// [cli11:option_inl:end]
}  // namespace CLI
// option.cpp
#define CLI11_COMPILE 1 // Might as well force it here)
#include <option.hpp>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions