widberg / bgfx.cmake

https://github.com/bkaradzic/bgfx.cmake. Independently maintained CMake build scripts for bgfx. Released under public domain.
https://github.com/bkaradzic/bgfx.cmake
Creative Commons Zero v1.0 Universal
286 stars 252 forks source link

Add EXPORT to install targets #59

Closed bwrsandman closed 4 years ago

bwrsandman commented 4 years ago

Add EXPORT bgfx-config with bgfx:: namespace to auto generate a bgfx-config.cmake file at install time (INSTALL on visual studio or make install on MakeFile projects). The file is for use with find_package and installs itself in the lib directory under cmake/bgfx/bgfx-config.cmake. If installed on a linux system, find_package will find this config file without any configuration. This config file allows dependent projects to use commands such as linking with bgfx:

find_package(bgfx REQUIRED COMPONENTS bgfx)
target_link_libraries(dependent PUBLIC bgfx::bgfx)

or compiling a shader at build time:

find_package(bgfx REQUIRED COMPONENTS shaderc)
add_custom_command(OUTPUT compiled_shader.glsl
                   COMMAND
                       bgfx::shaderc
                       -f vs_input_shader.sc
                       -o compiled_shader.glsl
                       --type vertex)

Since the library is static, the 3rd parties need to also be part of the export group. Paths marked with BUILD_INTERFACE are done so to be ignored by the install target which will not need them. In some cases they are accompanied by INSTALL_INTERFACE, this is to set a different include path at installation. e.g. /usr/include over /home/.../project_path/include