Skip to content

Commit

Permalink
WIP: integrate Drawdance internally
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Aug 5, 2023
1 parent 07f7192 commit fc7f28d
Show file tree
Hide file tree
Showing 635 changed files with 378 additions and 197,557 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ jobs:
-DSERVERGUI=on
-DTOOLS=on
-DTESTS=on
-DUSE_GENERATORS=off
"-DCMAKE_PREFIX_PATH=${{ matrix.cross_os && format('{0};', steps.cross-deps.outputs.path) }}${{ steps.deps.outputs.path }}"
-DCMAKE_INSTALL_PREFIX=out
-DCLANG_TIDY=${{ github.event_name != 'push' && 'on' || 'off' }}
Expand Down
17 changes: 7 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include(DrawpileVersions)
project(Drawpile
VERSION ${PROJECT_VERSION}
HOMEPAGE_URL https://drawpile.net
LANGUAGES CXX
LANGUAGES C CXX
)

include(DrawpileCheckSymlinks)
Expand Down Expand Up @@ -102,23 +102,17 @@ if(ANDROID AND QT_VERSION VERSION_LESS 6)
endif()

if(CLIENT OR SERVER)
# Since Drawdance also runs `find_package(Qt)` we must run it first or else
# the `apk` target will pick up the sub-project `PROJECT_NAME` instead of
# our own `PROJECT_NAME`.
# Finding Qt needs to come first, otherwise automoc gets confused about
# being unable to generate a MOC for the cmake-config directory below.
find_package(${QT_PACKAGE_NAME} REQUIRED COMPONENTS Core Network)

if(EXISTS ${PROJECT_SOURCE_DIR}/extern/drawdance/CMakeLists.txt)
add_subdirectory(extern/drawdance EXCLUDE_FROM_ALL)
else()
find_package(Drawdance REQUIRED COMPONENTS dpcommon dpengine dpmsg)
endif()
endif()

# This must be included *after* drawdance is added to make sure that we do not
# pollute that sub-project with our compiler options. Once CMake 3.25 is the
# minimum required version and Qt5 for Android is not used any more, it is
# possible that the SYSTEM flag of `add_subdirectory` may do this and then this
# can be moved down the list to where the rest of the dependencies are.
include(GetIgnoreWarningsInDirectory)
include(DrawpileCompilerOptions)

if(TESTS)
Expand Down Expand Up @@ -160,6 +154,9 @@ if(CLIENT OR SERVER)
endif()
add_feature_info("Zeroconf support" "TARGET KF5::DNSSD" "")

message(STATUS "Adding drawdance")
add_subdirectory(src/drawdance)

message(STATUS "Adding libshared")
add_subdirectory(src/libshared)
endif()
Expand Down
32 changes: 32 additions & 0 deletions cmake/DrawdanceCompilerOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-License-Identifier: MIT

if(MSVC)
add_compile_options(
# C4100: unreferenced formal parameter
# - MSVC has no `__attribute__((unused))` and omitting parameter names
# wouldn't be standard C
$<$<COMPILE_LANGUAGE:C>:/wd4100>
# C4127: conditional expression is constant
# - macros from uthash emit `do {} while(0);` and this triggers on
# `while(0)`
/wd4127
# C4200: nonstandard extension used: zero-sized array in struct/union
# - MSVC does not recognise C99 flexible array members as standard
/wd4200
# C4210: nonstandard extension used: function given file scope
# - MSVC does not recognize extern inside of functions as standard
/wd4210
# C4701 and 4703: potentially ininitialized (pointer) variable used
# - detection is so primitive that it spams innumerable false positives
/wd4701 /wd4703
# C4702: unreachable code
# - macros from uthash causing problems again
/wd4702
)
else()
add_compile_options(
-Wmissing-include-dirs -Wconversion
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>
)
endif()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,12 @@

function(dp_add_executable target)
add_executable(${target})

