2
2
3
3
Dependencies are located in ` vendor/ ` . The ` vendor/CMakeLists.txt ` uses
4
4
CMake's [ FetchContent] ( https://cmake.org/cmake/help/latest/module/FetchContent.html ) to load dependencies on configure
5
- time. Every dependency also has an associated folder containing a ` CMakeLists.txt ` for configuration.
5
+ time. Some dependencies also have an associated folder containing a ` CMakeLists.txt ` for configuration or setup purpose .
6
6
7
7
## Already included
8
8
9
- The following set of dependencies is already included:
9
+ The following set of dependencies are already included:
10
10
11
11
- [ Doctest] ( https://github.com/doctest/doctest ) - Testing framework
12
12
- [ fmtlib] ( https://fmt.dev/latest/index.html ) - Formatting library
@@ -29,37 +29,35 @@ FetchContent_Declare(
29
29
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
30
30
GIT_TAG v1.11.0
31
31
)
32
- add_subdirectory(spdlog)
33
32
```
34
33
35
- After adding this to the ` vendor ` CMake file, a new ` CMakeLists.txt ` needs to be created in a new folder for the
36
- dependency. Again with the spdlog example:
34
+ Further down the same file is a section for dependency settings. Again using spdlog as an example:
37
35
38
36
``` cmake
39
- # vendor/spdlog/ CMakeLists.txt
37
+ # vendor/CMakeLists.txt
40
38
41
- message(STATUS "Fetching spdlog ...")
39
+ # Settings
42
40
43
41
# Any package build settings here
44
42
set(SPDLOG_FMT_EXTERNAL "ON")
45
43
46
- FetchContent_MakeAvailable(spdlog)
44
+ # Populate
45
+
46
+ FetchContent_MakeAvailable(
47
+ # Other dependencies ...
48
+ spdlog)
47
49
```
48
50
49
- This dependency specific CMake file will contain a message for fetching the library, any package configuration, and a
50
- call to ` FetchContent_MakeAvailable ` with the given name to add them to the build.
51
+ At the end the call to ` FetchContent_MakeAvailable ` gets the new dependency added as well.
51
52
52
53
## New dependency without CMake support
53
54
54
- Adding a package that does not support CMake works almost the same as with support above . The difference is that the new
55
- library needs to be declared . Taking Dear ImGui as an example, that does not support CMake, this is how the setup is
55
+ Adding a package that does not support CMake is also not a problem . The difference is that the new library needs to be
56
+ setup separately . Taking Dear ImGui as an example, that does not support CMake, this is how the setup is
56
57
done:
57
58
58
59
``` cmake
59
- message(STATUS "Fetching imgui ...")
60
-
61
- # Define build options.
62
- set(CMAKE_CXX_STANDARD 20)
60
+ # vendor/imgui-setup/CMakeLists.txt
63
61
64
62
# Populate scope with library variables to get access to source and build directories.
65
63
FetchContent_GetProperties(imgui)
@@ -81,11 +79,28 @@ add_library(imgui
81
79
# Set include directory based in populated variable `imgui_SOURCE_DIR`.
82
80
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
83
81
82
+ # Define compile options.
83
+ target_compile_features(imgui PRIVATE cxx_std_20)
84
+
84
85
# Link external library SDL2, part of the dependencies as well.
85
86
target_link_libraries(imgui PUBLIC SDL2::SDL2)
87
+ ```
88
+
89
+ After setting up the library it needs to be made available in the vendor ` CMakeLists.txt ` :
90
+
91
+ ``` cmake
92
+ # vendor/CMakeLists.txt
93
+
94
+ # Settings
95
+
96
+ # Adding the setup directory
97
+ add_subdirectory(imgui-setup)
98
+
99
+ # Populate
86
100
87
- # Add to main build
88
- FetchContent_MakeAvailable(imgui)
101
+ FetchContent_MakeAvailable(
102
+ # Other dependencies ...
103
+ imgui)
89
104
```
90
105
91
106
## Link dependency
0 commit comments