Skip to content

Commit ccd9c7f

Browse files
committed
Included a minimal json lib in yue compiler tool.
1 parent 03d4fad commit ccd9c7f

5 files changed

Lines changed: 952 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ message(STATUS "Lua: " ${LUA})
5050
message(STATUS "Lua include: " ${LUA_INCLUDE_DIR})
5151
message(STATUS "Lua library: ${LUA_LIBRARIES}")
5252

53-
enable_language(CXX)
53+
enable_language(C CXX)
5454
include_directories(src src/3rdParty ${LUA_INCLUDE_DIR})
5555
add_definitions(-std=c++17 -O3 -fPIC)
5656

@@ -101,6 +101,7 @@ add_executable(yue
101101
src/yuescript/yue_compiler.cpp
102102
src/yuescript/yuescript.cpp
103103
src/yue.cpp
104+
src/3rdParty/colib/ljson.c
104105
)
105106

106107
# Add efsw sources only if not in Termux environment
@@ -180,6 +181,7 @@ if (MSVC)
180181
target_compile_definitions(yue PRIVATE _SCL_SECURE_NO_WARNINGS)
181182
else ()
182183
target_compile_options(yue PRIVATE -Wall -Wno-long-long -fPIC)
184+
set_source_files_properties(src/3rdParty/colib/ljson.c PROPERTIES COMPILE_FLAGS "-std=c99")
183185
endif()
184186

185187
# Add YUE_NO_WATCHER macro for Termux environment

makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
BIN_NAME := yue
44
# Compiler used
55
CXX ?= g++
6+
CC ?= gcc
67
# Extension of source files used in the project
78
SRC_EXT = cpp
89
# Path to the source directory, relative to the makefile
@@ -125,10 +126,13 @@ endif
125126

126127
# Combine compiler and linker flags
127128
release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS)
129+
release: export CFLAGS := $(CFLAGS) $(filter-out -std=c++17,$(COMPILE_FLAGS)) $(RCOMPILE_FLAGS)
128130
release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS)
129131
debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS)
132+
debug: export CFLAGS := $(CFLAGS) $(filter-out -std=c++17,$(COMPILE_FLAGS)) $(DCOMPILE_FLAGS)
130133
debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS)
131134
shared: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) $(TARGET_FLAGS)
135+
shared: export CFLAGS := $(CFLAGS) $(filter-out -std=c++17,$(COMPILE_FLAGS)) $(RCOMPILE_FLAGS) $(TARGET_FLAGS)
132136

133137
# Build and output paths
134138
release: export BUILD_PATH := build/release
@@ -163,9 +167,15 @@ ifeq ($(NO_LUA),true)
163167
SOURCES := $(filter-out $(SRC_PATH)/yuescript/yuescript.cpp, $(SOURCES))
164168
endif
165169

170+
# Add colib ljson.c source file
171+
SOURCES += $(SRC_PATH)/3rdParty/colib/ljson.c
172+
166173
# Set the object file names, with the source directory stripped
167174
# from the path, and the build path prepended in its place
168-
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
175+
CPP_SOURCES = $(filter %.cpp,$(SOURCES))
176+
C_SOURCES = $(filter %.c,$(SOURCES))
177+
OBJECTS = $(CPP_SOURCES:$(SRC_PATH)/%.cpp=$(BUILD_PATH)/%.o)
178+
OBJECTS += $(C_SOURCES:$(SRC_PATH)/%.c=$(BUILD_PATH)/%.o)
169179
# Set the dependency files that will be used to add header dependencies
170180
DEPS = $(OBJECTS:.o=.d)
171181

@@ -469,3 +479,11 @@ $(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
469479
$(CMD_PREFIX)$(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@
470480
@echo -en "\t Compile time: "
471481
@$(END_TIME)
482+
483+
# C source file rules
484+
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.c
485+
@echo "Compiling: $< -> $@"
486+
@$(START_TIME)
487+
$(CMD_PREFIX)$(CC) $(CFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@
488+
@echo -en "\t Compile time: "
489+
@$(END_TIME)

src/3rdParty/colib/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 colin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)