if(NOT SUBPROJECT)
install(TARGETS ${target}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
endfunction()

function(dp_add_library target)
add_library(${target})
add_library(${PROJECT_NAME}::${target} ALIAS ${target})

set_property(GLOBAL APPEND PROPERTY dp_components "${target}")

if(NOT SUBPROJECT)
install(TARGETS ${target}
EXPORT ${target}Targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(EXPORT ${target}Targets
FILE ${PROJECT_NAME}${target}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME}
)
endif()
endfunction()

function(dp_find_package)
Expand Down Expand Up @@ -78,14 +55,4 @@ endfunction()

function(dp_target_sources target)
target_sources(${target} PRIVATE ${ARGN})
if(NOT SUBPROJECT)
foreach(file IN LISTS ARGN)
if(file MATCHES "(\\.[Hh]([Pp][Pp])?|include[\\/][^.]*)$")
install(
FILES "${file}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${target}"
)
endif()
endforeach()
endif()
endfunction()
27 changes: 27 additions & 0 deletions cmake/DrawdanceOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: MIT

if(CLIENT OR SERVER)
set(IMAGE_IMPL QT)
set(FILE_IO_IMPL QT)
if(QT_VERSION_MAJOR EQUAL 5)
set(ZIP_IMPL KARCHIVE)
else()
set(ZIP_IMPL LIBZIP)
endif()
elseif(EMSCRIPTEN)
set(IMAGE_IMPL LIBS)
set(FILE_IO_IMPL STDIO)
else()
set(IMAGE_IMPL LIBS CACHE STRING "PNG and JPEG implementation (LIBS, QT)")
string(TOUPPER IMAGE_IMPL ${IMAGE_IMPL})

set(FILE_IO_IMPL STDIO CACHE STRING "Default file I/O (STDIO, QT)")
string(TOUPPER FILE_IO_IMPL ${FILE_IO_IMPL})

set(ZIP_IMPL LIBZIP CACHE STRING "ZIP folder implementation (LIBZIP, KARCHIVE)")
string(TOUPPER ZIP_IMPL ${ZIP_IMPL})
endif()

add_feature_info("Image library implementation (IMAGE_IMPL)" ON ${IMAGE_IMPL})
add_feature_info("File I/O implementation (FILE_IO_IMPL)" ON ${FILE_IO_IMPL})
add_feature_info("ZIP implementation (ZIP_IMPL)" ON ${ZIP_IMPL})
77 changes: 53 additions & 24 deletions cmake/DrawpileCompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOMOC_PATH_PREFIX ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_OBJCXX_STANDARD 17)
set(CMAKE_OBJCXX_STANDARD_REQUIRED ON)
set(CMAKE_OBJCXX_EXTENSIONS OFF)

if(EMSCRIPTEN)
set(CMAKE_EXECUTABLE_SUFFIX ".js")
# This flag is required when compiling all objects or linking will fail
# when --shared-memory is used, which it is implicitly
add_compile_options(-pthread)
endif()

if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
include(CheckIPOSupported)
check_ipo_supported(RESULT CMAKE_INTERPROCEDURAL_OPTIMIZATION LANGUAGES CXX)
Expand Down Expand Up @@ -41,30 +51,44 @@ if(MSVC)
endforeach()
endforeach()
unset(type_upper)

get_directory_property(IGNORE_WARNINGS_COMPILE_OPTIONS COMPILE_OPTIONS)
list(TRANSFORM IGNORE_WARNINGS_COMPILE_OPTIONS REPLACE "/W[0-9]$" "/W0")
list(TRANSFORM IGNORE_WARNINGS_COMPILE_OPTIONS REPLACE "/W([0-9]{4})" "/wd\\1")
else()
add_compile_options(-Wall -Wextra -Wpedantic
-Wcast-align
-Wcast-qual
-Wextra-semi
-Wformat-nonliteral
-Wimplicit-fallthrough
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wshadow
-Wunused
-Wunused-parameter
-Wunused-macros
-Wzero-as-null-pointer-constant
$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Wcast-qual>
$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Wextra-semi>
$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Wnon-virtual-dtor>
$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Wold-style-cast>
$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Woverloaded-virtual>
$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Wzero-as-null-pointer-constant>
)

# Some third-party libraries use comments to mark fallthrough cases, sccache
# strips those and that triggers warnings about implicit fallthrough.
foreach(lang IN LISTS ENABLED_LANGUAGES)
if(NOT CMAKE_${lang}_COMPILER_LAUNCHER MATCHES "sccache")
add_compile_options(
$<$<COMPILE_LANGUAGE:${lang}>:-Wimplicit-fallthrough>
)
endif()
endforeach()

if(NOT USE_STRICT_ALIASING)
add_compile_options(-fno-strict-aliasing)
add_compile_definitions(DP_NO_STRICT_ALIASING)
endif()

if(ENABLE_ARCH_NATIVE)
add_compile_options(-march=native)
endif()

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105725
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.2)
add_compile_options(-Wmismatched-tags)
add_compile_options($<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Wmismatched-tags>)
endif()

