Skip to content

Commit

Permalink
added general 'SyntaxConfig' export symbol for the shared libs
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed May 1, 2024
1 parent 1933748 commit 6fb7c8e
Show file tree
Hide file tree
Showing 26 changed files with 140 additions and 80 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ message("VERSION_HASH: ${VERSION_HASH}")

configure_file("${PROJECT_SOURCE_DIR}/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h")

set(BUILD_DEMO_CARTS_DEFAULT OFF)

if(ANDROID OR EMSCRIPTEN OR N3DS OR RPI)
set(BUILD_LIBRETRO_DEFAULT OFF)
set(BUILD_DEMO_CARTS_DEFAULT OFF)
set(BUILD_PLAYER_DEFAULT OFF)
else()
set(BUILD_LIBRETRO_DEFAULT ON)
set(BUILD_DEMO_CARTS_DEFAULT ON)
set(BUILD_PLAYER_DEFAULT ON)
endif()

Expand Down Expand Up @@ -53,8 +53,11 @@ if(NOT BUILD_SDL)
set(BUILD_SDLGPU OFF)
endif()

add_library(runtime INTERFACE)

if(BUILD_STATIC)
set(TIC_RUNTIME STATIC)
target_compile_definitions(runtime INTERFACE TIC_RUNTIME_STATIC)
else()
set(TIC_RUNTIME SHARED)
endif()
Expand All @@ -70,7 +73,6 @@ endif()

if (BAREMETALPI)
set(BUILD_SDL OFF)
set(BUILD_DEMO_CARTS OFF)
endif()

if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID AND NOT N3DS)
Expand Down Expand Up @@ -129,6 +131,8 @@ include(cmake/zip.cmake)
include(cmake/tools.cmake)

include(cmake/lua.cmake)
include(cmake/moon.cmake)
include(cmake/fennel.cmake)
include(cmake/wren.cmake)
include(cmake/mruby.cmake)
include(cmake/wasm.cmake)
Expand Down
12 changes: 10 additions & 2 deletions cmake/core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ macro(MACRO_CORE SCRIPT DEFINE BUILD_DEPRECATED)

if(BUILD_STATIC)
if(BUILD_WITH_LUA)
target_link_libraries(tic80core${SCRIPT} PUBLIC lua)
target_link_libraries(tic80core${SCRIPT} PRIVATE lua)
endif()

if(BUILD_WITH_MOON)
target_link_libraries(tic80core${SCRIPT} PRIVATE moon)
endif()

if(BUILD_WITH_FENNEL)
target_link_libraries(tic80core${SCRIPT} PRIVATE fennel)
endif()

if(BUILD_WITH_JS)
Expand Down Expand Up @@ -77,7 +85,7 @@ macro(MACRO_CORE SCRIPT DEFINE BUILD_DEPRECATED)
target_link_libraries(tic80core${SCRIPT} PRIVATE wasm)
endif()

target_compile_definitions(tic80core${SCRIPT} PUBLIC TIC_RUNTIME_STATIC)
target_link_libraries(tic80core${SCRIPT} PRIVATE runtime)

elseif(WIN32)
target_include_directories(tic80core${SCRIPT} PRIVATE ${THIRDPARTY_DIR}/dlfcn/src)
Expand Down
26 changes: 26 additions & 0 deletions cmake/fennel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
################################
# Fennel
################################

if(BUILD_WITH_FENNEL)

add_library(fennel ${TIC_RUNTIME} ${CMAKE_SOURCE_DIR}/src/api/fennel.c)

if(NOT BUILD_STATIC)
set_target_properties(fennel PROPERTIES PREFIX "")
endif()

target_link_libraries(fennel PRIVATE lua runtime)
target_include_directories(fennel
PRIVATE
${THIRDPARTY_DIR}/fennel
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src
)
target_compile_definitions(fennel INTERFACE TIC_BUILD_WITH_FENNEL)

