Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.2.1 #31

Merged
merged 28 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e187f7d
fix #29. add patch number to versioning
Raffaello Apr 27, 2020
46ca459
fix #32
Raffaello Apr 27, 2020
a27b0c0
remove cmake library obj as redundant
Raffaello Apr 28, 2020
246eb2c
simplified cmake
Raffaello Apr 28, 2020
d9552ab
add generated cmake version file #33
Raffaello Apr 28, 2020
be04750
fix #33. typo in var usage
Raffaello Apr 28, 2020
5681488
refacto test, partial fix #30: blinking cursor tests
Raffaello Apr 29, 2020
9cbd5b8
cursor shape snapshot tests. fix #30
Raffaello Apr 29, 2020
22120f6
enforce display cursor when changing status. Fix #26
Raffaello Apr 29, 2020
8ccef29
add noexcept to _busy method #26
Raffaello Apr 29, 2020
db5f727
[WIP] remove mutex and replaced with atomic operations.
Raffaello Apr 29, 2020
3df4637
cleanups #26
Raffaello Apr 29, 2020
1f9d580
more cleanups #26
Raffaello Apr 29, 2020
2cf58c2
fix linux/GCC build
Raffaello Apr 30, 2020
3a73ed3
fix cmake configuration with SDL2-static lib
Raffaello Apr 30, 2020
be5db37
helgrind test and related data races fixes #27
Raffaello Apr 30, 2020
12ca16e
remove atomic array and replace reads/writes with a mutex. Fixes #27
Raffaello Apr 30, 2020
6de8919
rename WITH_* to BUILD_* were approprioate in cmake config. Fixes #35
Raffaello Apr 30, 2020
79f56a9
dependent option TEST_DUMP_SNAPSHOT. Fixes #36
Raffaello Apr 30, 2020
1587146
review examples. Fixes #34
Raffaello May 1, 2020
0e3cb3d
codacy code review
Raffaello May 1, 2020
6d92140
keep unused var declaration
Raffaello May 1, 2020
3ccaa3a
rename _busy method to _setBusy, add isIdle method and test. #26
Raffaello May 1, 2020
5bf1ca5
Update CMakeLists.txt
Raffaello May 1, 2020
ccaa0e1
code rev, fix wrong cmake option logic WITH_SDL2_STATIC
Raffaello May 1, 2020
3c37d37
Apply suggestions from code review
Raffaello May 1, 2020
c54b14e
Apply suggestions from code review
Raffaello May 1, 2020
4162284
Update sdl2-vga-terminal/examples/CMakeLists.txt
Raffaello May 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()

project ("sdl2-vga-terminal" VERSION 0.2 DESCRIPTION "Vga Terminal on SDL2")
project ("sdl2-vga-terminal" VERSION 0.2.1 DESCRIPTION "Vga Terminal on SDL2")

option(WITH_EXAMPLES "build examples" ON)
option(WITH_TEST "build test" ON)
option(TEST_DUMP_SNAPSHOT "running test dumping the expected output instead of verifing it" OFF)
option(WITH_SNAPSHOT "running snapshot test" OFF)
option(BUILD_EXAMPLES "build examples" ON)
include(CTest)
option(BUILD_SNAPSHOT "build snapshot test" OFF)
include(CMakeDependentOption)
CMAKE_DEPENDENT_OPTION(TEST_DUMP_SNAPSHOT "build test to dump the expected output instead of verifing it" OFF
"BUILD_SNAPSHOT" OFF)
#option(TEST_DUMP_SNAPSHOT "build test to dump the expected output instead of verifing it" OFF)
option(WITH_SDL2_STATIC "linking STATIC LIB with SDL2 STATIC" OFF)

enable_testing()
Expand Down
196 changes: 116 additions & 80 deletions sdl2-vga-terminal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,30 @@ find_package(SDL2 CONFIG REQUIRED)

configure_file(version.h.in version.h)

