Skip to content

Commit

Permalink
C++: Make the system testing feature automatically enable debug info
Browse files Browse the repository at this point in the history
While we haven't settled on the debug info feature and are
merely controlling it via environment variable, setting that can be very hard - especially when using Yocto.

To make life easier, let's do in C++ what we can't easily do for Rust but would like to:

When enabling system testing, automatically emit the necessary debug info, by setting the environment variable when calling the compiler.

This is done by adding SLINT_ENABLED_FEATURES and SLINT_DISABLED_FEATURES properties
on the Slint::Slint target that - as lists - export the list of features and their status.

This way we can compile Slint in once place and safely in the CMake code running in application
scope check about the available features.
  • Loading branch information
tronical committed Jul 4, 2024
1 parent e190d2b commit 964de46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions api/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function(define_cargo_feature cargo_feature description default)
# turn foo-bar into SLINT_FEATURE_FOO_BAR
string(TOUPPER "${cargo_feature}" cmake_option)
string(REPLACE "-" "_" cmake_option "${cmake_option}")
list(APPEND public_cmake_features ${cmake_option})
set(cmake_option "SLINT_FEATURE_${cmake_option}")
option("${cmake_option}" "${description}" ${default})

Expand All @@ -42,13 +43,15 @@ function(define_cargo_feature cargo_feature description default)
endif()

set(features "${features}" PARENT_SCOPE)
set(public_cmake_features "${public_cmake_features}" PARENT_SCOPE)
add_feature_info(${cmake_option} ${cmake_option} ${description})
endfunction()

function(define_cargo_dependent_feature cargo_feature description default depends_condition)
# turn foo-bar into SLINT_FEATURE_FOO_BAR
string(TOUPPER "${cargo_feature}" cmake_option)
string(REPLACE "-" "_" cmake_option "${cmake_option}")
list(APPEND public_cmake_features ${cmake_option})
set(cmake_option "SLINT_FEATURE_${cmake_option}")
cmake_dependent_option("${cmake_option}" "${description}" ${default} ${depends_condition} OFF)

Expand All @@ -57,6 +60,7 @@ function(define_cargo_dependent_feature cargo_feature description default depend
endif()

set(features "${features}" PARENT_SCOPE)
set(public_cmake_features "${public_cmake_features}" PARENT_SCOPE)
add_feature_info(${cmake_option} ${cmake_option} ${description})
endfunction()

Expand Down Expand Up @@ -158,6 +162,19 @@ if (SLINT_BUILD_RUNTIME)
target_compile_options(Slint INTERFACE /bigobj)
endif()

foreach(feature ${public_cmake_features})
set(cmake_option "SLINT_FEATURE_${feature}")
if(${cmake_option})
list(APPEND enabled_features ${feature})
else()
list(APPEND disabled_features ${feature})
endif()
endforeach()
set_property(TARGET Slint APPEND PROPERTY SLINT_ENABLED_FEATURES "${enabled_features}")
set_property(TARGET Slint APPEND PROPERTY SLINT_DISABLED_FEATURES "${disabled_features}")
set_property(TARGET Slint APPEND PROPERTY EXPORT_PROPERTIES "SLINT_ENABLED_FEATURES")
set_property(TARGET Slint APPEND PROPERTY EXPORT_PROPERTIES "SLINT_DISABLED_FEATURES")

if (SLINT_FEATURE_FREESTANDING)
if (ESP_PLATFORM)
list(APPEND features "esp-backtrace/${IDF_TARGET}")
Expand Down
8 changes: 7 additions & 1 deletion api/cpp/cmake/SlintMacro.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ function(SLINT_TARGET_SOURCES target)
# Parse the NAMESPACE argument
cmake_parse_arguments(SLINT_TARGET_SOURCES "" "NAMESPACE" "LIBRARY_PATHS" ${ARGN})

get_target_property(enabled_features Slint::Slint SLINT_ENABLED_FEATURES)
if (("EXPERIMENTAL" IN_LIST enabled_features) AND ("SYSTEM_TESTING" IN_LIST enabled_features))
set(SLINT_COMPILER_ENV ${CMAKE_COMMAND} -E env)
set(SLINT_COMPILER_ENV ${SLINT_COMPILER_ENV} SLINT_EMIT_DEBUG_INFO=1)
endif()

if (DEFINED SLINT_TARGET_SOURCES_NAMESPACE)
# Remove the NAMESPACE argument from the list
list(FIND ARGN "NAMESPACE" _index)
Expand Down Expand Up @@ -41,7 +47,7 @@ function(SLINT_TARGET_SOURCES target)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_SLINT_BASE_NAME}.h
COMMAND Slint::slint-compiler ${_SLINT_ABSOLUTE}
COMMAND ${SLINT_COMPILER_ENV} $<TARGET_FILE:Slint::slint-compiler> ${_SLINT_ABSOLUTE}
-o ${CMAKE_CURRENT_BINARY_DIR}/${_SLINT_BASE_NAME}.h
--depfile ${CMAKE_CURRENT_BINARY_DIR}/${_SLINT_BASE_NAME}.d
--style ${_SLINT_STYLE}
Expand Down

0 comments on commit 964de46

Please sign in to comment.