Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 4.0)

project(DraconicEngine LANGUAGES C CXX)

find_package(Git QUIET)

if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
Expand All @@ -15,10 +17,10 @@ if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
endif()
endif()

project(DraconicEngine LANGUAGES C CXX)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

include(CTest)
include(Compiler)
include(Modules)

add_subdirectory(engine/native)
49 changes: 48 additions & 1 deletion docs/cxxmodules.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,51 @@ void private_foobar()
// foobar() is implemented in here
void foobar()
{ /* */ }
```
```

### How to add modules code in CMake

Our `CMake` project contains scripts that make it easy to add modules to the source tree.

Simply add your library containing the modules to a subdirectory
and use the `add_modules_library` function.

In this example, the library is called `my_modules`.
It exports `module_1` and `module_2`, which in turn use `subcomponent_1`
and `subcomponent_2` modules as well.
Most of these modules have an internal implementation unit as discussed above.
We also provide two unit test programs for the `my_modules` library.
Files that end in `.test.cpp` are automatically added to CTest.

```text
my_modules/
├── subcomponent_1/
| ├── subcomponent_1.cppm
| └── subcomponent_1.cpp
├── subcomponent_2/
| ├── subcomponent_2.cppm
| └── subcomponent_2.cpp
├── module_1.cppm
├── module_1.test.cpp
├── module_2.cppm
├── module_2.cpp
├── module_2.test.cpp
└── CMakeLists.txt
```

The CMakeLists.txt in `my_modules` needs to refer to the modules libraries
in its subdirectories.

```cmake
add_modules_library(subcomponent_1)
add_modules_library(subcomponent_2)
```

From the parent directory of `my_modules`, simply do

```cmake
add_modules_library(my_modules)
target_link_libraries(my_modules PUBLIC subcomponent_1 subcomponent_2)
```

This will add all the exported modules and unit test programs to the build.
3 changes: 0 additions & 3 deletions engine/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
include(Compiler)
include(Modules)

add_subdirectory(thirdparty SYSTEM)

add_modules_library(core SHARED)
Expand Down