Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
105 changes: 20 additions & 85 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
PROJECT(qjson)

set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII" )

# Force cmake 2.8.8 in order to have a decent support of Qt5
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
CMAKE_POLICY(SET CMP0003 NEW)

# Do not link against qtmain on Windows
if(POLICY CMP0020)
cmake_policy(SET CMP0020 OLD)
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" )
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" )
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" )

set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR})

add_compile_definitions("QT_NO_CAST_FROM_ASCII" "DQT_NO_CAST_TO_ASCII")

IF("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*")
ADD_DEFINITIONS("-DQT_NO_DEBUG_OUTPUT")
ENDIF("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*")
add_compile_definitions("QT_NO_DEBUG_OUTPUT")
ENDIF()

# Ability to disable verbose debug output
IF(QJSON_VERBOSE_DEBUG_OUTPUT)
ADD_DEFINITIONS("-DQJSON_VERBOSE_DEBUG_OUTPUT")
endif(QJSON_VERBOSE_DEBUG_OUTPUT)
add_compile_definitions("QJSON_VERBOSE_DEBUG_OUTPUT")
endif()

# On Windows debug library should have 'd' postfix.
IF (WIN32)
SET(CMAKE_DEBUG_POSTFIX "d")
elseif (APPLE)
set(CMAKE_DEBUG_POSTFIX "_debug")
endif (WIN32)
endif ()

option(QJSON_BUILD_TESTS "Build tests" OFF)

Expand All @@ -43,81 +37,22 @@ OPTION(OSX_FRAMEWORK "Build a Mac OS X Framework")
# Allow to use shared Qt when compiling static version of QJSON.
# Has effect only when BUILD_SHARED_LIBS is OFF.
option(LINK_SHARED_QT "Force to link with shared Qt" OFF)
option(QT4_BUILD "Force building with Qt4 even if Qt5 is found" OFF)

SET(FRAMEWORK_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/Library/Frameworks"
CACHE PATH "Where to place qjson.framework if OSX_FRAMEWORK is selected")

if(QT_QMAKE_EXECUTABLE AND EXISTS ${QT_QMAKE_EXECUTABLE})
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
endif()

if(QT_VERSION)
if(QT_VERSION MATCHES "^4\\.")
set(QT4_BUILD_DEFAULT ON)
else()
set(QT4_BUILD_DEFAULT OFF)
endif()
else()
set(QT4_BUILD_DEFAULT ON)
endif()

set(QT4_BUILD ${QT4_BUILD_DEFAULT})

IF (NOT QT4_BUILD)
FIND_PACKAGE( Qt5 COMPONENTS Widgets REQUIRED QUIET )
ENDIF()
find_package(Qt6 CONFIG REQUIRED COMPONENTS Core)

IF (Qt5Core_FOUND)
MESSAGE ("Qt5 found")

INCLUDE_DIRECTORIES(${Qt5Core_INCLUDE_DIRS})
ADD_DEFINITIONS(${Qt5Core_DEFINITIONS})
SET(PC_Requires "Qt5Core")
set(QJSON_SUFFIX "-qt5")
# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_USE_QSTRINGBUILDER" )
MESSAGE ("Enable QStringBuilder")
ELSE()
MESSAGE ("Qt5 not found, searching for Qt4")

# Don't use absolute path in qjson-targets-*.cmake
# (This will have no effect with CMake < 2.8)
# Workaround for no stdlib.h error. In this case it must be used with
# -DQT_INCLUDE_DIRS_NO_SYSTEM=ON. So cmake must be invoked with
# -DQT_USE_IMPORTED_TARGETS=OFF -DQT_INCLUDE_DIRS_NO_SYSTEM=ON
# See https://bugzilla.redhat.com/show_bug.cgi?id=1470809 for details
OPTION(QT_USE_IMPORTED_TARGETS "Use imported targets" ON)

# Find Qt4
FIND_PACKAGE( Qt4 4.5 REQUIRED QtCore)
# QStringBuilder is supported since Qt 4.8 for both QString and QByteArray
IF (NOT (${QT_VERSION_MINOR} STRLESS "8"))
MESSAGE ("Enable QStringBuilder")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_USE_QSTRINGBUILDER" )
ELSE()
MESSAGE ("Disable QStringBuilder")
ENDIF()

# Ensure to be linked with static Qt library on Widnows
IF(WIN32 AND NOT BUILD_SHARED_LIBS AND NOT LINK_SHARED_QT)
STRING(REPLACE "-DQT_DLL" "" QT_DEFINITIONS "${QT_DEFINITIONS}")
SET(QT_DEFINITIONS ${QT_DEFINITIONS} "-DQT_NODLL")
ENDIF()

# Include the cmake file needed to use qt4
INCLUDE( ${QT_USE_FILE} )
SET(PC_Requires "QtCore")
ENDIF()