############################ Shared lib ######################################
include(GenerateExportHeader)
add_library(vga-terminal SHARED)
generate_export_header(
vga-terminal
BASE_NAME vga-terminal
EXPORT_MACRO_NAME VGA_TERMINAL_EXPORT
EXPORT_FILE_NAME vga-terminal-export.h
STATIC_DEFINE vga-terminal-lib_BUILD_AS_STATIC
)
install(
TARGETS vga-terminal
EXPORT vga-terminal-config
DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/vga-terminal.h
$<TARGET_FILE_DIR:vga-terminal>/vga-terminal-export.h
DESTINATION include
)
install(FILES
$<TARGET_FILE:SDL2::SDL2>
DESTINATION lib
)
export(TARGETS vga-terminal
FILE ${CMAKE_BINARY_DIR}/vga-terminal.cmake
)
install(EXPORT
vga-terminal-config DESTINATION cmake
)
target_include_directories(vga-terminal PUBLIC
$<BUILD_INTERFACE:$<TARGET_FILE_DIR:vga-terminal>>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_sources(vga-terminal PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/Window.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/VgaTerminal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/vga-terminal.cpp
)
target_link_libraries(vga-terminal SDL2::SDL2)
if(WITH_SDL2_STATIC)
set(LIB_SDL2 SDL2::SDL2)
else()
set(LIB_SDL2 SDL2::SDL2-static)
endif()

if (WIN32)
set(LIB_SDL2main SDL2::SDL2main)
endif()

########################### Static Lib #######################################
add_library(vga-terminal-static STATIC)
set(LIB_NAME vga-terminal-static)
set(LIB_CONF ${LIB_NAME}-config)
set(LIB_VER ${LIB_CONF}-version)
if (MSVC)
# Requires VS 2015 Update 2 at least.
#add_compile_definitions(_ENABLE_ATOMIC_ALIGNMENT_FIX)
endif()
include(CMakePackageConfigHelpers)

add_library(${LIB_NAME} STATIC)
install(
TARGETS vga-terminal-static
EXPORT vga-terminal-static-config
TARGETS ${LIB_NAME}
EXPORT ${LIB_CONF}
DESTINATION static/lib
PUBLIC_HEADER DESTINATION static/include
)
Expand All @@ -66,81 +41,142 @@ install(FILES
DESTINATION static/include
)

export(TARGETS vga-terminal-static
FILE ${CMAKE_BINARY_DIR}/vga-terminal-static.cmake
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${LIB_VER}.cmake
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(TARGETS ${LIB_NAME}
FILE ${CMAKE_BINARY_DIR}/${LIB_NAME}.cmake
NAMESPACE VgaTerminal::
)
install(EXPORT
vga-terminal-static-config DESTINATION static/cmake

install(EXPORT ${LIB_CONF}
DESTINATION static/cmake
NAMESPACE VgaTerminal::
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${LIB_VER}.cmake
DESTINATION static/cmake
)
target_include_directories(vga-terminal-static PUBLIC
$<BUILD_INTERFACE:$<TARGET_FILE_DIR:vga-terminal>>
target_include_directories(${LIB_NAME} PUBLIC
$<BUILD_INTERFACE:$<TARGET_FILE_DIR:${LIB_NAME}>>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:static/include>
)
target_sources(vga-terminal-static PRIVATE
target_sources(${LIB_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/Window.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/VgaTerminal.cpp
)
target_link_libraries(vga-terminal-static SDL2::SDL2)

target_link_libraries(${LIB_NAME} PUBLIC ${LIB_SDL2})
if(NOT (WITH_SDL2_STATIC))
install(FILES
$<TARGET_FILE:SDL2::SDL2>
DESTINATION static/lib
)
endif()

################ Shared code among exe and tests #############################
add_library(vga-terminal-obj OBJECT)
target_sources(vga-terminal-obj PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/VgaTerminal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Window.cpp
)
unset(LIB_NAME)
unset(LIB_CONF)
unset(LIB_VER)

############################ Shared lib ######################################
set(LIB_NAME vga-terminal)
set(LIB_CONF ${LIB_NAME}-config)
set(LIB_VER ${LIB_CONF}-version)

include(GenerateExportHeader)

target_include_directories(vga-terminal-obj PUBLIC
$<BUILD_INTERFACE:$<TARGET_FILE_DIR:vga-terminal>>
${CMAKE_CURRENT_SOURCE_DIR}/src
add_library(${LIB_NAME} SHARED)
add_dependencies(${LIB_NAME} vga-terminal-static)
generate_export_header(
${LIB_NAME}
BASE_NAME ${LIB_NAME}
EXPORT_MACRO_NAME VGA_TERMINAL_EXPORT
EXPORT_FILE_NAME ${LIB_NAME}-export.h
STATIC_DEFINE ${LIB_NAME}-lib_BUILD_AS_STATIC
)
if(WITH_SDL2_STATIC)
target_link_libraries(vga-terminal-obj PUBLIC SDL2::SDL2-static)
else()
install(
TARGETS ${LIB_NAME}
EXPORT ${LIB_CONF}
DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/vga-terminal.h
$<TARGET_FILE_DIR:vga-terminal>/${LIB_NAME}-export.h
DESTINATION include
)
if (NOT (WITH_SDL2_STATIC))
install(FILES
$<TARGET_FILE:SDL2::SDL2>
DESTINATION static/lib
DESTINATION lib
)
target_link_libraries(vga-terminal-obj PUBLIC SDL2::SDL2)
endif()

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${LIB_VER}.cmake
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(TARGETS vga-terminal
FILE ${CMAKE_BINARY_DIR}/${LIB_NAME}.cmake
)
install(EXPORT
${LIB_CONF} DESTINATION cmake
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${LIB_VER}.cmake
DESTINATION cmake
)
target_include_directories(${LIB_NAME} PUBLIC
$<BUILD_INTERFACE:$<TARGET_FILE_DIR:${LIB_NAME}>>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_sources(vga-terminal PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/vga-terminal.cpp
)
target_link_libraries(${LIB_NAME} vga-terminal-static)

unset(LIB_NAME)
unset(LIB_CONF)
unset(LIB_VER)


######################## add compiler options ################################
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# @see https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=vs-2019

target_compile_options(vga-terminal PRIVATE /W4 /WX)
target_compile_options(vga-terminal-static PRIVATE /W4 /WX)
target_compile_options(vga-terminal-obj PRIVATE /W4 /WX)
target_compile_options(vga-terminal PRIVATE /W4 /WX)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(vga-terminal-static PRIVATE -Wall -Wextra -pedantic -fPIC) #-Werror)
target_compile_options(vga-terminal PRIVATE -Wall -Wextra -pedantic) #-Werror)
target_compile_options(vga-terminal-static PRIVATE -Wall -Wextra -pedantic) #-Werror)
target_compile_options(vga-terminal-obj PRIVATE -Wall -Wextra -pedantic) #-Werror)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif()


get_target_property(vga-terminal_copts vga-terminal COMPILE_OPTIONS)
get_target_property(vga-terminal-static_copts vga-terminal-static COMPILE_OPTIONS)
get_target_property(vga-terminal-obj_copts vga-terminal-obj COMPILE_OPTIONS)

message("target compiler options:")
message(STATUS "vga-terminal " ${vga-terminal_copts})
message(STATUS "vga-terminal-static " ${vga-terminal-static_copts})
message(STATUS "vga-terminal-obj " ${vga-terminal-obj_copts})



if (WIN32)
set(LIB_SDL2main SDL2::SDL2main)
endif()
unset(vga-terminal_copts)
unset(vga-terminal-static_copts)

################################ Examples ####################################
if(WITH_EXAMPLES)
if(BUILD_EXAMPLES)
add_subdirectory("examples")
endif()

############################### tests ########################################
if(WITH_TEST)
if(BUILD_TESTING)
add_subdirectory("test")
endif()
7 changes: 4 additions & 3 deletions sdl2-vga-terminal/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cmake_minimum_required (VERSION 3.16)

############################## Main Example ##################################
add_executable (${PROJECT_NAME} "sdl2-vga-terminal.cpp")
add_dependencies(${PROJECT_NAME} vga-terminal-obj)
target_link_libraries(${PROJECT_NAME} vga-terminal-obj ${LIB_SDL2main})
add_dependencies(${PROJECT_NAME} vga-terminal-static)
target_link_libraries(${PROJECT_NAME} vga-terminal-static ${LIB_SDL2main})


################## C example using SO/DLL with lazy loading ##################
Expand All @@ -23,8 +23,9 @@ endif()


################## C example using SO/DLL run-time loading ##################

add_executable (${PROJECT_NAME}-load-so "sdl2-vga-terminal-load-so.c")
target_link_libraries(${PROJECT_NAME}-load-so PUBLIC SDL2::SDL2 ${LIB_SDL2main} ${CMAKE_DL_LIBS})
target_link_libraries(${PROJECT_NAME}-load-so PUBLIC ${LIB_SDL2} ${LIB_SDL2main} ${CMAKE_DL_LIBS})
add_custom_command(TARGET "${PROJECT_NAME}-load-so" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:vga-terminal> $<TARGET_FILE_DIR:${PROJECT_NAME}-load-so>
)
6 changes: 3 additions & 3 deletions sdl2-vga-terminal/examples/sdl2-vga-terminal-load-so.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void win32()
PROCDESTROY ProcAddDestroy = NULL;
PROCWRITEXY ProcAddWriteXY = NULL;
PROCRENDER ProcAddRender = NULL;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
BOOL fFreeResult, fRunTimeLinkSuccess = SDL_FALSE;

printf("loading library: %s\n", soname);

Expand All @@ -61,9 +61,9 @@ void win32()

if (NULL != ProcAddInit && NULL != ProcAddDestroy && NULL != ProcAddWriteXY && NULL != ProcAddRender)
{
fRunTimeLinkSuccess = TRUE;
fRunTimeLinkSuccess = SDL_TRUE;
VGA_Terminal* term = ProcAddInit();
ProcAddWriteXY(term, 0, 0, "test", 10, 0);
ProcAddWriteXY(term, 0, 0, "GREETINGS PROFESSOR FALKENS.", 10, 0);
ProcAddRender(term);
SDL_Delay(1000);
ProcAddDestroy(term);
Expand Down
26 changes: 15 additions & 11 deletions sdl2-vga-terminal/examples/sdl2-vga-terminal-so.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <stdio.h>

#ifdef WIN32
#include <windows.h>
#include <delayimp.h>
#pragma comment(lib, "delayimp")
# include <windows.h>
# include <delayimp.h>
# pragma comment(lib, "delayimp")
#endif


Expand All @@ -23,23 +23,27 @@ int main(int argc, char* args[])

VGA_Terminal* term = VGA_TERMINAL_init();

VGA_TERMINAL_writeXY(term, 0, 0, "TEST test", 10, 0);
VGA_TERMINAL_writeXY(term, 0, 0, "GREETINGS PROFESSOR FALKEN.", 10, 0);
// emulating the main even loop 3 times
// just to show the cursor blinking....
int quit = 3;
int quit = 6;
SDL_Event e;
while (quit--) {
VGA_TERMINAL_render(term);
SDL_Delay(1000);
do {
SDL_WaitEvent(&e);
} while (e.type != SDL_USEREVENT && e.user.type != SDL_USEREVENT);

};

VGA_TERMINAL_destroy(term);

#ifdef WIN32
#ifndef NDEBUG
#define PFIX "d"
#else
#define PFIX ""
#endif
# ifndef NDEBUG
# define PFIX "d"
# else
# define PFIX ""
# endif
int t = __FUnloadDelayLoadedDLL2("vga-terminal" PFIX ".dll");
printf("unloaded? : %d\n", t);
getchar();
Expand Down
Loading