Skip to content

Commit 24898fb

Browse files
committed
added gbase, make sqlite static false on linux
1 parent 19bbfbe commit 24898fb

7 files changed

Lines changed: 128 additions & 23 deletions

File tree

gbase/examples/test_gbase.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
#include "gbase.h"
3+
4+
class g1 : public GBase<g1> {
5+
public:
6+
int object1 = 2;
7+
8+
explicit g1(std::shared_ptr<GOptions> gopt) : GBase(gopt) {
9+
log->info(0, "hello derived class ", SFUNCTION_NAME);
10+
}
11+
12+
~g1() = default;
13+
};
14+
15+
// returns this example options
16+
GOptions defineOptions() {
17+
18+
GOptions goptions("g1");
19+
20+
// command line switch
21+
goptions.defineSwitch("light", "a switch, this is just an example.");
22+
23+
return goptions;
24+
}
25+
26+
int main(int argc, char *argv[]) {
27+
28+
auto gopts = std::make_shared<GOptions>(argc, argv, defineOptions());
29+
30+
31+
g1 obj(gopts);
32+
33+
return EXIT_SUCCESS;
34+
35+
}

gbase/gbase.cc

Whitespace-only changes.

gbase/gbase.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <string>
5+
#include <typeinfo>
6+
7+
#include "glogger.h"
8+
9+
#define SDERIVED_NAME demangle(typeid(Derived).name())
10+
11+
12+
#if defined(__GNUG__)
13+
#include <cxxabi.h>
14+
#include <memory>
15+
16+
std::string inline demangle(const char* name) {
17+
int status = 0;
18+
using deleter_t = void(*)(void*);
19+
std::unique_ptr<char, deleter_t> demangled(abi::__cxa_demangle(name, nullptr, nullptr, &status), std::free);
20+
return (status == 0 && demangled) ? demangled.get() : name;
21+
}
22+
23+
#else
24+
std::string demangle(const char* name) {
25+
return name; // No demangling on non-GNU compilers
26+
}
27+
#endif
28+
29+
template <typename Derived>
30+
class GBase {
31+
public:
32+
explicit GBase(std::shared_ptr<GOptions> gopt) {
33+
log = std::make_shared<GLogger>(gopt, getDerivedName(), SDERIVED_NAME);
34+
log->debug(CONSTRUCTOR, getDerivedName());
35+
}
36+
37+
~GBase() {
38+
log->debug(DESTRUCTOR, SDERIVED_NAME);
39+
}
40+
41+
private:
42+
43+
std::string getDerivedName() const {
44+
return demangle(typeid(Derived).name());
45+
}
46+
47+
protected:
48+
std::shared_ptr<GLogger> log;
49+
};

gbase/meson.build

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sub_dir_name = meson.current_source_dir().split('/').get(-1)
2+
example_source = files('examples/test_gbase.cc')
3+
verbosity = ['-verbosity.g1=2', '-debug.g1=true']
4+
5+
LD += {
6+
'name' : sub_dir_name,
7+
'headers' : files(
8+
'gbase.h',
9+
),
10+
'dependencies' : [yaml_cpp_dep, clhep_deps, geant4_deps],
11+
12+
'examples' : {
13+
'test_gbase' : [example_source, verbosity],
14+
}
15+
}

glogging/glogger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#define FUNCTION_NAME __func__ // fallback
2222
#endif
2323

24+
#define SFUNCTION_NAME __func__ // Always portable and standard since C++11
25+
2426

2527

