google / google/prefab

[FR] export_preprocessor_defs and export_includes

Open
#164 9 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
236
Forks
33
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

I would like to define extra CMake variables + modify dependencies in the XXXConfig.cmake files, generated by prefab.

**Describe the solution you'd like**
Allow inclusion of random code in the form of inclusion of a cmake module script.
This requires a modification of the prefab json scheme to list cmake modules.

**Describe alternatives you've considered**
Extending the json scheme to list all properties/variables/... is a non-starter because nothing beats code.

**Additional context**

This missing feature comes up when wanting to make the SDL prefab package behave the same as ordinary SDL desktop packages.

For example:

A generated prefab `SDL3Config.cmake` file looks as follows:
```cmake
if(NOT TARGET SDL3::SDL3)
add_library(SDL3::SDL3 SHARED IMPORTED)
set_target_properties(SDL3::SDL3 PROPERTIES
IMPORTED_LOCATION "/home/maarten/.gradle/caches/transforms-3/289e2cc405c0bca25534e22271176741/transformed/SDL3-3.0.0/prefab/modules/SDL3/libs/android.x86/libSDL3.so"
INTERFACE_INCLUDE_DIRECTORIES "/home/maarten/.gradle/caches/transforms-3/289e2cc405c0bca25534e22271176741/transformed/SDL3-3.0.0/prefab/modules/SDL3/include"
INTERFACE_LINK_LIBRARIES ""
)
endif()

if(NOT TARGET SDL3::SDL3-static)
add_library(SDL3::SDL3-static STATIC IMPORTED)
set_target_properties(SDL3::SDL3-static PROPERTIES
IMPORTED_LOCATION "/home/maarten/.gradle/caches/transforms-3/289e2cc405c0bca25534e22271176741/transformed/SDL3-3.0.0/prefab/modules/SDL3-static/libs/android.x86/libSDL3.a"
INTERFACE_INCLUDE_DIRECTORIES "/home/maarten/.gradle/caches/transforms-3/289e2cc405c0bca25534e22271176741/transformed/SDL3-3.0.0/prefab/modules/SDL3-static/include"
INTERFACE_LINK_LIBRARIES "-ldl;-lGLESv1_CM;-lGLESv2;-llog;-landroid;-lOpenSLES"
)
endif()

if(NOT TARGET SDL3::SDL3test)
add_library(SDL3::SDL3test STATIC IMPORTED)
set_target_properties(SDL3::SDL3test PROPERTIES
IMPORTED_LOCATION "/home/maarten/.gradle/caches/transforms-3/289e2cc405c0bca25534e22271176741/transformed/SDL3-3.0.0/prefab/modules/SDL3test/libs/android.x86/libSDL3_test.a"
INTERFACE_LINK_LIBRARIES ""
)
endif()
```
It would be nice if it would become possible to inject a cmake module (at the bottom of the generated `SDL3Config.cmake`) that modifies these a bit:
```cmake
# Define CMake variables that SDL CMake users expect to exist
get_property(SDL3_INCLUDE_DIR TARGET SDL3::SDL3 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
set(SDL3_INCLUDE_DIRS "${SDL3_INCDIR};${SDL3_INCDIR}/SDL3")
set(SDL3_LIBRARIES SDL3::SDL3)
set(SDL3_STATIC_LIBRARIES SDL3::SDL3-static)
set(SDL3_STATIC_PRIVATE_LIBS)
set(SDL3TEST_LIBRARY SDL3::SDL3test)

# add "include/SDL3" to targets
set_property(TARGET SDL3::SDL3 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}/SDL3")
set_property(TARGET SDL3::SDL3-static APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}/SDL3")
set_property(TARGET SDL3::SDL3test APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}/SDL3")

# set compatible interface properties to avoid mixing shared and static SDL libraries
set_target_properties(SDL3::SDL3 PROPERTIES
COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
INTERFACE_SDL3_SHARED "TRUE"
)
set_target_properties(SDL3::SDL3-static PROPERTIES
COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
INTERFACE_SDL3_SHARED "FALSE"
)
```
This also allows packages to provide cmake functions etc.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.