DiligentEngine icon indicating copy to clipboard operation
DiligentEngine copied to clipboard

adding CMake find_package() support to installed DiligentEngine

Open fdarling opened this issue 6 months ago • 2 comments

I notice that if you can use CMake to build and then "install" DiligentEngine to an installation prefix, but the files it copies do not include any .cmake scripts suitable for having CMake's find_package() find DiligentEngine in a third party CMake project (such as a game project).

Typically files would be placed in subdirectory of the installation prefix such as lib/cmake/DiligentCore/, though there are alternative locations that CMake will search:

https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure

The type of .cmake file(s) that are expected to be in that folder would be of the form DiligentCore-config.cmake:

https://cmake.org/cmake/help/latest/command/find_package.html#config-mode

You could either have the different components be top-level libraries, or be modules to a common library/namespace. For example:

find_package(DiligentEngine REQUIRED Core FX)
# ...
target_link_libraries(myApp PRIVATE
   DiligentEngine::Core
   DiligentEngine::FX
)

Rather than:

find_package(DiligentCore)
find_package(DiligentFX)
# ...
target_link_libraries(myApp PRIVATE
   DiligentCore
   DiligentFX
)

I see that currently you support having people pull in DiligentEngine by using add_subdirectory() on something like DiligentCore (possibly a submodule folder) and then linking with things like Diligent-GraphicsEngineOpenGL-shared. What I am hoping for is find_package(DiligentCore) or find_package(Diligent::Core) and then linking similarly to before (though ideally with namespaces / components).

CMake also has a feature where by simply linking with a library, you pull in the include paths that library advertises with "INTERFACE_INCLUDE_DIRECTORIES". I don't fully know how to write CMake files to set this up, but I have used libraries that have done so!

Let me know if this makes sense, and if so, I am willing to help make it happen! I know CMake pretty well, and I have friends that know more than me :smile:

fdarling avatar Aug 30 '25 02:08 fdarling

This sounds like a really good idea - currently integrating with the Engine from the installation is not very convenient. Wrapping this in packages would simplify this dramatically.

Thank you for offering your help with this, this is a really good improvement.

find_package(DiligentEngine REQUIRED Core FX) looks good to me as long as this will work for individual modules (e.g. if there is Core only).

The main question I have so far is to how to make this robust. Will config files need to be written and updated manually or can this be automated somehow? For example what happens if a new project is added or an existing project gets moved or renamed? Also, how can this be tested? Maybe, after installation is run on CI, a test project can be configured that uses the config files.

TheMostDiligent avatar Sep 01 '25 22:09 TheMostDiligent

In general, the config file is generated from XxConfig.cmake.in. But how to handle shared and static library, export ENGINE_DLL definition as cmake target public compile_definition, or put inside build_config.h header file?

WangHoi avatar Dec 05 '25 16:12 WangHoi