diff --git a/CMakeLists.txt b/CMakeLists.txt index c1ad8a551..cf7365228 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,19 @@ else() include(${CMAKE_CURRENT_LIST_DIR}/env_support/cmake/custom.cmake) endif() +#[[ + unfortunately CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS does not work for global data. + for global data we still need decl specs. + Check out the docs to learn more about the limitations of CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS + https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html#prop_tgt:WINDOWS_EXPORT_ALL_SYMBOLS + + For all compiled sources within the library (i.e. basically all lvgl files) we need to use dllexport. + For all compiled sources from outside the library (i.e. files which include lvgl headers) we need to use dllimport. + We can do this by using CMakes INTERFACE and PRIVATE keyword. + ]] if (MSVC) - if (BUILD_SHARED_LIBS) - target_compile_definitions(lvgl PUBLIC LV_ATTRIBUTE_EXTERN_DATA=__declspec\(dllimport\)) - else() - target_compile_definitions(lvgl PUBLIC LV_ATTRIBUTE_EXTERN_DATA=__declspec\(dllexport\)) - endif() + target_compile_definitions(lvgl + INTERFACE LV_ATTRIBUTE_EXTERN_DATA=__declspec\(dllimport\) + PRIVATE LV_ATTRIBUTE_EXTERN_DATA=__declspec\(dllexport\) + ) endif() \ No newline at end of file diff --git a/src/core/lv_global.h b/src/core/lv_global.h index 93411c176..2b36a10e5 100644 --- a/src/core/lv_global.h +++ b/src/core/lv_global.h @@ -205,7 +205,7 @@ typedef struct _lv_global_t { #endif #define LV_GLOBAL_DEFAULT() LV_GLOBAL_CUSTOM() #else -extern lv_global_t lv_global; +LV_ATTRIBUTE_EXTERN_DATA extern lv_global_t lv_global; #define LV_GLOBAL_DEFAULT() (&lv_global) #endif diff --git a/src/font/lv_font.h b/src/font/lv_font.h index d5464dab9..610048d49 100644 --- a/src/font/lv_font.h +++ b/src/font/lv_font.h @@ -162,7 +162,7 @@ void lv_font_set_kerning(lv_font_t * font, lv_font_kerning_t kerning); * MACROS **********************/ -#define LV_FONT_DECLARE(font_name) extern const lv_font_t font_name; +#define LV_FONT_DECLARE(font_name) LV_ATTRIBUTE_EXTERN_DATA extern const lv_font_t font_name; #if LV_FONT_MONTSERRAT_8 LV_FONT_DECLARE(lv_font_montserrat_8) diff --git a/src/misc/lv_color.h b/src/misc/lv_color.h index 0d24dc7ec..5170e4696 100644 --- a/src/misc/lv_color.h +++ b/src/misc/lv_color.h @@ -445,7 +445,7 @@ static inline void lv_color16_premultiply(lv_color16_t * c, lv_opa_t a) #include "lv_palette.h" #include "lv_color_op.h" -extern const lv_color_filter_dsc_t lv_color_filter_shade; +LV_ATTRIBUTE_EXTERN_DATA extern const lv_color_filter_dsc_t lv_color_filter_shade; #ifdef __cplusplus } /*extern "C"*/