2628
/**

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ add_project_arguments('-Wno-shadow', language : ['cpp'])
4141
subdir('guts')
4242
subdir('goptions')
4343
subdir('glogging')
44+
subdir('gbase')
4445
subdir('gfactory')
4546
subdir('textProgressBar')
4647
subdir('gtouchable')

meson/meson.build

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ qt6_deps = dependency('qt6',
66
include_type : 'preserve')
77

88
# check system: pkg-config --cflags --libs gl
9-
ogl_deps = dependency('opengl', required: true)
9+
ogl_deps = dependency('opengl', required : true)
10+
11+
# pkg-config --cflags --libs gl.
12+
if host_machine.system() == 'darwin'
13+
sqlite_dep = dependency('sqlite3', required : true)
14+
else
15+
# no static or it will link to static system
16+
sqlite_dep = dependency('sqlite3', static : false, required : true)
17+
endif
1018

11-
# pkg-config --cflags --libs gl
12-
sqlite_dep = dependency('sqlite3', required: true)
1319

1420
# pkg-config --modversion expat
15-
expat_dep = dependency('expat', required: true)
21+
expat_dep = dependency('expat', required : true)
1622

1723
# pkg-config --cflags --libs zlib
18-
zlib_dep = dependency('zlib', static: false, required: true) # Use shared libz.so instead of libz.a
19-
20-
# sqlite
21-
sqlite_dep = dependency('sqlite3', required: true)
24+
zlib_dep = dependency('zlib', static : false, required : true) # Use shared libz.so instead of libz.a
2225

2326
# clhep: pkg-config
2427
clhep_deps = dependency('clhep',
@@ -56,36 +59,36 @@ cmake = import('cmake')
5659

5760
cmake_opts = cmake.subproject_options()
5861
cmake_opts.add_cmake_defines({
59-
'BUILD_SHARED_LIBS': false, # or false if you want static assimp
60-
'BUILD_STATIC_LIBS': true,
61-
'ZLIB_USE_STATIC_LIBS': false, # prefer shared zlib
62-
'CMAKE_POSITION_INDEPENDENT_CODE': true,
63-
'CMAKE_C_STANDARD': 17, # avoid C23 warnings in bundled zlib if you ever enable it
64-
'CMAKE_POLICY_VERSION_MINIMUM' : '4.0',
65-
})
62+
'BUILD_SHARED_LIBS' : false, # or false if you want static assimp
63+
'BUILD_STATIC_LIBS' : true,
64+
'ZLIB_USE_STATIC_LIBS' : false, # prefer shared zlib
65+
'CMAKE_POSITION_INDEPENDENT_CODE' : true,
66+
'CMAKE_C_STANDARD' : 17, # avoid C23 warnings in bundled zlib if you ever enable it
67+
'CMAKE_POLICY_VERSION_MINIMUM' : '4.0',
68+
})
6669

6770
if host_machine.system() == 'darwin'
6871
# there's a macro collision in Assimp’s bundled zlib on macOS.
6972
# Using system zlib is fine on macos
7073
cmake_opts.add_cmake_defines({
71-
'ASSIMP_BUILD_ZLIB': false,
72-
})
74+
'ASSIMP_BUILD_ZLIB' : false,
75+
})
7376
else
7477
# Ubuntu: zlib is not compiled with fPic on the system. Let Assimp compile it.
7578
cmake_opts.add_cmake_defines({
76-
'ASSIMP_BUILD_ZLIB': true,
77-
})
79+
'ASSIMP_BUILD_ZLIB' : true,
80+
})
7881
endif
7982

8083

8184
cmake_opts.append_compile_args('cpp', '-Wno-shadow')
8285

8386
# TODO: remove temp workaround for _LIBCPP_ENABLE_ASSERTIONS deprecation
8487
cmake_opts.append_compile_args('cpp',
85-
'-fPIC',
86-
'-Wno-shadow',
87-
'-U_LIBCPP_ENABLE_ASSERTIONS',
88-
'-D_LIBCPP_HARDENING_MODE_DEBUG=true',
88+
'-fPIC',
89+
'-Wno-shadow',
90+
'-U_LIBCPP_ENABLE_ASSERTIONS',
91+
'-D_LIBCPP_HARDENING_MODE_DEBUG=true',
8992
)
9093

9194
assimp_proj = cmake.subproject('assimp', options : cmake_opts)

0 commit comments

Comments
 (0)