22
33Dependencies are located in ` vendor/ ` . The ` vendor/CMakeLists.txt ` uses
44CMake'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 .
66
77## Already included
88
9- The following set of dependencies is already included:
9+ The following set of dependencies are already included:
1010
1111- [ Doctest] ( https://github.com/doctest/doctest ) - Testing framework
1212- [ fmtlib] ( https://fmt.dev/latest/index.html ) - Formatting library
@@ -29,37 +29,35 @@ FetchContent_Declare(
2929 GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
3030 GIT_TAG v1.11.0
3131)
32- add_subdirectory(spdlog)
3332```
3433
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:
3735
3836``` cmake
39- # vendor/spdlog/ CMakeLists.txt
37+ # vendor/CMakeLists.txt
4038
41- message(STATUS "Fetching spdlog ...")
39+ # Settings
4240
4341# Any package build settings here
4442set(SPDLOG_FMT_EXTERNAL "ON")
4543
46- FetchContent_MakeAvailable(spdlog)
44+ # Populate
45+
46+ FetchContent_MakeAvailable(
47+ # Other dependencies ...
48+ spdlog)
4749```
4850
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.
5152
5253## New dependency without CMake support
5354
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
5657done:
5758
5859``` cmake
59- message(STATUS "Fetching imgui ...")
60-
61- # Define build options.
62- set(CMAKE_CXX_STANDARD 20)
60+ # vendor/imgui-setup/CMakeLists.txt
6361
6462# Populate scope with library variables to get access to source and build directories.
6563FetchContent_GetProperties(imgui)
@@ -81,11 +79,28 @@ add_library(imgui
8179# Set include directory based in populated variable `imgui_SOURCE_DIR`.
8280target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
8381
82+ # Define compile options.
83+ target_compile_features(imgui PRIVATE cxx_std_20)
84+
8485# Link external library SDL2, part of the dependencies as well.
8586target_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
86100
87- # Add to main build
88- FetchContent_MakeAvailable(imgui)
101+ FetchContent_MakeAvailable(
102+ # Other dependencies ...
103+ imgui)
89104```
90105
91106## Link dependency
0 commit comments