Skip to content

Commit

Permalink
add HAVE_{component} defines only to main component, improving compil…
Browse files Browse the repository at this point in the history
…ation time when a component is disabled. use "static inline" in misc/print.h to ensure that the correct function is used in every translat1ion unit
  • Loading branch information
NiklasRosenstein committed Sep 12, 2018
1 parent ffa9a9c commit 53d603e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
17 changes: 5 additions & 12 deletions build.craftr
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,8 @@ class ComponentList(object):
self.components.append(Component(*args, **kwargs))
return self

def defines(self):
result = []
for comp in self:
if comp.enabled:
result.append('HAVE_' + comp.name.upper())
return result

def compile_all(self, dependencies=(), **options):
result = []
defines = self.defines()
for comp in self:
if not comp.enabled:
continue
Expand All @@ -89,7 +81,7 @@ class ComponentList(object):
properties({
'cxx.srcs': comp.sources,
'cxx.link': False,
'cxx.defines': comp.defines + defines,
'cxx.defines': comp.defines,
'cxx.enableExceptions': True,
'cxx.cppStd': 'c++17',
'c4d.SourceProcessor': False
Expand Down Expand Up @@ -119,9 +111,6 @@ def glob_descriptions(pattern):
# ============================================================================

components = (ComponentList()
.add("main",
sources=['source/main.cpp', 'source/menu.cpp', 'source/config.cpp', 'source/fs.cpp']
)
.add("autoconnect",
enabled=True,
sources=['source/autoconnect.cpp'],
Expand Down Expand Up @@ -177,6 +166,10 @@ components = (ComponentList()
dependencies=[':webp']
)
)
components.add("main",
sources=['source/main.cpp', 'source/menu.cpp', 'source/config.cpp', 'source/fs.cpp'],
defines=['HAVE_' + x.name.upper() for x in components if x.enabled]
)

# ============================================================================
# Compilation Targets
Expand Down
10 changes: 5 additions & 5 deletions source/misc/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,38 +79,38 @@ inline String _join_for_print(String const& sep, T const& t, R&&... r) {
*/
//============================================================================
template <typename... R>
inline void print(R&&... r) {
static inline void print(R&&... r) {
GePrint(String(PRINT_PREFIX) + _join_for_print(String(" "), std::forward<R>(r)...));
}

//============================================================================
//============================================================================
template <typename... R>
inline void info(R&&... r) {
static inline void info(R&&... r) {
if (PRINT_LEVEL <= PRINT_INFO)
print(std::forward<R>(r)...);
}

//============================================================================
//============================================================================
template <typename... R>
inline void debug(R&&... r) {
static inline void debug(R&&... r) {
if (PRINT_LEVEL <= PRINT_DEBUG)
print(std::forward<R>(r)...);
}

//============================================================================
//============================================================================
template <typename... R>
inline void warn(R&&... r) {
static inline void warn(R&&... r) {
if (PRINT_LEVEL <= PRINT_WARN)
print(std::forward<R>(r)...);
}

//============================================================================
//============================================================================
template <typename... R>
inline void error(R&&... r) {
static inline void error(R&&... r) {
if (PRINT_LEVEL <= PRINT_ERROR)
print(std::forward<R>(r)...);
}
Expand Down

0 comments on commit 53d603e

Please sign in to comment.