IF (NOT WIN32)
SET( QT_DONT_USE_QTGUI TRUE )
ENDIF()
set(QJSON_SUFFIX "-qt6")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
add_compile_definitions("QT_USE_QSTRINGBUILDER")
MESSAGE("Enable QStringBuilder")

# IF (NOT WIN32)
# SET( QT_DONT_USE_QTGUI TRUE )
# ENDIF()

#add extra search paths for libraries and includes
SET (LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
Expand All @@ -126,7 +61,7 @@ SET (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The direc
SET (CMAKECONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${CMAKE_PROJECT_NAME}${QJSON_SUFFIX}" CACHE PATH "Directory where to install QJSONConfig.cmake")

set(QJSON_LIB_MAJOR_VERSION "0")
set(QJSON_LIB_MINOR_VERSION "9")
set(QJSON_LIB_MINOR_VERSION "10")
set(QJSON_LIB_PATCH_VERSION "0")

set(QJSON_LIB_VERSION_STRING "${QJSON_LIB_MAJOR_VERSION}.${QJSON_LIB_MINOR_VERSION}.${QJSON_LIB_PATCH_VERSION}")
Expand Down
30 changes: 12 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,22 @@ set(qjson_MOC_HDRS
serializerrunnable.h
)

IF (NOT Qt5Core_FOUND)
qt4_wrap_cpp(qjson_MOC_SRCS ${qjson_MOC_HDRS})
ENDIF()

set (qjson_SRCS parser.cpp qobjecthelper.cpp json_scanner.cpp json_parser.cc parserrunnable.cpp serializer.cpp serializerrunnable.cpp)
set (qjson_HEADERS parser.h parserrunnable.h qobjecthelper.h serializer.h serializerrunnable.h qjson_export.h)

# Required to use the intree copy of FlexLexer.h
INCLUDE_DIRECTORIES(.)
# INCLUDE_DIRECTORIES(.)

# Special hack to fix scanner test compilation on Windows
# JsonScanner class is not for export. So need to make static
# lib what can be compiled against scanner test.
if(WIN32 AND QJSON_BUILD_TESTS AND BUILD_SHARED_LIBS)
add_library(qjson_scanner STATIC json_scanner.cpp)
target_link_libraries(qjson_scanner Qt::Core)
endif()

add_library (qjson${QJSON_SUFFIX} ${qjson_SRCS} ${qjson_MOC_SRCS} ${qjson_HEADERS})
IF (Qt5Core_FOUND)
target_link_libraries( qjson${QJSON_SUFFIX} ${Qt5Core_LIBRARIES})
ELSE()
target_link_libraries( qjson${QJSON_SUFFIX} ${QT_LIBRARIES})
ENDIF()
target_link_libraries(qjson${QJSON_SUFFIX} Qt::Core)

if(NOT ANDROID)
set_target_properties(qjson${QJSON_SUFFIX} PROPERTIES
Expand Down Expand Up @@ -65,12 +58,13 @@ INSTALL(TARGETS qjson${QJSON_SUFFIX} EXPORT qjson-export
PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}/qjson${QJSON_SUFFIX}
)

if(MSVC)
get_target_property(LOCATION qjson LOCATION_DEBUG)
string(REGEX REPLACE "\\.[^.]*$" ".pdb" LOCATION "${LOCATION}")
install(FILES ${LOCATION} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin CONFIGURATIONS Debug)
# TODO double check
# if(MSVC)
# get_target_property(LOCATION qjson${QJSON_SUFFIX} LOCATION_DEBUG)
# string(REGEX REPLACE "\\.[^.]*$" ".pdb" LOCATION "${LOCATION}")
# install(FILES ${LOCATION} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin CONFIGURATIONS Debug)

get_target_property(LOCATION qjson LOCATION_RELWITHDEBINFO)
string(REGEX REPLACE "\\.[^.]*$" ".pdb" LOCATION "${LOCATION}")
install(FILES ${LOCATION} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin CONFIGURATIONS RelWithDebInfo)
endif(MSVC)
# get_target_property(LOCATION qjson${QJSON_SUFFIX} LOCATION_RELWITHDEBINFO)
# string(REGEX REPLACE "\\.[^.]*$" ".pdb" LOCATION "${LOCATION}")
# install(FILES ${LOCATION} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin CONFIGURATIONS RelWithDebInfo)
# endif(MSVC)
4 changes: 2 additions & 2 deletions src/json_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace yy {
{
if (*yystr == '"')
{
std::string yyr;
std::string yyr = "";
char const *yyp = yystr;

for (;;)
Expand Down Expand Up @@ -495,7 +495,7 @@ namespace yy {
{
QVariantMap* pair = new QVariantMap();
pair->insert((yysemantic_stack_[(3) - (1)]).toString(), (yysemantic_stack_[(3) - (3)]));
(yyval).setValue<QVariantMap* >(pair);
(yyval).setValue(pair);
}
break;

Expand Down
2 changes: 1 addition & 1 deletion src/json_parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object: CURLY_BRACKET_OPEN CURLY_BRACKET_CLOSE {
members: STRING COLON value {
QVariantMap* pair = new QVariantMap();
pair->insert($1.toString(), $3);
$$.setValue<QVariantMap* >(pair);
$$.setValue(pair);
}
| members COMMA STRING COLON value {
$$.value<QVariantMap*>()->insert($3.toString(), $5);
Expand Down
1 change: 0 additions & 1 deletion src/json_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <ctype.h>

#include <QtCore/QDebug>
#include <QtCore/QRegExp>

#include <cassert>

Expand Down
2 changes: 1 addition & 1 deletion src/qobjecthelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void QObjectHelper::qvariant2qobject(const QVariantMap& variant, QObject* object
}

QMetaProperty metaproperty = metaobject->property( pIdx );
QVariant::Type type = metaproperty.type();
QMetaType type = metaproperty.metaType();
QVariant v( iter.value() );
if ( v.canConvert( type ) ) {
v.convert( type );
Expand Down
1 change: 1 addition & 0 deletions src/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "serializer.h"

#include <QtCore/QDataStream>
#include <QtCore/QIODevice>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

Expand Down
11 changes: 1 addition & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
IF (Qt5Core_FOUND)
FIND_PACKAGE( Qt5Test REQUIRED )

INCLUDE_DIRECTORIES(${Qt5Test_INCLUDE_DIRS})
ADD_DEFINITIONS(${Qt5Test_DEFINITIONS})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Test_EXECUTABLE_COMPILE_FLAGS}")

SET (TEST_LIBRARIES ${Qt5Test_LIBRARIES})
ENDIF()
find_package(Qt6 CONFIG REQUIRED COMPONENTS Core Widgets Test)

macro(add_unittest DESCRIPTION)
add_test(NAME "${DESCRIPTION}"
Expand All @@ -15,7 +7,6 @@ macro(add_unittest DESCRIPTION)
)
endmacro()


ADD_SUBDIRECTORY(cmdline_tester)
ADD_SUBDIRECTORY(parser)
ADD_SUBDIRECTORY(scanner)
Expand Down
19 changes: 5 additions & 14 deletions tests/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
##### Probably don't want to edit below this line #####

SET( QT_USE_QTTEST TRUE )

INCLUDE(AddFileDependencies)

# Include the library include directories, and the current build directory (moc)
INCLUDE_DIRECTORIES(
../../include
${CMAKE_CURRENT_BINARY_DIR}
)

SET( UNIT_TESTS
parsingbenchmark
qlocalevsstrtod_l
Expand All @@ -25,10 +13,13 @@ FOREACH(test ${UNIT_TESTS})

TARGET_LINK_LIBRARIES(
${test}
${QT_LIBRARIES}
${TEST_LIBRARIES}
Qt::Core
Qt::Test
qjson${QJSON_SUFFIX}
)

target_include_directories(${test} PRIVATE ../../include)

if (QJSON_TEST_OUTPUT STREQUAL "xml")
# produce XML output
add_test( ${test} ${test} -xml -o ${test}.tml )
Expand Down
37 changes: 5 additions & 32 deletions tests/cmdline_tester/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
##### Probably don't want to edit below this line #####

IF (WIN32 AND Qt5Core_FOUND)
FIND_PACKAGE( Qt5Widgets REQUIRED )

INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDE_DIRS})
ADD_DEFINITIONS(${Qt5Widgets_DEFINITIONS})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
ENDIF()

IF (NOT Qt5Core_FOUND)
# Use it
INCLUDE( ${QT_USE_FILE} )
ENDIF()

INCLUDE(AddFileDependencies)

# Include the library include directories, and the current build directory (moc)
INCLUDE_DIRECTORIES(
../../include
${CMAKE_CURRENT_BINARY_DIR}
)

ADD_EXECUTABLE(
cmdline_tester
cmdline_tester.cpp
cmdlineparser.cpp
)

target_include_directories(cmdline_tester PRIVATE ../../include)

TARGET_LINK_LIBRARIES(
cmdline_tester
${QT_LIBRARIES}
Qt::Core
Qt::Widgets
Qt::Test
qjson${QJSON_SUFFIX}
)

if(WIN32)
target_link_libraries(
cmdline_tester
${QT_QTGUI_LIBRARY}
${Qt5Widgets_LIBRARIES}
)
endif()
12 changes: 3 additions & 9 deletions tests/cmdline_tester/cmdline_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QElapsedTimer>
#include <QtCore/QFile>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtCore/QTextCodec>
#include <QtCore/QTime>

#include <QJson/Parser>
#include <QJson/Serializer>
Expand All @@ -36,13 +35,8 @@ using namespace QJson;
int main(int argc, char *argv[]) {
QCoreApplication app (argc, argv);

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForCStrings(codec);
#endif

QTime time;
int duration;
QElapsedTimer time;
qint64 duration;


CmdLineParser cmd (app.arguments());
Expand Down
Loading