Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ vendor
build-*
docs/html
build
*.txt.user
.vscode
141 changes: 141 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
cmake_minimum_required(VERSION 3.14)

set(${PROJECT_NAME}_MAJOR_VERSION 0)
set(${PROJECT_NAME}_MINOR_VERSION 1)
set(${PROJECT_NAME}_PATCH_VERSION 0)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION}.${${PROJECT_NAME}_PATCH_VERSION}
)

project(
QSyncable
LANGUAGES CXX
VERSION ${${PROJECT_NAME}_VERSION})

set(CMAKE_AUTOMOC ON)

# compiler options
include(cmake/StandardProjectSettingsConfig.cmake)

# standard compiler warnings
include(cmake/CompilerOptionsAndWarningsConfig.cmake)
set(project_options_and_warnings ${PROJECT_NAME}_project_options_and_warnings)
add_library(${project_options_and_warnings} INTERFACE)
set_project_options_and_warnings(${project_options_and_warnings})

# enable doxygen
include(cmake/DoxygenConfig.cmake)

# project satinizers
include(cmake/Sanitizers.cmake)
enable_sanitizers(project_options_and_warnings)

# static analyzers
include(cmake/CppCheckConfig.cmake)
include(cmake/ClangTidyConfig.cmake)

find_package(
QT NAMES Qt6 Qt5
COMPONENTS Core Qml
REQUIRED)

find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Core Qml
REQUIRED)

set(SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/qsdiffrunner.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qsdiffrunneralgo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qsjsonlistmodel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/QSListModel
${CMAKE_CURRENT_SOURCE_DIR}/qslistmodel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qspatch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qstree.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qstreenode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qsuuid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qsyncablefunctions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qsyncableqmltypes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qsyncableqmlwrapper.cpp)
set(INCLUDE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/qsdiffrunner.h
${CMAKE_CURRENT_SOURCE_DIR}/qsfastdiffrunner.h
${CMAKE_CURRENT_SOURCE_DIR}/qsjsonlistmodel.h
${CMAKE_CURRENT_SOURCE_DIR}/qslistmodel.h
${CMAKE_CURRENT_SOURCE_DIR}/qspatch.h
${CMAKE_CURRENT_SOURCE_DIR}/qspatchable.h
${CMAKE_CURRENT_SOURCE_DIR}/qsuuid.h
${CMAKE_CURRENT_SOURCE_DIR}/qsyncablefunctions.h
${CMAKE_CURRENT_SOURCE_DIR}/QSListModel
${CMAKE_CURRENT_SOURCE_DIR}/qsyncableqmlwrapper.h)

set(INCLUDE_PRIV_FILES
${CMAKE_CURRENT_SOURCE_DIR}/priv/qsalgotypes_p.h
${CMAKE_CURRENT_SOURCE_DIR}/priv/qsdiffrunneralgo_p.h
${CMAKE_CURRENT_SOURCE_DIR}/priv/qsfastdiffrunneralgo_p.h
${CMAKE_CURRENT_SOURCE_DIR}/priv/qsimmutablewrapper_p.h
${CMAKE_CURRENT_SOURCE_DIR}/priv/qstree.h
${CMAKE_CURRENT_SOURCE_DIR}/priv/qstreenode.h)

add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${INCLUDE_FILES}
${INCLUDE_PRIV_FILES})

target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)


target_link_libraries(${PROJECT_NAME} PRIVATE ${project_options_and_warnings})
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Qml)

set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX d)

# Examples
option(${PROJECT_NAME}_EXAMPLES "Enable Examples" OFF)

if(${PROJECT_NAME}_EXAMPLES)
message(STATUS "Building Examples")
add_subdirectory(examples/faketrello)
endif()

# Install script
option(${PROJECT_NAME}_INSTALL "Enable Installing as Library" OFF)

if(${PROJECT_NAME}_INSTALL)
# Offer the user the choice of overriding the installation directories
install(
TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
EXPORT ${PROJECT_NAME}Targets)

install(FILES ${INCLUDE_FILES} DESTINATION include/${PROJECT_NAME})
install(FILES ${INCLUDE_PRIV_FILES} DESTINATION include/${PROJECT_NAME}/priv)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}Version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

# installation - build tree specific package config files
export(EXPORT ${PROJECT_NAME}Targets
FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Targets.cmake)
# installation - relocatable package config files
configure_package_config_file(
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION cmake)

set(CONFIG_PACKAGE_LOCATION ${CMAKE_INSTALL_LIBDIR}/cmake/QSyncable)

install(
EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CONFIG_PACKAGE_LOCATION})

install(FILES ${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME}Version.cmake
DESTINATION ${CONFIG_PACKAGE_LOCATION})
endif()
2 changes: 2 additions & 0 deletions QSListModel
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#include "qslistmodel.h"