include(CheckCXXCompilerFlag)
Expand All @@ -79,40 +103,45 @@ else()
-Wformat-security
-Wlogical-op
-Wlogical-op-parentheses
-Wsuggest-destructor-override
-Wsuggest-final-methods
-Wsuggest-final-types
-Wsuggest-override
-Wunused-member-function
-Wunused-template
-Wuseless-cast
# These are only valid for C++ and Objective C++, marked by a trailing >
-Wsuggest-destructor-override>
-Wsuggest-final-methods>
-Wsuggest-final-types>
-Wsuggest-override>
-Wunused-member-function>
-Wunused-template>
-Wuseless-cast>
)
string(TOUPPER ${flag} flag_name)
string(REPLACE "-W" "CXX_HAS_" flag_name ${flag_name})
string(REPLACE "-" "_" flag_name ${flag_name})
string(REPLACE "=" "_" flag_name ${flag_name})
string(REPLACE ">" "" flag_name ${flag_name})
check_cxx_compiler_flag(${flag} ${flag_name})
if(${flag_name})
add_compile_options(${flag})
if("${flag}" MATCHES ">")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:${flag}")
else()
add_compile_options(${flag})
endif()
endif()
endforeach()

if($ENV{CI})
add_compile_options(-Werror)
endif()

get_directory_property(IGNORE_WARNINGS_COMPILE_OPTIONS COMPILE_OPTIONS)
list(TRANSFORM IGNORE_WARNINGS_COMPILE_OPTIONS REPLACE "-W(no-)?([^=]+)(=.*$)?" "-Wno-\\2")

# This is valid in C++20 and all the C++17 compilers already support it;
# it must be ignored to use the QLoggingCategory macros like
# `qCDebug(foo) << "Message"`
check_cxx_compiler_flag(-Wgnu-zero-variadic-macro-arguments CXX_HAS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS)
if (CXX_HAS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS)
if(CXX_HAS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS)
add_compile_options(-Wno-gnu-zero-variadic-macro-arguments)
endif()
endif()

get_ignore_warnings_in_directory(IGNORE_WARNINGS_COMPILE_OPTIONS)

foreach(lang IN LISTS ENABLED_LANGUAGES)
if(CLANG_TIDY AND NOT CMAKE_${lang}_CLANG_TIDY)
if(NOT DEFINED clang_tidy_exe)
Expand Down
13 changes: 13 additions & 0 deletions cmake/DrawpileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ else()
set(INITSYS "" CACHE STRING "" FORCE)
endif()

if(NOT CMAKE_CROSSCOMPILING)
option(USE_GENERATORS "Do code generation" ON)
add_feature_info("Code generation (USE_GENERATORS)" USE_GENERATORS "")
endif()

if(NOT MSVC AND NOT EMSCRIPTEN)
option(USE_STRICT_ALIASING "Enable strict aliasing optimizations" OFF)
add_feature_info("Strict aliasing (USE_STRICT_ALIASING)" USE_STRICT_ALIASING "")

option(ENABLE_ARCH_NATIVE "Optimize for this computer's CPU" OFF)
add_feature_info("Non-portable optimizations (ENABLE_ARCH_NATIVE)" ENABLE_ARCH_NATIVE "")
endif()

option(DIST_BUILD "Build for stand-alone distribution")
add_feature_info("Distribution build (DIST_BUILD)" DIST_BUILD "")

Expand Down
2 changes: 1 addition & 1 deletion cmake/DrawpileVersions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ endif()
unset(dp_version)

set(dp_proto_regex "^[ \t]*version:[ \t]*\"?dp:([0-9]+)\\.([0-9]+)\\.([0-9]+)\"?$")
file(STRINGS extern/drawdance/generators/protogen/protocol.yaml dp_proto_version LIMIT_COUNT 1 REGEX ${dp_proto_regex})
file(STRINGS src/drawdance/generators/protogen/protocol.yaml dp_proto_version LIMIT_COUNT 1 REGEX ${dp_proto_regex})
if(dp_proto_version MATCHES ${dp_proto_regex})
set(DRAWPILE_PROTO_SERVER_VERSION ${CMAKE_MATCH_1})
set(DRAWPILE_PROTO_MAJOR_VERSION ${CMAKE_MATCH_2})
Expand Down
12 changes: 12 additions & 0 deletions cmake/GetIgnoreWarningsInDirectory.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: MIT

function(get_ignore_warnings_in_directory out_var)
get_directory_property(options COMPILE_OPTIONS)
if(MSVC)
list(TRANSFORM options REPLACE "/W[0-9]$" "/W0")
list(TRANSFORM options REPLACE "/W([0-9]{4})" "/wd\\1")
else()
list(TRANSFORM options REPLACE "-W(no-)?([^=]+)(=.*$)?" "-Wno-\\2")
endif()
set(${out_var} "${options}" PARENT_SCOPE)
endfunction()
3 changes: 0 additions & 3 deletions extern/drawdance/.clang-tidy

This file was deleted.

12 changes: 0 additions & 12 deletions extern/drawdance/.gitignore

This file was deleted.

Loading

0 comments on commit fc7f28d

Please sign in to comment.