if(BUILD_DEMO_CARTS)
list(APPEND DEMO_CARTS ${DEMO_CARTS_IN}/fenneldemo.fnl)
endif()

endif()
2 changes: 2 additions & 0 deletions cmake/janet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ if(BUILD_WITH_JANET)
set_target_properties(janet PROPERTIES PREFIX "")
endif()

target_link_libraries(janet PRIVATE runtime)

target_include_directories(janet
PRIVATE
${THIRDPARTY_DIR}/janet/src/include
Expand Down
48 changes: 2 additions & 46 deletions cmake/lua.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,14 @@ if(BUILD_WITH_LUA)
list(APPEND LUA_SRC ${CMAKE_SOURCE_DIR}/src/api/lua.c)
list(APPEND LUA_SRC ${CMAKE_SOURCE_DIR}/src/api/parse_note.c)

if(BUILD_WITH_MOON)
list(APPEND LUA_SRC ${CMAKE_SOURCE_DIR}/src/api/moonscript.c)
endif()

if(BUILD_WITH_FENNEL)
list(APPEND LUA_SRC ${CMAKE_SOURCE_DIR}/src/api/fennel.c)
endif()

add_library(lua ${TIC_RUNTIME} ${LUA_SRC})

if(NOT BUILD_STATIC)
set_target_properties(lua PROPERTIES PREFIX "")
endif()

target_link_libraries(lua PRIVATE runtime)

target_compile_definitions(lua PRIVATE LUA_COMPAT_5_2)
target_include_directories(lua
PUBLIC ${THIRDPARTY_DIR}/lua
Expand All @@ -89,16 +83,6 @@ if(BUILD_WITH_LUA)

target_compile_definitions(lua INTERFACE TIC_BUILD_WITH_LUA)

if(BUILD_WITH_MOON)
target_include_directories(lua PRIVATE ${THIRDPARTY_DIR}/moonscript)
target_compile_definitions(lua INTERFACE TIC_BUILD_WITH_MOON)
endif()

if(BUILD_WITH_FENNEL)
target_include_directories(lua PRIVATE ${THIRDPARTY_DIR}/fennel)
target_compile_definitions(lua INTERFACE TIC_BUILD_WITH_FENNEL)
endif()

if(BUILD_DEMO_CARTS)
list(APPEND DEMO_CARTS ${CMAKE_SOURCE_DIR}/config.lua)

Expand All @@ -116,33 +100,5 @@ if(BUILD_WITH_LUA)
list(APPEND DEMO_CARTS ${DEMO_CARTS_IN}/luademo.lua)
list(APPEND DEMO_CARTS ${DEMO_CARTS_IN}/bunny/luamark.lua)

if(BUILD_WITH_MOON)
list(APPEND DEMO_CARTS ${DEMO_CARTS_IN}/moondemo.moon)
list(APPEND DEMO_CARTS ${DEMO_CARTS_IN}/bunny/moonmark.moon)
endif()

if(BUILD_WITH_FENNEL)
list(APPEND DEMO_CARTS ${DEMO_CARTS_IN}/fenneldemo.fnl)
endif()
endif()
endif()

################################
# LPEG
################################

if(BUILD_WITH_MOON)

set(LPEG_DIR ${THIRDPARTY_DIR}/lpeg)
set(LPEG_SRC
${LPEG_DIR}/lpcap.c
${LPEG_DIR}/lpcode.c
${LPEG_DIR}/lpprint.c
${LPEG_DIR}/lptree.c
${LPEG_DIR}/lpvm.c
)

add_library(lpeg STATIC ${LPEG_SRC})
target_include_directories(lpeg PRIVATE ${LUA_DIR})
target_link_libraries(lua PRIVATE lpeg)
endif()
40 changes: 40 additions & 0 deletions cmake/moon.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
################################
# MoonScript
################################

if(BUILD_WITH_MOON)

set(LPEG_DIR ${THIRDPARTY_DIR}/lpeg)
set(LPEG_SRC
${LPEG_DIR}/lpcap.c
${LPEG_DIR}/lpcode.c
${LPEG_DIR}/lpprint.c
${LPEG_DIR}/lptree.c
${LPEG_DIR}/lpvm.c
)

add_library(lpeg STATIC ${LPEG_SRC})
target_include_directories(lpeg PRIVATE ${LUA_DIR})

add_library(moon ${TIC_RUNTIME} ${CMAKE_SOURCE_DIR}/src/api/moonscript.c)

if(NOT BUILD_STATIC)
set_target_properties(moon PROPERTIES PREFIX "")
endif()

target_link_libraries(moon PRIVATE lpeg lua runtime)

target_include_directories(moon
PRIVATE
${THIRDPARTY_DIR}/moonscript
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src
)

target_compile_definitions(moon INTERFACE TIC_BUILD_WITH_MOON)

if(BUILD_DEMO_CARTS)
list(APPEND DEMO_CARTS ${DEMO_CARTS_IN}/moondemo.moon)
list(APPEND DEMO_CARTS ${DEMO_CARTS_IN}/bunny/moonmark.moon)
endif()
endif()
2 changes: 2 additions & 0 deletions cmake/mruby.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ if(BUILD_WITH_MRUBY)
set_target_properties(ruby PROPERTIES PREFIX "")
endif()

target_link_libraries(ruby PRIVATE runtime)

if(CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_UC)
endif()
Expand Down
2 changes: 2 additions & 0 deletions cmake/pocketpy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ if(BUILD_WITH_PYTHON)
set_target_properties(python PROPERTIES PREFIX "")
endif()

target_link_libraries(python PRIVATE runtime)

target_include_directories(python
PRIVATE
${THIRDPARTY_DIR}/pocketpy/include
Expand Down
2 changes: 2 additions & 0 deletions cmake/quickjs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ if(BUILD_WITH_JS)
set_target_properties(js PROPERTIES PREFIX "")
endif()

target_link_libraries(js PRIVATE runtime)

target_link_libraries(js PRIVATE quickjs)
target_include_directories(js
PRIVATE
Expand Down
2 changes: 2 additions & 0 deletions cmake/scheme.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ if(BUILD_WITH_SCHEME)
set_target_properties(scheme PROPERTIES PREFIX "")
endif()

target_link_libraries(scheme PRIVATE runtime)

set_target_properties(scheme PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(scheme
PUBLIC ${SCHEME_DIR}
Expand Down
2 changes: 2 additions & 0 deletions cmake/squirrel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ if(BUILD_WITH_SQUIRREL)
set_target_properties(squirrel PROPERTIES PREFIX "")
endif()

target_link_libraries(squirrel PRIVATE runtime)

set_target_properties(squirrel PROPERTIES LINKER_LANGUAGE CXX)

target_include_directories(squirrel
Expand Down
2 changes: 2 additions & 0 deletions cmake/wasm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ if(BUILD_WITH_WASM)
set_target_properties(wasm PROPERTIES PREFIX "")
endif()

target_link_libraries(wasm PRIVATE runtime)

target_include_directories(wasm
PUBLIC ${WASM_DIR}
PRIVATE
Expand Down
4 changes: 3 additions & 1 deletion cmake/wren.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ if(BUILD_WITH_WREN)
if(NOT BUILD_STATIC)
set_target_properties(wren PROPERTIES PREFIX "")
endif()


target_link_libraries(wren PRIVATE runtime)

target_include_directories(wren
PRIVATE
${CMAKE_SOURCE_DIR}/include
Expand Down
8 changes: 8 additions & 0 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,11 @@ const tic_script_config* tic_core_script_config(tic_mem* memory);
#define VBANK(tic, bank) \
bool MACROVAR(_bank_) = tic_api_vbank(tic, bank); \
SCOPE(tic_api_vbank(tic, MACROVAR(_bank_)))

#define SYNTAX_CONFIG SyntaxConfig

#if defined(TIC_RUNTIME_STATIC)
#define EXPORT_CONFIG(X) CONCAT(X, SYNTAX_CONFIG)
#else
#define EXPORT_CONFIG(X) SYNTAX_CONFIG
#endif
2 changes: 1 addition & 1 deletion src/api/fennel.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static const u8 DemoRom[] =
#include "../build/assets/fenneldemo.tic.dat"
};

const tic_script_config FennelSyntaxConfig =
const tic_script_config EXPORT_CONFIG(Fennel) =
{
.id = 14,
.name = "fennel",
Expand Down
2 changes: 1 addition & 1 deletion src/api/janet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ static const u8 MarkRom[] =
#include "../build/assets/janetmark.tic.dat"
};

JANET_API const tic_script_config JanetSyntaxConfig =
JANET_API const tic_script_config EXPORT_CONFIG(Janet) =
{
.id = 18,
.name = "janet",
Expand Down
2 changes: 1 addition & 1 deletion src/api/js.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ static const u8 MarkRom[] =
#include "../build/assets/jsmark.tic.dat"
};

const tic_script_config JsSyntaxConfig =
const tic_script_config EXPORT_CONFIG(Js) =
{
.id = 12,
.name = "js",
Expand Down
2 changes: 1 addition & 1 deletion src/api/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ static const u8 DemoCar[] =
#include "../build/assets/car.tic.dat"
};

const tic_script_config LuaSyntaxConfig =
const tic_script_config EXPORT_CONFIG(Lua) =
{
.id = 10,
.name = "lua",
Expand Down
2 changes: 1 addition & 1 deletion src/api/moonscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static const u8 MarkRom[] =
#include "../build/assets/moonmark.tic.dat"
};

const tic_script_config MoonSyntaxConfig =
const tic_script_config EXPORT_CONFIG(Moon) =
{
.id = 13,
.name = "moon",
Expand Down
2 changes: 1 addition & 1 deletion src/api/mruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ static const u8 MarkRom[] =
#include "../build/assets/rubymark.tic.dat"
};

const tic_script_config RubySyntaxConfig =
const tic_script_config EXPORT_CONFIG(Ruby) =
{
.id = 11,
.name = "ruby",
Expand Down
2 changes: 1 addition & 1 deletion src/api/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ static const u8 MarkRom[] =
#include "../build/assets/pythonmark.tic.dat"
};

PK_EXPORT const tic_script_config PythonSyntaxConfig =
PK_EXPORT const tic_script_config EXPORT_CONFIG(Python) =
{
.id = 20,
.name = "python",
Expand Down
2 changes: 1 addition & 1 deletion src/api/scheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ static const u8 MarkRom[] =
#include "../build/assets/schememark.tic.dat"
};

const tic_script_config SchemeSyntaxConfig =
const tic_script_config EXPORT_CONFIG(Scheme) =
{
.id = 19,
.name = "scheme",
Expand Down
2 changes: 1 addition & 1 deletion src/api/squirrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ static const u8 MarkRom[] =
#include "../build/assets/squirrelmark.tic.dat"
};

const tic_script_config SquirrelSyntaxConfig =
const tic_script_config EXPORT_CONFIG(Squirrel) =
{
.id = 15,
.name = "squirrel",
Expand Down
2 changes: 1 addition & 1 deletion src/api/wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ static const u8 MarkRom[] =
#include "../build/assets/wasmmark.tic.dat"
};

const tic_script_config WasmSyntaxConfig =
const tic_script_config EXPORT_CONFIG(Wasm) =
{
.id = 17,
.name = "wasm",
Expand Down
2 changes: 1 addition & 1 deletion src/api/wren.c
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ static const u8 MarkRom[] =
#include "../build/assets/wrenmark.tic.dat"
};

const tic_script_config WrenSyntaxConfig =
const tic_script_config EXPORT_CONFIG(Wren) =
{
.id = 16,
.name = "wren",
Expand Down

0 comments on commit 6fb7c8e

Please sign in to comment.