File tree 5 files changed +129
-0
lines changed
5 files changed +129
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ set(CMAKE_CXX_STANDARD 20)
15
15
set (CMAKE_CXX_STANDARD_REQUIRED ON )
16
16
set (CMAKE_CXX_EXTENSIONS OFF )
17
17
set (CMAKE_POSITION_INDEPENDENT_CODE ON )
18
+ set (CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API ON )
18
19
19
20
project (cpp-jam
20
21
VERSION 0.0.1
@@ -40,6 +41,12 @@ find_package(Boost.DI CONFIG REQUIRED)
40
41
find_package (qtils CONFIG REQUIRED)
41
42
find_package (prometheus-cpp CONFIG REQUIRED)
42
43
44
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
45
+ add_compile_options (-fmodules-ts)
46
+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang" )
47
+ add_compile_options (-fmodules)
48
+ endif ()
49
+
43
50
add_library (headers INTERFACE )
44
51
target_include_directories (headers INTERFACE
45
52
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /src_>
Original file line number Diff line number Diff line change @@ -11,3 +11,8 @@ add_library(modules
11
11
target_link_libraries (modules
12
12
qtils::qtils
13
13
)
14
+
15
+ # -------------- Modules --------------
16
+
17
+ # Example module
18
+ add_subdirectory (example)
Original file line number Diff line number Diff line change
1
+ #
2
+ # Copyright Quadrivium LLC
3
+ # All Rights Reserved
4
+ # SPDX-License-Identifier: Apache-2.0
5
+ #
6
+
7
+ # Create a shared module library
8
+ add_library (example_module MODULE # or SHARED
9
+ example.cpp
10
+ )
11
+
12
+ # Set C++ standard
13
+ target_compile_features (example_module PRIVATE
14
+ cxx_std_20
15
+ )
16
+
17
+ # Set include directories
18
+ target_include_directories (example_module PRIVATE
19
+ ${CMAKE_CURRENT_SOURCE_DIR}
20
+ )
21
+
22
+ # Set exported symbols visibility
23
+ set_target_properties (example_module PROPERTIES
24
+ CXX_VISIBILITY_PRESET hidden
25
+ VISIBILITY_INLINES_HIDDEN ON
26
+ )
27
+
28
+ # Ensure exported symbols are explicitly marked
29
+ target_compile_definitions (example_module PRIVATE
30
+ EXAMPLE_EXPORTS
31
+ )
32
+
33
+ # Link with libs
34
+ target_link_libraries (example_module
35
+ qtils::qtils
36
+ )
Original file line number Diff line number Diff line change
1
+ /* *
2
+ * Copyright Quadrivium LLC
3
+ * All Rights Reserved
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ #include " modules/example/example.hpp"
8
+
9
+ MODULE_C_API const uint64_t JAM_MAGIC = jam::modules::JAM_MAGIC;
10
+
11
+ std::shared_ptr<jam::modules::ExampleModule> module_instance;
12
+
13
+ MODULE_C_API const char *loader_id () {
14
+ return " ExampleLoader" ;
15
+ }
16
+
17
+ MODULE_C_API const char *get_module_name_and_version () {
18
+ return " ExampleModule v1.0" ;
19
+ }
20
+
21
+ std::string path_;
22
+ std::unique_ptr<void , decltype(&dlclose)> handle_{};
23
+ std::string loader_id_;
24
+
25
+ MODULE_API std::weak_ptr<jam::modules::ExampleModule> query_module_instance () {
26
+ static bool _ = ({
27
+ module_instance = jam::modules::ExampleModule::create_shared (
28
+ path_, // path
29
+ std::move (handle_), // handler
30
+ loader_id_ // loader
31
+ );
32
+ true ;
33
+ });
34
+ return module_instance;
35
+ }
36
+
37
+ MODULE_API void release_module_instance () {
38
+ module_instance = nullptr ;
39
+ };
Original file line number Diff line number Diff line change
1
+ /* *
2
+ * Copyright Quadrivium LLC
3
+ * All Rights Reserved
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ #pragma once
8
+
9
+ #include < modules/module.hpp>
10
+
11
+ // / @brief Magic word to check if module is JAM module actually
12
+ MODULE_C_API const uint64_t JAM_MAGIC;
13
+
14
+ // / @brief Identifier of suitable module loader
15
+ MODULE_C_API const char *loader_id ();
16
+
17
+ // / @brief Returns module name and version
18
+ // / @return A string containing module name and version
19
+ MODULE_C_API const char *get_module_name_and_version ();
20
+
21
+ namespace jam ::modules {
22
+ class ExampleModule ;
23
+ }
24
+
25
+ MODULE_API std::weak_ptr<jam::modules::ExampleModule> query_module_instance ();
26
+
27
+ MODULE_API void release_module_instance ();
28
+
29
+ class BlockTree ;
30
+ class ExampleModuleLoader ;
31
+
32
+ namespace jam ::modules {
33
+
34
+ class ExampleModule : public Module , Singleton<ExampleModule> { // implement by module
35
+ using Module::Module;
36
+ virtual ~ExampleModule () = default ;
37
+ CREATE_SHARED_METHOD (ExampleModule);
38
+ // virtual void initialize(std::shared_ptr<BlockTree> tree,
39
+ // std::weak_ptr<ExampleModuleLoader> loader) = 0;
40
+ };
41
+
42
+ } // namespace jam::modules
You can’t perform that action at this time.
0 commit comments