Skip to content

Commit

Permalink
sdl driver: make it compatible with different AtomVM build options
Browse files Browse the repository at this point in the history
AVM_DISABLE_SMP and AVM_DISABLE_TASK_DRIVER change GlobalContext struct memory layout, leading to
a crash when they are not #defined correctly (before including
globalcontext.h).

Add 2 option useful to mirror their configuration also here.

Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Aug 19, 2024
1 parent 58044d9 commit 8eeb2a2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sdl_display/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
cmake_minimum_required (VERSION 3.13)
project (avm_sdl_display)

option(AVM_DISABLE_SMP "Disable SMP." OFF)
option(AVM_DISABLE_TASK_DRIVER "Disable task driver support." OFF)

include_directories(${LIBATOMVM_INCLUDE_PATH})

find_package(SDL)
Expand All @@ -41,6 +44,27 @@ endif()
set(CMAKE_SHARED_LIBRARY_PREFIX "")

add_library(avm_display_port_driver SHARED display.c ufontlib.c)

if (AVM_DISABLE_SMP)
target_compile_definitions(avm_display_port_driver PUBLIC AVM_NO_SMP)
endif()
if (NOT AVM_DISABLE_TASK_DRIVER)
target_compile_definitions(avm_display_port_driver PUBLIC AVM_TASK_DRIVER_ENABLED)
endif()

include(CheckIncludeFile)
CHECK_INCLUDE_FILE(stdatomic.h STDATOMIC_INCLUDE)
include(CheckCSourceCompiles)
check_c_source_compiles("
#include <stdatomic.h>
int main() {
_Static_assert(ATOMIC_POINTER_LOCK_FREE == 2, \"Expected ATOMIC_POINTER_LOCK_FREE to be equal to 2\");
}
" ATOMIC_POINTER_LOCK_FREE_IS_TWO)
if (ATOMIC_POINTER_LOCK_FREE_IS_TWO)
target_compile_definitions(avm_display_port_driver PUBLIC HAVE_ATOMIC)
endif()

target_link_libraries(avm_display_port_driver ${SDL_LIBRARY} ${ZLIB_LIBRARIES})
set_property(TARGET avm_display_port_driver PROPERTY C_STANDARD 11)
set_property(TARGET avm_display_port_driver PROPERTY PREFIX "")
23 changes: 23 additions & 0 deletions sdl_display/README.Md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SDL Display Driver

This display driver can be used for displaying graphics on a PC using SDL library.

## Build
In order to build it, just run `cmake` first and then `make`.

Beware:
- Make sure to set the path to AtomVM headers (`LIBATOMVM_INCLUDE_PATH`) before running cmake,
such as: `cmake -DLIBATOMVM_INCLUDE_PATH=/path-to/AtomVM/src/libAtomVM/ .`.
- Also make sure to build this plugin using same options as AtomVM, that means that
when `AVM_DISABLE_SMP` or `AVM_DISABLE_TASK_DRIVER` have been disabled in AtomVM build, also here
they must be disabled accordingly (their default is on, and in that case no further action is
required).

## Requirements

- zlib
- SDL (v1)

## Run

Once compiled, it must placed in the current working directory.

0 comments on commit 8eeb2a2

Please sign in to comment.