void registerQSyncableTypes();
3 changes: 3 additions & 0 deletions QSyncableConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@
set_and_check(QSyncable_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(QSyncable_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@")
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,44 @@ Download a release and bundle the folder within your source tree.

Or:

```
```sh
qpm install com.github.benlau.qsyncable
```

Using Cmake
-----------

Add the follow snippet to your CMakeFile

```cmake
include(FetchContent)

FetchContent_Declare(
QSyncable
PREFIX "${PROJECT_BINARY_DIR}/QSyncable-build"
GIT_REPOSITORY "https://github.com/benlau/QSyncable.git"
CMAKE_ARGS "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
"-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/QSyncable"
"-DCMAKE_INSTALL_LIBDIR=${PROJECT_BINARY_DIR}/QSyncable/lib"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
)

FetchContent_MakeAvailable(QSyncable)

```

Link it to your library

```cmake
target_link_libraries(${PROJECT_NAME} PRIVATE QSyncable)
```

In your main function you need to manually register the QML types

```cpp
registerQSyncableTypes();
```

Class Reference
---------------

Expand Down
11 changes: 11 additions & 0 deletions cmake/ClangTidyConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
option(ENABLE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF)

if(ENABLE_CLANG_TIDY)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)
set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY}
-extra-arg=-Wno-unknown-warning-option)
else()
message(WARNING "clang-tidy requested but executable not found")
endif()
endif()
14 changes: 14 additions & 0 deletions cmake/CodeCoverageConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function(enable_code_coverage project_name)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES
".*Clang")
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" OFF)

if(ENABLE_COVERAGE)
target_compile_options(project_options INTERFACE --coverage -O0 -g)
target_link_libraries(project_options INTERFACE --coverage)
endif()

endif()

endfunction()
109 changes: 109 additions & 0 deletions cmake/CompilerOptionsAndWarningsConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# from here:
#
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Avai
# lable.md

function(set_project_options_and_warnings project_name)
option(ENABLE_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)

set(MSVC_WARNINGS
/W4 # Baseline reasonable warnings
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss
# of data
/w14254 # 'operator': conversion from 'type1:field_bits' to
# 'type2:field_bits', possible loss of data
/w14263 # 'function': member function does not override any base class
# virtual member function
/w14265 # 'classname': class has virtual functions, but destructor is not
# virtual instances of this class may not be destructed correctly
/w14287 # 'operator': unsigned/negative constant mismatch
/we4289 # nonstandard extension used: 'variable': loop control variable
# declared in the for-loop is used outside the for-loop scope
/w14296 # 'operator': expression is always 'boolean_value'
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
/w14545 # expression before comma evaluates to a function which is missing
# an argument list
/w14546 # function call before comma missing argument list
/w14547 # 'operator': operator before comma has no effect; expected
# operator with side-effect
/w14549 # 'operator': operator before comma has no effect; did you intend
# 'operator'?
/w14555 # expression has no effect; expected expression with side- effect
/w14619 # pragma warning: there is no warning number 'number'
/w14640 # Enable warning on thread un-safe static member initialization
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may
# cause unexpected runtime behavior.
/w14905 # wide string literal cast to 'LPSTR'
/w14906 # string literal cast to 'LPWSTR'
/w14928 # illegal copy-initialization; more than one user-defined
# conversion has been implicitly applied
/permissive- # standards conformance mode for MSVC compiler.
)

set(CLANG_WARNINGS
-Wall
-Wextra # reasonable and standard
-Wshadow # warn the user if a variable declaration shadows one from a
# parent context
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a
# non-virtual destructor. This helps catch hard to
# track down memory errors
-Wold-style-cast # warn for c-style casts
-Wcast-align # warn for potential performance problem casts
-Wunused # warn on anything being unused
-Woverloaded-virtual # warn if you overload (not override) a virtual
# function
-Wpedantic # warn if non-standard C++ is used
-Wconversion # warn on type conversions that may lose data
-Wsign-conversion # warn on sign conversions
-Wnull-dereference # warn if a null dereference is detected
-Wdouble-promotion # warn if float is implicit promoted to double
-Wformat=2 # warn on security issues around functions that format output
# (ie printf)
)

if(ENABLE_WARNINGS_AS_ERRORS)
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
message(STATUS "Warnings as Errors")
endif()

set(GCC_WARNINGS
${CLANG_WARNINGS}
-Wmisleading-indentation # warn if indentation implies blocks where blocks
# do not exist
-Wduplicated-cond # warn if if / else chain has duplicated conditions
-Wduplicated-branches # warn if if / else branches have duplicated code
-Wlogical-op # warn about logical operations being used where bitwise were
# probably wanted.
-Wuseless-cast # warn if you perform a cast to the same type
)

if(NO_EXCEPTIONS)
set(MSVC_OPTIONS /GR-)
set(GCC_OPTIONS -fno-exceptions -fno-rtti)
message(STATUS "No exceptions allowed")
endif()

message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")

if(MSVC)
set(PROJECT_WARNINGS ${MSVC_WARNINGS})
set(PROJECT_OPTIONS ${MSVC_OPTIONS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(PROJECT_WARNINGS ${CLANG_WARNINGS})
set(PROJECT_OPTIONS ${GCC_OPTIONS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(PROJECT_WARNINGS ${GCC_WARNINGS})
set(PROJECT_OPTIONS ${GCC_OPTIONS})
else()
message(
AUTHOR_WARNING
"No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif()

message(STATUS "Adding Compiler Options and Warnings to target: ${project_name}")
target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}
${PROJECT_OPTIONS})

endfunction()
Loading