From 34d6c185d112d9342379d08999f82dd7c6b5b0af Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sat, 25 Mar 2023 18:36:36 -0500 Subject: [PATCH] Fix broken builds and missing install targets This commit rewrites the existing CMake files so that they export targets and install required headers in a way that allows the application and libraries to install and be idiomatically integrated with other projects. Included third-party code now builds object libraries that are embedded in the final archives and public headers from those third-party libraries are installed in subdirectories of the embedding libraries. This commit also fixes compiling the drawdance and dpgles2 targets and the emscripten cross-compilation, which were all broken. Across CMake files, verbose copyright headers are replaced with SPDX identifiers plus an AUTHORS.txt for standard attribution. Finally, this commit removes clang-format from CMake, since this cannot work with all generators according to and should go into a git pre-commit hook instead or integrated in the IDE. --- 3rdparty/CMakeLists.txt | 114 +++++---- 3rdparty/dpgles2/gl2.h | 2 +- 3rdparty/dpgles2/gl2platform.h | 2 +- 3rdparty/dpgles2/khrplatform.h | 311 ++++++++++++++++++++++++ AUTHORS.txt | 4 + CMakeLists.txt | 219 ++++++++--------- Config.cmake.in | 40 +++ appconv/CMakeLists.txt | 36 +-- appdrawdance/CMakeLists.txt | 141 ++++------- appdrawdance/drawdance_lua/ui.c | 2 + cmake/address_sanitizer.cmake | 46 ---- cmake/clang_format.cmake | 38 --- cmake/clang_tidy.cmake | 43 ---- cmake/compile_flags.cmake | 166 +++++++++---- cmake/dependencies.cmake | 92 ++----- cmake/dpconfig.cmake | 22 -- cmake/{dpconfig.tpl.h => dpconfig.h.in} | 0 cmake/emscripten.cmake | 28 --- cmake/emsdl2/SDL.h | 1 - cmake/emsdl2/SDL_timer.h | 1 - cmake/export.cmake | 33 --- cmake/helper.cmake | 85 +++++++ cmake/language_standards.cmake | 25 -- cmake/tests.cmake | 58 ++--- generators/CMakeLists.txt | 36 +-- libclient/CMakeLists.txt | 81 +++--- libclient/dpclient/document.c | 2 +- libclient/dpclient/tcp_socket_client.c | 10 +- libcommon/CMakeLists.txt | 106 +++----- libcommon/dpcommon/threading.h | 3 + libengine/CMakeLists.txt | 205 ++++++++-------- libengine/dpengine/brush.h | 4 + libmsg/CMakeLists.txt | 67 ++--- libmsg/dpmsg/binary_writer.h | 4 + libmsg/dpmsg/text_writer.h | 4 + test/CMakeLists.txt | 37 +-- 36 files changed, 1068 insertions(+), 1000 deletions(-) create mode 100644 3rdparty/dpgles2/khrplatform.h create mode 100644 AUTHORS.txt create mode 100644 Config.cmake.in delete mode 100644 cmake/address_sanitizer.cmake delete mode 100644 cmake/clang_format.cmake delete mode 100644 cmake/clang_tidy.cmake delete mode 100644 cmake/dpconfig.cmake rename cmake/{dpconfig.tpl.h => dpconfig.h.in} (100%) delete mode 100644 cmake/emscripten.cmake delete mode 100644 cmake/emsdl2/SDL.h delete mode 100644 cmake/emsdl2/SDL_timer.h delete mode 100644 cmake/export.cmake create mode 100644 cmake/helper.cmake delete mode 100644 cmake/language_standards.cmake diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 701b15a..e32c69f 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -1,25 +1,7 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT if(BUILD_APPS) - add_library(lua STATIC lua/lapi.c lua/lapi.h lua/lauxlib.c lua/lauxlib.h + add_library(lua OBJECT lua/lapi.c lua/lapi.h lua/lauxlib.c lua/lauxlib.h lua/lbaselib.c lua/lcode.c lua/lcode.h lua/lcorolib.c lua/lctype.c lua/lctype.h lua/ldblib.c lua/ldebug.c lua/ldebug.h lua/ldo.c lua/ldo.h lua/ldump.c lua/lfunc.c lua/lfunc.h lua/lgc.c lua/lgc.h @@ -32,26 +14,32 @@ if(BUILD_APPS) lua/ltm.h lua/lua.h lua/luaconf.h lua/lualib.h lua/lundump.c lua/lundump.h lua/lutf8lib.c lua/lvm.c lua/lvm.h lua/lzio.c lua/lzio.h ) - set_dp_target_properties(lua NO_CLANG_TIDY NO_WARNINGS) - target_include_directories(lua INTERFACE "${CMAKE_CURRENT_LIST_DIR}/lua") + target_include_directories(lua SYSTEM PUBLIC + $ + $ + ) - add_clang_format_files(dpgles2/gles2_inc.h) add_library(dpgles2 INTERFACE) - set_dp_target_properties(dpgles2 NO_ASAN NO_CLANG_TIDY NO_WARNINGS) - target_include_directories(dpgles2 INTERFACE "${CMAKE_CURRENT_LIST_DIR}/dpgles2") + target_include_directories(dpgles2 SYSTEM INTERFACE "dpgles2") - add_library(imgui STATIC imgui/imconfig.h imgui/imgui.cpp imgui/imgui_demo.cpp + add_library(imgui OBJECT imgui/imconfig.h imgui/imgui.cpp imgui/imgui_demo.cpp imgui/imgui_draw.cpp imgui/imgui.h imgui/imgui_impl_opengl3.cpp imgui/imgui_impl_opengl3.h imgui/imgui_impl_sdl.cpp imgui/imgui_impl_sdl.h imgui/imgui_internal.h imgui/imgui_tables.cpp imgui/imgui_widgets.cpp imgui/imstb_rectpack.h imgui/imstb_textedit.h imgui/imstb_truetype.h) - set_dp_target_properties(imgui CXX NO_CLANG_TIDY NO_WARNINGS) target_compile_definitions(imgui PRIVATE IMGUI_IMPL_OPENGL_ES2) - target_include_directories(imgui INTERFACE "${CMAKE_CURRENT_LIST_DIR}/imgui") - target_link_libraries(imgui PUBLIC dpgles2 SDL2::SDL2) + target_include_directories(imgui SYSTEM PUBLIC + $ + $ + ) + target_link_libraries(imgui PRIVATE dpgles2 SDL2::SDL2) + # https://github.com/libsdl-org/SDL/issues/3657 + if(APPLE AND SDL2_VERSION VERSION_LESS 2.0.13) + target_compile_definitions(imgui PRIVATE _DARWIN_C_SOURCE) + endif() - add_library(uriparser STATIC uriparser/UriCommon.c uriparser/UriCommon.h + add_library(uriparser OBJECT uriparser/UriCommon.c uriparser/UriCommon.h uriparser/UriCompare.c uriparser/UriEscape.c uriparser/UriFile.c uriparser/UriIp4.c uriparser/UriIp4Base.c uriparser/UriIp4Base.h uriparser/UriMemory.c uriparser/UriMemory.h @@ -65,27 +53,32 @@ if(BUILD_APPS) uriparser/include/uriparser/UriDefsAnsi.h uriparser/include/uriparser/UriDefsConfig.h uriparser/include/uriparser/UriIp4.h) - set_dp_target_properties(uriparser NO_CLANG_TIDY NO_WARNINGS) target_compile_definitions(uriparser PUBLIC URI_NO_UNICODE) - target_include_directories( - uriparser PRIVATE "${CMAKE_CURRENT_LIST_DIR}/uriparser") - target_include_directories( - uriparser PUBLIC "${CMAKE_CURRENT_LIST_DIR}/uriparser/include") + target_include_directories(uriparser SYSTEM + PUBLIC + $ + $ + PRIVATE + $ + ) endif() -add_library(parson STATIC parson/parson.c parson/parson.h) -set_dp_target_properties(parson NO_CLANG_TIDY NO_WARNINGS) -target_include_directories(parson INTERFACE "${CMAKE_CURRENT_LIST_DIR}/parson") +add_library(parson OBJECT parson/parson.c parson/parson.h) +target_include_directories(parson SYSTEM PUBLIC + $ + $ +) -add_library(qgrayraster STATIC qgrayraster/qgrayraster.c +add_library(qgrayraster OBJECT qgrayraster/qgrayraster.c qgrayraster/qgrayraster_inc.h qgrayraster/qgrayraster_p.h qgrayraster/qrasterdefs_p.h) -set_dp_target_properties(qgrayraster NO_CLANG_TIDY NO_WARNINGS) -target_include_directories(qgrayraster INTERFACE - "${CMAKE_CURRENT_LIST_DIR}/qgrayraster") +target_include_directories(qgrayraster SYSTEM PUBLIC + $ + $ +) -add_library(mypaint STATIC libmypaint/brushsettings-gen.h +add_library(mypaint OBJECT libmypaint/brushsettings-gen.h libmypaint/config.h libmypaint/fastapprox/cast.h libmypaint/fastapprox/fasterf.h libmypaint/fastapprox/fastexp.h libmypaint/fastapprox/fastgamma.h @@ -104,15 +97,32 @@ add_library(mypaint STATIC libmypaint/brushsettings-gen.h libmypaint/mypaint-rectangle.h libmypaint/mypaint-surface.c libmypaint/mypaint-surface.h libmypaint/rng-double.c libmypaint/rng-double.h ) -set_dp_target_properties(mypaint NO_CLANG_TIDY NO_WARNINGS) -target_include_directories(mypaint INTERFACE - "${CMAKE_CURRENT_LIST_DIR}/libmypaint") +target_include_directories(mypaint SYSTEM PUBLIC + $ + $ +) add_library(uthash INTERFACE) -set_dp_target_properties(uthash NO_CLANG_TIDY NO_WARNINGS) -target_include_directories(uthash INTERFACE "${CMAKE_CURRENT_LIST_DIR}/uthash") +target_include_directories(uthash INTERFACE "uthash") -add_library(jo_gifx STATIC jo_gifx/jo_gifx.h jo_gifx/jo_gifx.c) -set_dp_target_properties(jo_gifx NO_WARNINGS) -target_include_directories( - jo_gifx INTERFACE "${CMAKE_CURRENT_LIST_DIR}/jo_gifx") +add_library(jo_gifx OBJECT jo_gifx/jo_gifx.h jo_gifx/jo_gifx.c) +target_include_directories(jo_gifx SYSTEM PUBLIC + $ + $ +) + +# The project root adds compiler warnings and tidy to all targets, but +# third-party code does not follow the same code hygiene rules, so turn those +# off for everything in this directory +get_directory_property(third_party_targets BUILDSYSTEM_TARGETS) +set_property(TARGET ${third_party_targets} APPEND PROPERTY + COMPILE_OPTIONS "${IGNORE_WARNINGS_COMPILE_OPTIONS}" +) +# It is not possible to use the same approach that was used to disable +# warnings because CMake apparently discards empty list items when a list is +# passed to set_target_properties, so instead we must loop to unset each +# property +foreach(ignore_tidy IN LISTS IGNORE_TIDY_PROPERTY_NAMES) + set_property(TARGET ${third_party_targets} PROPERTY ${ignore_tidy}) +endforeach() +unset(third_party_targets) diff --git a/3rdparty/dpgles2/gl2.h b/3rdparty/dpgles2/gl2.h index db37db0..f274cd9 100644 --- a/3rdparty/dpgles2/gl2.h +++ b/3rdparty/dpgles2/gl2.h @@ -58,7 +58,7 @@ extern "C" { #ifndef GL_ES_VERSION_2_0 #define GL_ES_VERSION_2_0 1 -#include "../KHR/khrplatform.h" +#include "khrplatform.h" typedef khronos_int8_t GLbyte; typedef khronos_float_t GLclampf; typedef khronos_int32_t GLfixed; diff --git a/3rdparty/dpgles2/gl2platform.h b/3rdparty/dpgles2/gl2platform.h index 64fe848..478ac22 100644 --- a/3rdparty/dpgles2/gl2platform.h +++ b/3rdparty/dpgles2/gl2platform.h @@ -25,7 +25,7 @@ * https://github.com/KhronosGroup/OpenGL-Registry */ -#include "../KHR/khrplatform.h" +#include "khrplatform.h" #ifndef GL_APICALL #define GL_APICALL KHRONOS_APICALL diff --git a/3rdparty/dpgles2/khrplatform.h b/3rdparty/dpgles2/khrplatform.h new file mode 100644 index 0000000..0164644 --- /dev/null +++ b/3rdparty/dpgles2/khrplatform.h @@ -0,0 +1,311 @@ +#ifndef __khrplatform_h_ +#define __khrplatform_h_ + +/* +** Copyright (c) 2008-2018 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Khronos platform-specific types and definitions. + * + * The master copy of khrplatform.h is maintained in the Khronos EGL + * Registry repository at https://github.com/KhronosGroup/EGL-Registry + * The last semantic modification to khrplatform.h was at commit ID: + * 67a3e0864c2d75ea5287b9f3d2eb74a745936692 + * + * Adopters may modify this file to suit their platform. Adopters are + * encouraged to submit platform specific modifications to the Khronos + * group so that they can be included in future versions of this file. + * Please submit changes by filing pull requests or issues on + * the EGL Registry repository linked above. + * + * + * See the Implementer's Guidelines for information about where this file + * should be located on your system and for more details of its use: + * http://www.khronos.org/registry/implementers_guide.pdf + * + * This file should be included as + * #include + * by Khronos client API header files that use its types and defines. + * + * The types in khrplatform.h should only be used to define API-specific types. + * + * Types defined in khrplatform.h: + * khronos_int8_t signed 8 bit + * khronos_uint8_t unsigned 8 bit + * khronos_int16_t signed 16 bit + * khronos_uint16_t unsigned 16 bit + * khronos_int32_t signed 32 bit + * khronos_uint32_t unsigned 32 bit + * khronos_int64_t signed 64 bit + * khronos_uint64_t unsigned 64 bit + * khronos_intptr_t signed same number of bits as a pointer + * khronos_uintptr_t unsigned same number of bits as a pointer + * khronos_ssize_t signed size + * khronos_usize_t unsigned size + * khronos_float_t signed 32 bit floating point + * khronos_time_ns_t unsigned 64 bit time in nanoseconds + * khronos_utime_nanoseconds_t unsigned time interval or absolute time in + * nanoseconds + * khronos_stime_nanoseconds_t signed time interval in nanoseconds + * khronos_boolean_enum_t enumerated boolean type. This should + * only be used as a base type when a client API's boolean type is + * an enum. Client APIs which use an integer or other type for + * booleans cannot use this as the base type for their boolean. + * + * Tokens defined in khrplatform.h: + * + * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. + * + * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. + * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. + * + * Calling convention macros defined in this file: + * KHRONOS_APICALL + * KHRONOS_APIENTRY + * KHRONOS_APIATTRIBUTES + * + * These may be used in function prototypes as: + * + * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( + * int arg1, + * int arg2) KHRONOS_APIATTRIBUTES; + */ + +#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) +# define KHRONOS_STATIC 1 +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APICALL + *------------------------------------------------------------------------- + * This precedes the return type of the function in the function prototype. + */ +#if defined(KHRONOS_STATIC) + /* If the preprocessor constant KHRONOS_STATIC is defined, make the + * header compatible with static linking. */ +# define KHRONOS_APICALL +#elif defined(_WIN32) +# define KHRONOS_APICALL __declspec(dllimport) +#elif defined (__SYMBIAN32__) +# define KHRONOS_APICALL IMPORT_C +#elif defined(__ANDROID__) +# define KHRONOS_APICALL __attribute__((visibility("default"))) +#else +# define KHRONOS_APICALL +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIENTRY + *------------------------------------------------------------------------- + * This follows the return type of the function and precedes the function + * name in the function prototype. + */ +#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) + /* Win32 but not WinCE */ +# define KHRONOS_APIENTRY __stdcall +#else +# define KHRONOS_APIENTRY +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIATTRIBUTES + *------------------------------------------------------------------------- + * This follows the closing parenthesis of the function prototype arguments. + */ +#if defined (__ARMCC_2__) +#define KHRONOS_APIATTRIBUTES __softfp +#else +#define KHRONOS_APIATTRIBUTES +#endif + +/*------------------------------------------------------------------------- + * basic type definitions + *-----------------------------------------------------------------------*/ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) + + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 +/* + * To support platform where unsigned long cannot be used interchangeably with + * inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t. + * Ideally, we could just use (u)intptr_t everywhere, but this could result in + * ABI breakage if khronos_uintptr_t is changed from unsigned long to + * unsigned long long or similar (this results in different C++ name mangling). + * To avoid changes for existing platforms, we restrict usage of intptr_t to + * platforms where the size of a pointer is larger than the size of long. + */ +#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__) +#if __SIZEOF_POINTER__ > __SIZEOF_LONG__ +#define KHRONOS_USE_INTPTR_T +#endif +#endif + +#elif defined(__VMS ) || defined(__sgi) + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) + +/* + * Win32 + */ +typedef __int32 khronos_int32_t; +typedef unsigned __int32 khronos_uint32_t; +typedef __int64 khronos_int64_t; +typedef unsigned __int64 khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__sun__) || defined(__digital__) + +/* + * Sun or Digital + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#if defined(__arch64__) || defined(_LP64) +typedef long int khronos_int64_t; +typedef unsigned long int khronos_uint64_t; +#else +typedef long long int khronos_int64_t; +typedef unsigned long long int khronos_uint64_t; +#endif /* __arch64__ */ +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif 0 + +/* + * Hypothetical platform with no float or int64 support + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#define KHRONOS_SUPPORT_INT64 0 +#define KHRONOS_SUPPORT_FLOAT 0 + +#else + +/* + * Generic fallback + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#endif + + +/* + * Types that are (so far) the same on all platforms + */ +typedef signed char khronos_int8_t; +typedef unsigned char khronos_uint8_t; +typedef signed short int khronos_int16_t; +typedef unsigned short int khronos_uint16_t; + +/* + * Types that differ between LLP64 and LP64 architectures - in LLP64, + * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears + * to be the only LLP64 architecture in current use. + */ +#ifdef KHRONOS_USE_INTPTR_T +typedef intptr_t khronos_intptr_t; +typedef uintptr_t khronos_uintptr_t; +#elif defined(_WIN64) +typedef signed long long int khronos_intptr_t; +typedef unsigned long long int khronos_uintptr_t; +#else +typedef signed long int khronos_intptr_t; +typedef unsigned long int khronos_uintptr_t; +#endif + +#if defined(_WIN64) +typedef signed long long int khronos_ssize_t; +typedef unsigned long long int khronos_usize_t; +#else +typedef signed long int khronos_ssize_t; +typedef unsigned long int khronos_usize_t; +#endif + +#if KHRONOS_SUPPORT_FLOAT +/* + * Float type + */ +typedef float khronos_float_t; +#endif + +#if KHRONOS_SUPPORT_INT64 +/* Time types + * + * These types can be used to represent a time interval in nanoseconds or + * an absolute Unadjusted System Time. Unadjusted System Time is the number + * of nanoseconds since some arbitrary system event (e.g. since the last + * time the system booted). The Unadjusted System Time is an unsigned + * 64 bit value that wraps back to 0 every 584 years. Time intervals + * may be either signed or unsigned. + */ +typedef khronos_uint64_t khronos_utime_nanoseconds_t; +typedef khronos_int64_t khronos_stime_nanoseconds_t; +#endif + +/* + * Dummy value used to pad enum types to 32 bits. + */ +#ifndef KHRONOS_MAX_ENUM +#define KHRONOS_MAX_ENUM 0x7FFFFFFF +#endif + +/* + * Enumerated boolean type + * + * Values other than zero should be considered to be true. Therefore + * comparisons should not be made against KHRONOS_TRUE. + */ +typedef enum { + KHRONOS_FALSE = 0, + KHRONOS_TRUE = 1, + KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM +} khronos_boolean_enum_t; + +#endif /* __khrplatform_h_ */ diff --git a/AUTHORS.txt b/AUTHORS.txt new file mode 100644 index 0000000..4c23901 --- /dev/null +++ b/AUTHORS.txt @@ -0,0 +1,4 @@ +askmeaboutloom +Colin Snover +cow <103213068+cow54787@users.noreply.github.com> +cow54787 <103213068+cow54787@users.noreply.github.com> diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e4ca1a..ea52edc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,152 +1,129 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -cmake_minimum_required(VERSION 3.15) - -project(drawdance +# SPDX-License-Identifier: MIT + +cmake_minimum_required(VERSION 3.18) +set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13 CACHE STRING "macOS deployment target") +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) + +project(Drawdance VERSION 0.3.0 DESCRIPTION "A Drawpile Client" LANGUAGES C CXX) -option(USE_GENERATORS "Do code generation (turn off when cross-compiling)" ON) -option(USE_ADDRESS_SANITIZER "Build with address sanitizer enabled" ON) -option(USE_CLANG_TIDY "Run clang-tidy on build" ON) -option(USE_STRICT_ALIASING "Enable strict aliasing optimizations" OFF) +include(FeatureSummary) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +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) + # Feature info will be emitted later once it is clear whether or not these + # features could actually be enabled + option(CLANG_TIDY "Automatically enable Clang-Tidy" ON) + option(ADDRESS_SANITIZER "Automatically enable AddressSanitizer" OFF) + + 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(ENABLE_WERROR "Fail the build when there's warnings" OFF) -option(ENABLE_ARCH_NATIVE "Optimize for this computer's CPU" OFF) -option(LINK_WITH_LIBM "Link with libm when using math" ON) -option(BUILD_TESTS "Build TAP tests" ON) +add_feature_info("Warning as errors (ENABLE_WERROR)" ENABLE_WERROR "") + option(BUILD_APPS "Build applications (as opposed to only libraries)" ON) -option(BUILD_TOOLS "Build command-line tools, even if BUILD_APPS is OFF" OFF) +add_feature_info("Applications (BUILD_APPS)" BUILD_APPS "") -set(IMAGE_IMPL LIBS CACHE STRING "PNG and JPEG implementation (LIBS, QT)") +option(BUILD_SHARED_LIBS "Build shared libraries" OFF) +add_feature_info("Shared libraries (BUILD_SHARED_LIBS)" BUILD_SHARED_LIBS "") -set(FILE_IO_IMPL STDIO CACHE STRING "Default file I/O (STDIO, QT)") +if(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}) + add_feature_info("Image library implementation (IMAGE_IMPL)" ON ${IMAGE_IMPL}) -set(XML_IMPL QT CACHE STRING "XML reader implementation (QT)") + set(FILE_IO_IMPL STDIO CACHE STRING "Default file I/O (STDIO, QT)") + string(TOUPPER FILE_IO_IMPL ${FILE_IO_IMPL}) + add_feature_info("File I/O implementation (FILE_IO_IMPL)" ON ${FILE_IO_IMPL}) -set(ZIP_IMPL LIBZIP CACHE STRING "ZIP folder implementation (LIBZIP, KARCHIVE)") + option(BUILD_TESTS "Build TAP tests" ON) + add_feature_info("TAP tests (BUILD_TESTS)" BUILD_TESTS "") -set(QT_VERSION 5 CACHE STRING "Qt version to use, if pulled in (5, 6)") + option(BUILD_TOOLS "Build command-line tools, even if BUILD_APPS is OFF" OFF) + add_feature_info("Tools (BUILD_TOOLS)" BUILD_TOOLS "") -if(CMAKE_CROSSCOMPILING) - message(STATUS "Cross-compiling for platform '${CMAKE_SYSTEM_NAME}'") -endif() + set(ZIP_IMPL LIBZIP CACHE STRING "ZIP folder implementation (LIBZIP, KARCHIVE)") + string(TOUPPER ZIP_IMPL ${ZIP_IMPL}) + add_feature_info("ZIP implementation (ZIP_IMPL)" ON ${ZIP_IMPL}) -if(CMAKE_TOOLCHAIN_FILE) - message(STATUS "Using toolchain file '${CMAKE_TOOLCHAIN_FILE}'") + set(QT_VERSION 5 CACHE STRING "Qt version to use, if pulled in (5, 6)") + add_feature_info("Qt version (QT_VERSION)" ON ${QT_VERSION}) endif() -include("${CMAKE_CURRENT_LIST_DIR}/cmake/address_sanitizer.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/cmake/clang_format.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/cmake/clang_tidy.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/cmake/compile_flags.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/cmake/dpconfig.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/cmake/language_standards.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/cmake/export.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/cmake/dependencies.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/cmake/tests.cmake") - -function(set_dp_target_properties target) - get_target_property(target_type "${target}" TYPE) - - if(DRAWDANCE_EMSCRIPTEN) - if(NOT "${target_type}" STREQUAL "INTERFACE_LIBRARY") - target_compile_options("${target}" PRIVATE "-pthread") - target_link_options("${target}" PRIVATE - "-pthread" "SHELL:-s PROXY_TO_PTHREAD" - "SHELL:-s ALLOW_BLOCKING_ON_MAIN_THREAD=0" - "SHELL:-s ALLOW_MEMORY_GROWTH=1" "SHELL:-s FETCH=1" - "SHELL:-s MODULARIZE=1" - "SHELL:-s EXPORT_NAME=createModule" - "SHELL:-s DYNAMIC_EXECUTION=0") - endif() - - if("${target_type}" STREQUAL "EXECUTABLE") - set_property(TARGET "${target}" PROPERTY SUFFIX ".js") - endif() - endif() - - if(NOT "NO_EXPORT" IN_LIST ARGN) - add_dp_export_target("${target}") - endif() - - if(NOT "${target_type}" STREQUAL "INTERFACE_LIBRARY") - set_language_standards("${target}") - add_address_sanitizer("${target}") - target_compile_definitions("${target}" PRIVATE - "DP_PERF_REALM=${target}" - "_XOPEN_SOURCE=600" - "_CRT_SECURE_NO_WARNINGS" - "WIN32_LEAN_AND_MEAN" - "NOMINMAX") - - if("CXX" IN_LIST ARGN) - target_compile_options("${target}" PRIVATE "${dp_cxxflags}") - else() - target_compile_options("${target}" PRIVATE "${dp_cflags}") - endif() - - if(NOT "NO_CLANG_TIDY" IN_LIST ARGN) - add_clang_tidy("${target}") - endif() - - if(NOT "NO_WARNINGS" IN_LIST ARGN) - if("CXX" IN_LIST ARGN) - target_compile_options("${target}" PRIVATE "${dp_cxxwarnings}") - else() - target_compile_options("${target}" PRIVATE "${dp_cwarnings}") - endif() - endif() - - if(NOT USE_STRICT_ALIASING) - target_compile_definitions( - "${target}" PRIVATE "DP_NO_STRICT_ALIASING") - endif() - - string(LENGTH "${PROJECT_SOURCE_DIR}/" project_dir_length) - target_compile_definitions( - "${target}" PRIVATE "DP_PROJECT_DIR_LENGTH=${project_dir_length}") - endif() -endfunction() +string(LENGTH "${PROJECT_SOURCE_DIR}/" project_dir_length) +add_compile_definitions( + "DP_PROJECT_DIR_LENGTH=${project_dir_length}" + _XOPEN_SOURCE=600 + _CRT_SECURE_NO_WARNINGS + WIN32_LEAN_AND_MEAN + NOMINMAX +) + +include(compile_flags) +include(helper) +include(dependencies) + +configure_file(cmake/dpconfig.h.in "${CMAKE_BINARY_DIR}/config/dpconfig.h") if(BUILD_TESTS) + include(tests) add_subdirectory(test) endif() + add_subdirectory(3rdparty) add_subdirectory(generators) add_subdirectory(libcommon) add_subdirectory(libmsg) add_subdirectory(libengine) + if(BUILD_APPS) add_subdirectory(libclient) - add_subdirectory(appconv) add_subdirectory(appdrawdance) -elseif(BUILD_TOOLS) +endif() + +if(BUILD_TOOLS) add_subdirectory(appconv) endif() -define_clang_format_target() -report_address_sanitizer_targets() -report_clang_tidy_targets() -report_dp_export_targets() -report_dptest_targets() +write_basic_package_version_file( + DrawdanceVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +get_property(CONFIG_DEPS GLOBAL PROPERTY dp_dependencies) +list(JOIN CONFIG_DEPS "\n" CONFIG_DEPS) +get_property(CONFIG_COMPONENTS GLOBAL PROPERTY dp_components) +configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) + +feature_summary(INCLUDE_QUIET_PACKAGES + WHAT PACKAGES_NOT_FOUND ENABLED_FEATURES DISABLED_FEATURES) -export_dp_export_targets() +if(BUILD_TESTS) + report_dptest_targets() +endif() diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 0000000..46b5dcc --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,40 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +@CONFIG_DEPS@ + +set(_supported_components @CONFIG_COMPONENTS@) + +if(NOT @PROJECT_NAME@_FIND_COMPONENTS) + set(@PROJECT_NAME@_FIND_COMPONENTS ${_supported_components}) +endif() + +# CMake autogenerated code does not correctly order intra-package dependencies, +# and like everything else in CMake it is unclear how this is supposed to +# actually work, so invert the way the docs say to manage component installs and +# iterate over the list of _supported_components and check it against the +# find_components list so the order is well-defined +list(LENGTH @PROJECT_NAME@_FIND_COMPONENTS _n_required_components) +foreach(_comp IN LISTS _supported_components) + if(_comp IN_LIST @PROJECT_NAME@_FIND_COMPONENTS) + math(EXPR _n_required_components "${_n_required_components} - 1") + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@${_comp}Targets.cmake") + endif() +endforeach() + +if(NOT _n_required_components EQUAL 0) + set(@PROJECT_NAME@_FOUND FALSE) + set(_unsupported_components) + foreach(_comp IN LISTS @PROJECT_NAME@_FIND_COMPONENTS) + if(NOT _comp IN_LIST _supported_components) + list(APPEND _unsupported_components ${_comp}) + endif() + endforeach() + set(@PROJECT_NAME@_NOT_FOUND_MESSAGE "Unsupported components: ${_unsupported_components}") +endif() + +unset(_comp) +unset(_unsupported_components) +unset(_supported_components) +unset(_n_required_components) diff --git a/appconv/CMakeLists.txt b/appconv/CMakeLists.txt index 37293ad..d335679 100644 --- a/appconv/CMakeLists.txt +++ b/appconv/CMakeLists.txt @@ -1,27 +1,11 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT -set(dpconv_sources dpconv.c) - -add_clang_format_files("${dpconv_sources}") - -add_executable(dpconv "${dpconv_sources}") -set_dp_target_properties(dpconv) -target_link_libraries(dpconv PUBLIC dpengine dpmsg) +dp_add_executable(dpconv) +target_sources(dpconv PRIVATE + dpconv.c +) +target_link_libraries(dpconv PRIVATE + dpcommon + dpengine + dpmsg +) diff --git a/appdrawdance/CMakeLists.txt b/appdrawdance/CMakeLists.txt index 5f93263..2277b1a 100644 --- a/appdrawdance/CMakeLists.txt +++ b/appdrawdance/CMakeLists.txt @@ -1,101 +1,60 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT -set(drawdance_gui_sources drawdance_gui/gui.cpp) -set(drawdance_gui_headers drawdance_gui/gui.h) - -add_clang_format_files("${drawdance_gui_sources}" "${drawdance_gui_headers}") - -add_library(drawdance_gui STATIC "${drawdance_gui_sources}" - "${drawdance_gui_headers}") -set_dp_target_properties(drawdance_gui CXX) -target_include_directories(drawdance_gui INTERFACE drawdance_gui) -target_link_libraries(drawdance_gui PUBLIC imgui dpgles2) - - -set(drawdance_lua_cxx_sources - drawdance_lua/imgui.cpp - drawdance_lua/imgui_gen.cpp) - -add_clang_format_files("${drawdance_lua_cxx_sources}") - -add_library(drawdance_lua_cxx STATIC "${drawdance_lua_cxx_sources}") -set_dp_target_properties(drawdance_lua_cxx CXX) -target_link_libraries(drawdance_lua_cxx PUBLIC dpcommon lua imgui dpgles2) - -set(drawdance_lua_sources - drawdance_lua/client.c - drawdance_lua/document.c - drawdance_lua/lua_bindings.c - drawdance_lua/message.c - drawdance_lua/ui.c) - -set(drawdance_lua_headers - drawdance_lua/lua_bindings.h - drawdance_lua/lua_util.h) - -add_clang_format_files("${drawdance_lua_sources}" "${drawdance_lua_headers}") - -add_library(drawdance_lua STATIC "${drawdance_lua_sources}" - "${drawdance_lua_headers}") -set_dp_target_properties(drawdance_lua) -target_include_directories(drawdance_lua PRIVATE "${CMAKE_BINARY_DIR}/config") -target_include_directories(drawdance_lua INTERFACE drawdance_lua) -target_link_libraries(drawdance_lua PUBLIC dpclient dpmsg lua) - -if(NOT DRAWDANCE_EMSCRIPTEN) - target_compile_definitions(drawdance_lua PRIVATE DRAWDANCE_IMGUI) - target_link_libraries(drawdance_lua PUBLIC drawdance_lua_cxx) -endif() - - -set(drawdance_sources +dp_add_executable(drawdance) +target_sources(drawdance PRIVATE drawdance/app.c - drawdance/canvas_renderer.c - drawdance/gl.c - drawdance/main.c - drawdance/ui.c) - -set(drawdance_headers drawdance/app.h + drawdance/canvas_renderer.c drawdance/canvas_renderer.h drawdance/emproxy.h + drawdance/gl.c drawdance/gl.h - drawdance/ui.h) - -add_clang_format_files("${drawdance_sources}" "${drawdance_headers}") - -add_executable(drawdance "${drawdance_sources}" "${drawdance_headers}") -set_dp_target_properties(drawdance) -target_link_libraries(drawdance PUBLIC drawdance_lua dpclient dpengine dpgles2) - -if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - target_compile_definitions(drawdance PRIVATE DP_GL_CHECKS) -endif() - -if(DRAWDANCE_EMSCRIPTEN) + drawdance/main.c + drawdance/ui.c + drawdance/ui.h + drawdance_gui/gui.cpp + drawdance_gui/gui.h + drawdance_lua/client.c + drawdance_lua/document.c + drawdance_lua/imgui.cpp + drawdance_lua/imgui_gen.cpp + drawdance_lua/lua_bindings.c + drawdance_lua/lua_bindings.h + drawdance_lua/lua_util.h + drawdance_lua/message.c + drawdance_lua/ui.c +) +target_include_directories(drawdance PRIVATE + drawdance + drawdance_gui + drawdance_lua + "${CMAKE_BINARY_DIR}/config" +) +target_link_libraries(drawdance PRIVATE + dpcommon + dpclient + dpengine + dpmsg + lua + parson + imgui + dpgles2 + SDL2::SDL2 +) +target_compile_definitions(drawdance PRIVATE $<$:DP_GL_CHECKS>) + +if(EMSCRIPTEN) target_link_options(drawdance PRIVATE - "SHELL:-s EXPORTED_FUNCTIONS=_main,_DP_send_from_browser" - "SHELL:-s EXPORTED_RUNTIME_METHODS=ALLOC_NORMAL,allocate,intArrayFromString" - "SHELL:--preload-file '${CMAKE_SOURCE_DIR}/appdrawdance/lua@appdrawdance/lua'") + "-sPROXY_TO_PTHREAD" + "-sALLOW_BLOCKING_ON_MAIN_THREAD=0" + "-sALLOW_MEMORY_GROWTH=1" + "-sMODULARIZE=1" + "-sEXPORT_NAME=createModule" + "-sDYNAMIC_EXECUTION=0" + "-sEXPORTED_FUNCTIONS=_main,_DP_send_from_browser" + "-sEXPORTED_RUNTIME_METHODS=ALLOC_NORMAL,allocate,intArrayFromString" + "--preload-file=${CMAKE_SOURCE_DIR}/appdrawdance/lua@appdrawdance/lua" + ) else() target_compile_definitions(drawdance PRIVATE DRAWDANCE_IMGUI) - target_link_libraries(drawdance PUBLIC drawdance_gui) endif() diff --git a/appdrawdance/drawdance_lua/ui.c b/appdrawdance/drawdance_lua/ui.c index 7710420..fe79f1e 100644 --- a/appdrawdance/drawdance_lua/ui.c +++ b/appdrawdance/drawdance_lua/ui.c @@ -533,7 +533,9 @@ int DP_lua_ui_init(lua_State *L) DP_LUA_SET_ENUM(KMOD_, NUM); DP_LUA_SET_ENUM(KMOD_, CAPS); DP_LUA_SET_ENUM(KMOD_, MODE); +#if SDL_VERSION_ATLEAST(2, 0, 22) DP_LUA_SET_ENUM(KMOD_, SCROLL); +#endif DP_LUA_SET_ENUM(KMOD_, CTRL); DP_LUA_SET_ENUM(KMOD_, SHIFT); DP_LUA_SET_ENUM(KMOD_, ALT); diff --git a/cmake/address_sanitizer.cmake b/cmake/address_sanitizer.cmake deleted file mode 100644 index e56e5ff..0000000 --- a/cmake/address_sanitizer.cmake +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -if(USE_ADDRESS_SANITIZER) - if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") - set(dp_asan_options -fno-omit-frame-pointer -fsanitize=address) - message(STATUS "Using address sanitizer for gcc/clang " - "via options '${dp_asan_options}'") - else() - message(STATUS "Don't know how to enable address " - "sanitizer on ${CMAKE_C_COMPILER_ID}") - endif() -else() - message(STATUS "Not using address sanitizer, as requested") -endif() - -function(add_address_sanitizer target) - if(dp_asan_options) - set_property(GLOBAL APPEND PROPERTY dp_asan_targets "${target}") - target_compile_definitions("${target}" PRIVATE "DP_ADDRESS_SANITIZER") - target_compile_options("${target}" PRIVATE ${dp_asan_options}) - target_link_options("${target}" PRIVATE ${dp_asan_options}) - endif() -endfunction() - -function(report_address_sanitizer_targets) - get_property(targets GLOBAL PROPERTY dp_asan_targets) - message(STATUS "Targets with address sanitizer: ${targets}") -endfunction() diff --git a/cmake/clang_format.cmake b/cmake/clang_format.cmake deleted file mode 100644 index 2479ef9..0000000 --- a/cmake/clang_format.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -function(add_clang_format_files) - foreach(path IN LISTS ARGN) - set_property(GLOBAL APPEND PROPERTY dp_clang_format_files - "${CMAKE_CURRENT_LIST_DIR}/${path}") - endforeach() -endfunction() - -function(define_clang_format_target) - find_program(clang_format NAMES "clang-format") - if(clang_format) - message(STATUS "Using clang-format at ${clang_format}") - message(STATUS "Invoke target 'clang-format' to format code") - get_property(files GLOBAL PROPERTY dp_clang_format_files) - add_custom_target(clang-format COMMAND "${clang_format}" -i ${files}) - else() - message(STATUS "Did not find clang-format") - endif() -endfunction() diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake deleted file mode 100644 index 98dbfe9..0000000 --- a/cmake/clang_tidy.cmake +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -if(USE_CLANG_TIDY) - find_program(dp_clang_tidy NAMES "clang-tidy") - if(dp_clang_tidy) - message(STATUS "Using clang-tidy at ${dp_clang_tidy}") - else() - message(STATUS "Did not find clang-tidy, linting disabled") - endif() -else() - message(STATUS "Not using clang-tidy, as requested") -endif() - -function(add_clang_tidy target) - if(dp_clang_tidy) - set_property(GLOBAL APPEND PROPERTY dp_clang_tidy_targets "${target}") - set_target_properties("${target}" PROPERTIES - C_CLANG_TIDY "${dp_clang_tidy}") - endif() -endfunction() - -function(report_clang_tidy_targets) - get_property(targets GLOBAL PROPERTY dp_clang_tidy_targets) - message(STATUS "Targets with clang-tidy: ${targets}") -endfunction() diff --git a/cmake/compile_flags.cmake b/cmake/compile_flags.cmake index c30e144..7244d2c 100644 --- a/cmake/compile_flags.cmake +++ b/cmake/compile_flags.cmake @@ -1,57 +1,135 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") - unset(dp_common_cflags) - set(dp_common_warnings -pedantic -Wall -Wextra -Wshadow - -Wmissing-include-dirs -Wconversion) +# SPDX-License-Identifier: MIT +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +if(EMSCRIPTEN) + set(CMAKE_EXECUTABLE_SUFFIX ".js") + # This is required to use CMAKE_PREFIX_PATH for find_package in config mode, + # otherwise it will only look in the emscripten sysroot cache + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ON) + # 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(MSVC) + # C4100: unreferenced formal parameter + # - MSVC has no `__attribute__((unused))` and parameter names are not + # omitted from the code + # C4200: nonstandard extension used: zero-sized array in struct/union + # - MSVC does not recognise C99 flexible array members as standard + # C4127: conditional expression is constant + # - macros from cthash emit `do {} while(0);` and this triggers on + # `while(0)` + # C4702: unreachable code + # - macros from cthash causing problems again + add_compile_options(/utf-8 /W4 /wn4100 /wn4200 /wn4127 /wn4702) if(ENABLE_WERROR) - list(APPEND dp_common_warnings -pedantic-errors -Werror -Wno-error=unused-parameter) + add_compile_options(/WX) + add_link_options(/WX:NO) endif() - # When LTO is enabled, CMake will try to pass -fno-fat-lto-objects, which in - # turn causes clang-tidy to spew a warning about not understanding it, which - # fails the compilation due to -Werror. We have to turn off the ignored - # optimization argument warning entirely, -Wno-error doesn't work with GCC - # in turn because it doesn't know that warning and dies because of it. At - # the time of writing, there's no way to make CMake not pass that flag. - if(CMAKE_INTERPROCEDURAL_OPTIMIZATION AND dp_clang_tidy) - list(APPEND dp_common_warnings -Wno-ignored-optimization-argument) + # https://github.com/mozilla/sccache/pull/963 + if(CMAKE_C_COMPILER_LAUNCHER MATCHES "sccache") + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") + endif() endif() + if(CMAKE_CXX_COMPILER_LAUNCHER MATCHES "sccache") + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + endif() + endif() +else() + add_compile_options( + -Wpedantic -Wall -Wextra -Wshadow + -Wmissing-include-dirs -Wconversion + $<$:-fno-exceptions> + $<$:-Wstrict-prototypes> + ) if(NOT USE_STRICT_ALIASING) - list(APPEND dp_common_cflags -fno-strict-aliasing) + add_compile_options(-fno-strict-aliasing) + add_compile_definitions(DP_NO_STRICT_ALIASING) endif() if(ENABLE_ARCH_NATIVE) - list(APPEND dp_common_cflags -march=native) + add_compile_options(-march=native) + endif() +endif() + +if(CLANG_TIDY) + get_property(enabled_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + foreach(lang IN LISTS enabled_languages) + if(NOT CMAKE_${lang}_CLANG_TIDY) + if(NOT DEFINED clang_tidy_exe) + set(clang_tidy_names clang-tidy) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + string(REGEX MATCH "^([0-9]+)" clang_tidy_version_matched "${CMAKE_CXX_COMPILER_VERSION}") + if(CMAKE_MATCH_1) + list(PREPEND clang_tidy_names "clang-tidy-${CMAKE_MATCH_1}") + endif() + endif() + find_program(clang_tidy_exe NAMES ${clang_tidy_names}) + endif() + if(clang_tidy_exe) + set(CMAKE_${lang}_CLANG_TIDY "${clang_tidy_exe}") + list(APPEND IGNORE_TIDY_PROPERTY_NAMES ${lang}_CLANG_TIDY) + endif() + endif() + endforeach() + unset(enabled_languages) + unset(clang_tidy_exe) +endif() +add_feature_info("Clang-Tidy (CLANG_TIDY)" CMAKE_CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY}") + +if(ADDRESS_SANITIZER) + include(CheckLinkerFlag) + check_linker_flag(CXX "-fsanitize=address" HAVE_SANITIZE_ADDRESS) + if(HAVE_SANITIZE_ADDRESS) + # In at least CMake 3.19, `add_compile_options` flags are used by + # `try_compile` but `add_link_options` flags are not, so to prevent + # accidental failures of feature detection caused by ASan linker + # failures, explicitly set `CMAKE_EXE_LINKER_FLAGS` instead, which does + # get used by `try_compile`. + # Also, this variable is treated as a string, not a list, so using + # `list(APPEND)` would break the compiler. + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address") + add_compile_options(-fno-omit-frame-pointer -fsanitize=address) + else() + set(ADDRESS_SANITIZER OFF) endif() +endif() +add_feature_info("AddressSanitizer (ADDRESS_SANITIZER)" ADDRESS_SANITIZER "") + +# When LTO is enabled, CMake will try to pass -fno-fat-lto-objects, which in +# turn causes clang-tidy to spew a warning about not understanding it, which +# fails the compilation due to -Werror. We have to turn off the ignored +# optimization argument warning entirely, -Wno-error doesn't work with GCC +# in turn because it doesn't know that warning and dies because of it. At +# the time of writing, there's no way to make CMake not pass that flag. +if(CMAKE_INTERPROCEDURAL_OPTIMIZATION AND CMAKE_CXX_CLANG_TIDY) + add_compile_options(-Wno-ignored-optimization-argument) +endif() - set(dp_cflags ${dp_common_cflags}) - set(dp_cxxflags ${dp_common_cflags} -fno-exceptions -fms-extensions) # c++ anonymous struct is an MS extension - set(dp_cwarnings ${dp_common_warnings} -Wstrict-prototypes) - set(dp_cxxwarnings ${dp_common_warnings}) -elseif(CMAKE_C_COMPILER MATCHES "MSVC") - unset(dp_common_cflags) - set(dp_common_cflags "/utf-8") - set(dp_cflags ${dp_common_cflags}) - set(dp_cxxflags ${dp_common_cflags}) +if(MSVC) + 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})" "/wn\\1") +else() + get_directory_property(IGNORE_WARNINGS_COMPILE_OPTIONS COMPILE_OPTIONS) + list(TRANSFORM IGNORE_WARNINGS_COMPILE_OPTIONS REPLACE "-W(no-)?([^=]+)(=.*$)?" "-Wno-\\2") endif() diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 648e761..79b0d00 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -1,77 +1,35 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT -if(DRAWDANCE_EMSCRIPTEN) - add_library(empng INTERFACE) - add_library(PNG::PNG ALIAS empng) - target_compile_options(empng INTERFACE "SHELL:-s USE_LIBPNG=1" - "SHELL:-sUSE_ZLIB=1") - target_link_options(empng INTERFACE "SHELL:-s USE_LIBPNG=1" - "SHELL:-s USE_ZLIB=1") - add_dp_export_target(empng) +dp_find_package(ZLIB MODULE REQUIRED) - add_library(emsdl2 INTERFACE) - add_library(SDL2::SDL2 ALIAS emsdl2) - target_compile_options(emsdl2 INTERFACE "SHELL:-s USE_SDL=2") - target_link_options(emsdl2 INTERFACE "SHELL:-s USE_SDL=2") - target_include_directories(emsdl2 INTERFACE - "${CMAKE_SOURCE_DIR}/cmake/emsdl2") - add_dp_export_target(emsdl2) - - add_library(emthreads INTERFACE) - add_library(Threads::Threads ALIAS emthreads) - add_dp_export_target(emthreads) - # Need to compile and link all targets with -pthreads so that they actually - # link together in the end, so this target does nothing on Emscripten. - # The set_dp_target_properties function sets the flag on all targets. -else() - find_package(ZLIB MODULE REQUIRED) - - if("${IMAGE_IMPL}" STREQUAL "LIBS") - find_package(PNG MODULE REQUIRED) - find_package(JPEG MODULE REQUIRED) - elseif("${IMAGE_IMPL}" STREQUAL "QT") - find_package("Qt${QT_VERSION}" COMPONENTS Gui REQUIRED) - endif() +if(IMAGE_IMPL STREQUAL "LIBS") + dp_find_package(PNG REQUIRED) + dp_find_package(JPEG REQUIRED) +elseif(IMAGE_IMPL STREQUAL "QT") + dp_find_package("Qt${QT_VERSION}" COMPONENTS Gui REQUIRED) +endif() - if(NOT WIN32) - set(THREADS_PREFER_PTHREAD_FLAG TRUE) - find_package(Threads REQUIRED) - endif() +if(NOT WIN32) + dp_find_package(Threads REQUIRED) +endif() - if("${XML_IMPL}" STREQUAL "QT") - find_package("Qt${QT_VERSION}" COMPONENTS Xml REQUIRED) - endif() +if(NOT EMSCRIPTEN) + dp_find_package("Qt${QT_VERSION}" COMPONENTS Xml REQUIRED) - if("${ZIP_IMPL}" STREQUAL "LIBZIP") - find_package(libzip REQUIRED) - elseif("${ZIP_IMPL}" STREQUAL "KARCHIVE") - find_package(KF5Archive REQUIRED) + if(ZIP_IMPL STREQUAL "LIBZIP") + dp_find_package(libzip REQUIRED) + elseif(ZIP_IMPL STREQUAL "KARCHIVE") + dp_find_package(KF5Archive REQUIRED) endif() +endif() - if(BUILD_APPS) - find_package(SDL2 REQUIRED) - find_package(CURL MODULE REQUIRED COMPONENTS HTTPS HTTP SSL) +if(BUILD_APPS) + dp_find_package(SDL2 REQUIRED) + if(NOT EMSCRIPTEN) + dp_find_package(CURL REQUIRED COMPONENTS HTTPS HTTP SSL) endif() +endif() - if(USE_GENERATORS) - find_package("Qt${QT_VERSION}" COMPONENTS Core Gui) - endif() +if(USE_GENERATORS) + dp_find_package("Qt${QT_VERSION}" COMPONENTS Core Gui) endif() diff --git a/cmake/dpconfig.cmake b/cmake/dpconfig.cmake deleted file mode 100644 index 348e283..0000000 --- a/cmake/dpconfig.cmake +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -set(dpconfig_h "${CMAKE_BINARY_DIR}/config/dpconfig.h") -configure_file(cmake/dpconfig.tpl.h "${dpconfig_h}") diff --git a/cmake/dpconfig.tpl.h b/cmake/dpconfig.h.in similarity index 100% rename from cmake/dpconfig.tpl.h rename to cmake/dpconfig.h.in diff --git a/cmake/emscripten.cmake b/cmake/emscripten.cmake deleted file mode 100644 index e591b38..0000000 --- a/cmake/emscripten.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -set(DRAWDANCE_EMSCRIPTEN ON CACHE BOOL OFF FORCE) -set(CMAKE_SYSTEM_NAME Generic CACHE STRING "" FORCE) -set(CMAKE_C_COMPILER_ID Clang CACHE STRING "" FORCE) -set(CMAKE_CXX_COMPILER_ID Clang CACHE STRING "" FORCE) -set(CMAKE_C_COMPILER_VERSION 11.1.0 CACHE STRING "" FORCE) -set(CMAKE_CXX_COMPILER_VERSION 11.1.0 CACHE STRING "" FORCE) -set(CMAKE_C_STANDARD_COMPUTED_DEFAULT 17 CACHE STRING "" FORCE) -set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT 17 CACHE STRING "" FORCE) diff --git a/cmake/emsdl2/SDL.h b/cmake/emsdl2/SDL.h deleted file mode 100644 index 577fdf4..0000000 --- a/cmake/emsdl2/SDL.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/cmake/emsdl2/SDL_timer.h b/cmake/emsdl2/SDL_timer.h deleted file mode 100644 index 9c810db..0000000 --- a/cmake/emsdl2/SDL_timer.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/cmake/export.cmake b/cmake/export.cmake deleted file mode 100644 index 9720611..0000000 --- a/cmake/export.cmake +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -function(add_dp_export_target target) - set_property(GLOBAL APPEND PROPERTY dp_export_targets "${target}") -endfunction() - -function(report_dp_export_targets) - get_property(targets GLOBAL PROPERTY dp_export_targets) - message(STATUS "Export targets: ${targets}") -endfunction() - -function(export_dp_export_targets) - get_property(targets GLOBAL PROPERTY dp_export_targets) - export(TARGETS ${targets} NAMESPACE Drawdance:: FILE Drawdance.cmake) -endfunction() diff --git a/cmake/helper.cmake b/cmake/helper.cmake new file mode 100644 index 0000000..1ad2022 --- /dev/null +++ b/cmake/helper.cmake @@ -0,0 +1,85 @@ +# SPDX-License-Identifier: MIT + +function(dp_add_executable target) + add_executable(${target}) + + install(TARGETS ${target} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ) +endfunction() + +function(dp_add_library target) + add_library(${target}) + add_library(${PROJECT_NAME}::${target} ALIAS ${target}) + + set_property(GLOBAL APPEND PROPERTY dp_components "${target}") + + 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} + ) +endfunction() + +function(dp_find_package) + if(EMSCRIPTEN) + dp_find_package_emscripten(${ARGV}) + else() + find_package(${ARGV}) + endif() + + list(JOIN ARGV " " dep) + set_property(GLOBAL APPEND PROPERTY dp_dependencies "find_dependency(${dep})") +endfunction() + +function(dp_find_package_emscripten name) + cmake_parse_arguments(PARSE_ARGV 1 ARG "" "" "COMPONENTS") + + if(name STREQUAL "Threads") + add_library(${name}::${name} INTERFACE IMPORTED) + set_target_properties(${name}::${name} PROPERTIES + INTERFACE_COMPILE_OPTIONS "-pthread" + INTERFACE_LINK_LIBRARIES "-pthread" + ) + return() + elseif(name STREQUAL "SDL2") + set(use SDL=2) + elseif(name STREQUAL "ZLIB") + set(use ZLIB=1) + elseif(name STREQUAL "PNG") + set(use LIBPNG) + elseif(name STREQUAL "JPEG") + set(use LIBJPEG=1) + else() + find_package(${ARGV}) + return() + endif() + + foreach(component IN LISTS ARG_COMPONENTS ITEMS ${name}) + add_library(${name}::${component} INTERFACE IMPORTED) + set_target_properties(${name}::${component} PROPERTIES + INTERFACE_COMPILE_OPTIONS "-sUSE_${use}" + INTERFACE_LINK_LIBRARIES "-sUSE_${use}" + ) + endforeach() +endfunction() + +function(dp_target_sources target) + target_sources(${target} PRIVATE ${ARGN}) + foreach(file IN LISTS ARGN) + if(file MATCHES "(\\.[Hh]([Pp][Pp])?|include[\\/][^.]*)$") + install( + FILES "${file}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${target}" + ) + endif() + endforeach() +endfunction() diff --git a/cmake/language_standards.cmake b/cmake/language_standards.cmake deleted file mode 100644 index afd31b6..0000000 --- a/cmake/language_standards.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -function(set_language_standards target) - set_target_properties("${target}" PROPERTIES - C_STANDARD 11 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF - CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF) -endfunction() diff --git a/cmake/tests.cmake b/cmake/tests.cmake index bbe55ef..3f6b6c4 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -1,49 +1,27 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT -if(BUILD_TESTS) - enable_testing() +enable_testing() - function(add_dptest_targets type lib tests) - foreach(test_file IN LISTS "${tests}") - get_filename_component(test_file_name "${test_file}" NAME_WE) - set(test_name "dp${type}_${test_file_name}_test") +function(add_dptest_targets type lib tests) + foreach(test_file IN LISTS "${tests}") + get_filename_component(test_file_name "${test_file}" NAME_WE) + set(test_name "dp${type}_${test_file_name}_test") - add_executable("${test_name}" "${test_file}") - set_dp_target_properties("${test_name}" NO_EXPORT) - target_link_libraries("${test_name}" PUBLIC "dp${type}" "${lib}") + add_executable("${test_name}" "${test_file}") + target_include_directories("${test_name}" PRIVATE + "${CMAKE_SOURCE_DIR}/test/dptest" + ) + target_link_libraries("${test_name}" PRIVATE "dp${type}" "${lib}") - add_test(NAME "${test_name}" COMMAND "${test_name}" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") + add_test(NAME "${test_name}" COMMAND "${test_name}" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") - set_property(GLOBAL APPEND PROPERTY dptest_targets "${test_name}") - endforeach() - endfunction() -else() - # Trying to add tests when not enabled is a mistake in the build script. - function(add_dptest_targets) - message(FATAL_ERROR "add_dptest_targets called, but BUILD_TESTS is off") - endfunction() -endif() + set_property(GLOBAL APPEND PROPERTY dptest_targets "${test_name}") + endforeach() +endfunction() function(report_dptest_targets) get_property(targets GLOBAL PROPERTY dptest_targets) - message(STATUS "Test targets: ${targets}") + list(JOIN targets "\n * " targets) + message(STATUS "The following tests have been enabled: \n\n * ${targets}\n") endfunction() diff --git a/generators/CMakeLists.txt b/generators/CMakeLists.txt index 4134776..bc25286 100644 --- a/generators/CMakeLists.txt +++ b/generators/CMakeLists.txt @@ -1,40 +1,16 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -add_clang_format_files( - generate_conversions.c - qt_premul_factors.cpp) - +# SPDX-License-Identifier: MIT if(USE_GENERATORS) add_executable(generate_conversions generate_conversions.c) - set_dp_target_properties(generate_conversions) - if("${QT${QT_VERSION}_FOUND}") - add_executable(qt_image_resize qt_image_resize.cpp) - set_dp_target_properties(qt_image_resize CXX) + if(TARGET Qt${QT_VERSION}::Gui) + add_executable(qt_image_resize) + target_sources(qt_image_resize PRIVATE qt_image_resize.cpp) target_link_libraries(qt_image_resize "Qt${QT_VERSION}::Gui") if("${QT_VERSION}" EQUAL 5) - add_executable(qt_premul_factors qt_premul_factors.cpp) - set_dp_target_properties(qt_premul_factors CXX) + add_executable(qt_premul_factors) + target_sources(qt_premul_factors PRIVATE qt_premul_factors.cpp) target_link_libraries(qt_premul_factors Qt5::Gui) else() message(STATUS "Not building qt_premul_factors generator since it " diff --git a/libclient/CMakeLists.txt b/libclient/CMakeLists.txt index 33722f2..c470ae5 100644 --- a/libclient/CMakeLists.txt +++ b/libclient/CMakeLists.txt @@ -1,56 +1,43 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT -set(dpclient_sources +dp_add_library(dpclient) +dp_target_sources(dpclient dpclient/client.c - dpclient/document.c - dpclient/uri_utils.c) - -set(dpclient_headers dpclient/client.h - dpclient/client_internal.h + dpclient/document.c dpclient/document.h dpclient/ext_auth.h - dpclient/uri_utils.h) - -add_clang_format_files( - "${dpclient_sources}" "${dpclient_headers}" - dpclient/ext_auth.c dpclient/ext_auth_em.c - dpclient/tcp_socket_client.c dpclient/tcp_socket_client.h - dpclient/web_socket_client.c dpclient/web_socket_client.h) - -if(DRAWDANCE_EMSCRIPTEN) - list(APPEND dpclient_sources dpclient/web_socket_client.c dpclient/ext_auth_em.c) - list(APPEND dpclient_headers dpclient/web_socket_client.h) -else() - list(APPEND dpclient_sources dpclient/tcp_socket_client.c dpclient/ext_auth.c) - list(APPEND dpclient_headers dpclient/tcp_socket_client.h) -endif() + dpclient/uri_utils.c + dpclient/uri_utils.h +) +target_sources(dpclient PRIVATE + dpclient/client_internal.h +) -add_library(dpclient STATIC "${dpclient_sources}" "${dpclient_headers}") -set_dp_target_properties(dpclient) -target_include_directories(dpclient INTERFACE "${CMAKE_CURRENT_LIST_DIR}") -target_link_libraries(dpclient PUBLIC dpengine SDL2::SDL2 uriparser) +target_include_directories(dpclient PUBLIC + $ + $ +) +target_link_libraries(dpclient PRIVATE + dpcommon + dpmsg + dpengine + SDL2::SDL2 + $ +) -if(DRAWDANCE_EMSCRIPTEN) - target_link_options(dpclient PUBLIC "-lwebsocket.js") +if(EMSCRIPTEN) + dp_target_sources(dpclient + dpclient/ext_auth_em.c + dpclient/web_socket_client.c + dpclient/web_socket_client.h + ) + target_link_options(dpclient PUBLIC -sFETCH -lwebsocket.js) else() - target_link_libraries(dpclient PUBLIC CURL::libcurl) + dp_target_sources(dpclient + dpclient/ext_auth.c + dpclient/tcp_socket_client.c + dpclient/tcp_socket_client.h + ) + target_link_libraries(dpclient PRIVATE CURL::libcurl) endif() diff --git a/libclient/dpclient/document.c b/libclient/dpclient/document.c index e673d6f..384f72a 100644 --- a/libclient/dpclient/document.c +++ b/libclient/dpclient/document.c @@ -86,7 +86,7 @@ DP_Document *DP_document_new(void) DP_document_free(doc); return NULL; } - if (!(doc->canvas_history = DP_canvas_history_new(NULL, NULL))) { + if (!(doc->canvas_history = DP_canvas_history_new(NULL, NULL, false, NULL))) { DP_document_free(doc); return NULL; } diff --git a/libclient/dpclient/tcp_socket_client.c b/libclient/dpclient/tcp_socket_client.c index 45057c4..80810a9 100644 --- a/libclient/dpclient/tcp_socket_client.c +++ b/libclient/dpclient/tcp_socket_client.c @@ -244,6 +244,14 @@ static void run_send(void *data) NULL); int sockfd = DP_atomic_get(&tsc->socket); + int sendflag = 0; +# if defined(SO_NOSIGPIPE) + int set = 1; + setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(set)); +# elif defined(MSG_NOSIGNAL) + // Use flag NOSIGNAL on send call + sendflag = MSG_NOSIGNAL; +# endif DP_Queue *queue = &tsc->queue; DP_Mutex *mutex_queue = tsc->mutex_queue; DP_Semaphore *sem_queue = tsc->sem_queue; @@ -267,7 +275,7 @@ static void run_send(void *data) size_t sent = 0; do { ssize_t result = - send(sockfd, buffer + sent, length - sent, MSG_NOSIGNAL); + send(sockfd, buffer + sent, length - sent, sendflag); if (result >= 0) { sent += (size_t)result; } diff --git a/libcommon/CMakeLists.txt b/libcommon/CMakeLists.txt index 9a4728b..affb59d 100644 --- a/libcommon/CMakeLists.txt +++ b/libcommon/CMakeLists.txt @@ -1,22 +1,4 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT if(USE_GENERATORS) add_custom_command( @@ -25,7 +7,8 @@ if(USE_GENERATORS) ARGS "${CMAKE_SOURCE_DIR}/libcommon/dpcommon/conversions.h") endif() -set(dpcommon_sources +dp_add_library(dpcommon) +dp_target_sources(dpcommon dpcommon/atomic.c dpcommon/base64.c dpcommon/binary.c @@ -40,9 +23,7 @@ set(dpcommon_sources dpcommon/queue.c dpcommon/threading_common.c dpcommon/vector.c - dpcommon/worker.c) - -set(dpcommon_headers + dpcommon/worker.c dpcommon/atomic.h dpcommon/base64.h dpcommon/binary.h @@ -60,45 +41,33 @@ set(dpcommon_headers dpcommon/queue.h dpcommon/threading.h dpcommon/vector.h - dpcommon/worker.h) - -set(dpcommon_tests - test/base64.c - test/file.c - test/queue.c - test/rect.c - test/vector.c) - -set(dpcommon_qt_io_sources - dpcommon/input_qt.cpp - dpcommon/output_qt.cpp) - -set(dpcommon_qt_io_headers - dpcommon/input_qt.h - dpcommon/output_qt.h) - -add_clang_format_files("${dpcommon_sources}" "${dpcommon_headers}" - "${dpcommon_tests}" "${dpcommon_qt_io_sources}" "${dpcommon_qt_io_headers}" - dpcommon/threading_pthread.c dpcommon/threading_qt.cpp - dpcommon/threading_sdl.c) + dpcommon/worker.h +) if(WIN32) - list(APPEND dpcommon_sources dpcommon/threading_win32.c) + target_sources(dpcommon PRIVATE dpcommon/threading_win32.c) else() - list(APPEND dpcommon_sources dpcommon/threading_pthread.c) + target_sources(dpcommon PRIVATE dpcommon/threading_pthread.c) endif() -add_library(dpcommon STATIC "${dpcommon_sources}" "${dpcommon_headers}") -set_dp_target_properties(dpcommon) -target_include_directories(dpcommon INTERFACE "${CMAKE_CURRENT_LIST_DIR}") -target_link_libraries(dpcommon PUBLIC ZLIB::ZLIB) +if(APPLE) + # for _SC_NPROCESSORS_ONLN + target_compile_definitions(dpcommon PRIVATE _DARWIN_C_SOURCE) +endif() + +target_include_directories(dpcommon PUBLIC + $ + $ +) + +target_link_libraries(dpcommon PRIVATE ZLIB::ZLIB) if(NOT WIN32) - target_link_libraries(dpcommon PUBLIC Threads::Threads) + target_link_libraries(dpcommon PRIVATE Threads::Threads) endif() include(TestBigEndian) -TEST_BIG_ENDIAN(IS_BIG_ENDIAN) +test_big_endian(IS_BIG_ENDIAN) if(IS_BIG_ENDIAN) target_compile_definitions(dpcommon PUBLIC DP_BYTE_ORDER=2) @@ -106,25 +75,28 @@ else() target_compile_definitions(dpcommon PUBLIC DP_BYTE_ORDER=1) endif() -if("${FILE_IO_IMPL}" STREQUAL "STDIO") - # Nothing to do. -elseif("${FILE_IO_IMPL}" STREQUAL "QT") - add_library(dpcommon_qt_io STATIC - "${dpcommon_qt_io_sources}" "${dpcommon_qt_io_headers}") - set_dp_target_properties(dpcommon_qt_io CXX) - target_link_libraries( - dpcommon_qt_io PUBLIC dpcommon "Qt${QT_VERSION}::Core") - target_compile_definitions(dpcommon PUBLIC DP_QT_IO=1) - target_link_libraries(dpcommon PUBLIC dpcommon_qt_io) +target_compile_definitions(dpcommon PUBLIC DP_PERF_REALM=$) - if("${ZIP_IMPL}" STREQUAL "KARCHIVE") - target_compile_definitions(dpcommon PUBLIC DP_QT_IO_KARCHIVE=1) - target_link_libraries(dpcommon PUBLIC KF5::Archive) +if(FILE_IO_IMPL STREQUAL "QT") + target_compile_definitions(dpcommon PUBLIC DP_QT_IO) + dp_target_sources(dpcommon + dpcommon/input_qt.cpp + dpcommon/input_qt.h + dpcommon/output_qt.cpp + dpcommon/output_qt.h + ) + target_link_libraries(dpcommon PRIVATE "Qt${QT_VERSION}::Core") + + if(ZIP_IMPL STREQUAL "KARCHIVE") + target_compile_definitions(dpcommon PUBLIC DP_QT_IO_KARCHIVE) + target_link_libraries(dpcommon PRIVATE KF5::Archive) endif() -else() +elseif(NOT FILE_IO_IMPL STREQUAL "STDIO") message(SEND_ERROR "Unknown FILE_IO_IMPL value '${FILE_IO_IMPL}'") endif() if(BUILD_TESTS) - add_dptest_targets(common dptest dpcommon_tests) + add_dptest_targets(common dptest + "test/base64.c;test/file.c;test/queue.c;test/rect.c;test/vector.c" + ) endif() diff --git a/libcommon/dpcommon/threading.h b/libcommon/dpcommon/threading.h index ad8642e..82e9c42 100644 --- a/libcommon/dpcommon/threading.h +++ b/libcommon/dpcommon/threading.h @@ -32,6 +32,9 @@ typedef int DP_ThreadId; #elif defined(__ANDROID__) typedef long DP_ThreadId; # define DP_THREAD_ID_FMT "ld" +#elif defined(__EMSCRIPTEN_PTHREADS__) +typedef void * DP_ThreadId; +# define DP_THREAD_ID_FMT "p" #else typedef unsigned long long DP_ThreadId; # define DP_THREAD_ID_FMT "llu" diff --git a/libengine/CMakeLists.txt b/libengine/CMakeLists.txt index 510cd03..17292bf 100644 --- a/libengine/CMakeLists.txt +++ b/libengine/CMakeLists.txt @@ -1,24 +1,7 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT -set(dpengine_sources +dp_add_library(dpengine) +dp_target_sources(dpengine dpengine/affected_area.c dpengine/annotation.c dpengine/annotation_list.c @@ -35,6 +18,7 @@ set(dpengine_sources dpengine/flood_fill.c dpengine/frame.c dpengine/image.c + dpengine/image_base.c dpengine/image_transform.c dpengine/layer_content.c dpengine/layer_group.c @@ -42,7 +26,6 @@ set(dpengine_sources dpengine/layer_props.c dpengine/layer_props_list.c dpengine/layer_routes.c - dpengine/load.c dpengine/model_changes.c dpengine/ops.c dpengine/paint.c @@ -50,14 +33,11 @@ set(dpengine_sources dpengine/pixels.c dpengine/player.c dpengine/recorder.c - dpengine/save.c dpengine/snapshots.c dpengine/tile.c dpengine/tile_iterator.c dpengine/timeline.c - dpengine/view_mode.c) - -set(dpengine_headers + dpengine/view_mode.c dpengine/affected_area.h dpengine/annotation.h dpengine/annotation_list.h @@ -83,7 +63,6 @@ set(dpengine_headers dpengine/layer_props.h dpengine/layer_props_list.h dpengine/layer_routes.h - dpengine/load.h dpengine/model_changes.h dpengine/ops.h dpengine/paint.h @@ -91,91 +70,115 @@ set(dpengine_headers dpengine/pixels.h dpengine/player.h dpengine/recorder.h - dpengine/save.h dpengine/snapshots.h dpengine/tile.h dpengine/tile_iterator.h dpengine/timeline.h dpengine/view_mode.h - dpengine/xml_stream.h - dpengine/zip_archive.h) - -set(dptest_engine_sources test/dptest/dptest_engine.c) -set(dptest_engine_headers test/dptest/dptest_engine.h) - -set(dpengine_tests - test/handle_annotations.c - test/handle_layers.c - test/handle_metadata.c - test/handle_timeline.c - test/image_thumbnail.c - test/model_changes.c - test/read_write_image.c - test/render_recording.c - test/resize_image.c) - -set(dpengine_clang_format_files "${dpengine_sources}" "${dpengine_headers}" - "${dptest_engine_sources}" - "${dptest_engine_headers}" "${dpengine_tests}" - dpengine/image_base.c dpengine/image_jpeg.c - dpengine/image_png.c dpengine/image_qt.cpp - dpengine/xml_stream_qt.cpp - dpengine/zip_archive_karchive.cpp - dpengine/zip_archive_libzip.c - test/resize_image.h) - -add_clang_format_files("${dpengine_clang_format_files}") - -if("${XML_IMPL}" STREQUAL "QT") - add_library(dpengine_xml STATIC dpengine/xml_stream_qt.cpp) - set_dp_target_properties(dpengine_xml CXX) - target_link_libraries(dpengine_xml PUBLIC dpcommon "Qt${QT_VERSION}::Xml") -else() - message(SEND_ERROR "Unknown XML_IMPL value '${XML_IMPL}'") +) + +target_include_directories(dpengine + PUBLIC + $ + $ + PRIVATE + $ +) +target_link_libraries(dpengine PRIVATE + $ + $ + $ + $ + $ + dpmsg + dpcommon +) + +# Qt is too heavy a dependency just for an XML parser, libzip has to be compiled +# manually out-of-tree, both of them are not used by the web app now anyway, so +# just exclude them from emscripten builds +if(NOT EMSCRIPTEN) + dp_target_sources(dpengine + dpengine/load.c + dpengine/load.h + dpengine/save.c + dpengine/save.h + dpengine/xml_stream.h + dpengine/xml_stream_qt.cpp + dpengine/zip_archive.h + ) + target_link_libraries(dpengine PRIVATE + "Qt${QT_VERSION}::Xml" + ) + + if(ZIP_IMPL STREQUAL "LIBZIP") + target_sources(dpengine PRIVATE dpengine/zip_archive_libzip.c) + target_link_libraries(dpengine PRIVATE libzip::zip) + elseif(ZIP_IMPL STREQUAL "KARCHIVE") + target_sources(dpengine PRIVATE dpengine/zip_archive_karchive.cpp) + target_link_libraries(dpengine PRIVATE KF5::Archive) + else() + message(SEND_ERROR "Unknown ZIP_IMPL value '${ZIP_IMPL}'") + endif() endif() -if("${ZIP_IMPL}" STREQUAL "LIBZIP") - add_library(dpengine_archive STATIC dpengine/zip_archive_libzip.c) - set_dp_target_properties(dpengine_archive) - target_link_libraries(dpengine_archive PUBLIC dpcommon libzip::zip) -elseif("${ZIP_IMPL}" STREQUAL "KARCHIVE") - add_library(dpengine_archive STATIC dpengine/zip_archive_karchive.cpp) - set_dp_target_properties(dpengine_archive CXX) - target_link_libraries(dpengine_archive PUBLIC dpcommon KF5::Archive) -else() - message(SEND_ERROR "Unknown ZIP_IMPL value '${ZIP_IMPL}'") -endif() - -add_library(dpengine STATIC "${dpengine_sources}" "${dpengine_headers}") -set_dp_target_properties(dpengine) -target_include_directories(dpengine INTERFACE "${CMAKE_CURRENT_LIST_DIR}") -target_include_directories(dpengine PRIVATE "${CMAKE_BINARY_DIR}/config") -target_link_libraries(dpengine PUBLIC dpengine_archive dpengine_xml - dpmsg_interface uthash mypaint qgrayraster - parson jo_gifx) - -if("${IMAGE_IMPL}" STREQUAL "LIBS") - target_sources(dpengine PRIVATE dpengine/image_base.c dpengine/image_jpeg.c - dpengine/image_png.c) - target_link_libraries(dpengine PUBLIC PNG::PNG JPEG::JPEG) -elseif("${IMAGE_IMPL}" STREQUAL "QT") - add_library(dpengine_image STATIC dpengine/image_base.c - dpengine/image_qt.cpp) - set_dp_target_properties(dpengine_image CXX) - target_link_libraries(dpengine_image PUBLIC dpcommon "Qt${QT_VERSION}::Gui") - target_link_libraries(dpengine PUBLIC dpengine_image) +install( + FILES + "${CMAKE_SOURCE_DIR}/3rdparty/libmypaint/mypaint-brush.h" + "${CMAKE_SOURCE_DIR}/3rdparty/libmypaint/mypaint-config.h" + "${CMAKE_SOURCE_DIR}/3rdparty/libmypaint/mypaint-brush-settings.h" + "${CMAKE_SOURCE_DIR}/3rdparty/libmypaint/mypaint-brush-settings-gen.h" + "${CMAKE_SOURCE_DIR}/3rdparty/libmypaint/mypaint-glib-compat.h" + "${CMAKE_SOURCE_DIR}/3rdparty/libmypaint/mypaint-rectangle.h" + "${CMAKE_SOURCE_DIR}/3rdparty/libmypaint/mypaint-surface.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/dpengine/libmypaint" +) +target_compile_definitions(dpengine INTERFACE $) + +if(IMAGE_IMPL STREQUAL "LIBS") + target_sources(dpengine PRIVATE + dpengine/image_jpeg.c + dpengine/image_png.c + ) + target_link_libraries(dpengine PRIVATE + PNG::PNG + JPEG::JPEG + ) +elseif(IMAGE_IMPL STREQUAL "QT") + target_sources(dpengine PRIVATE dpengine/image_qt.cpp) + target_link_libraries(dpengine PRIVATE "Qt${QT_VERSION}::Gui") else() message(SEND_ERROR "Unknown IMAGE_IMPL value '${IMAGE_IMPL}'") endif() if(BUILD_TESTS) - add_library(dptest_engine STATIC "${dptest_engine_sources}" - "${dptest_engine_headers}") - set_dp_target_properties(dptest_engine NO_EXPORT) - target_include_directories(dptest_engine INTERFACE - "${CMAKE_CURRENT_LIST_DIR}/test/dptest") - target_link_libraries(dptest_engine PUBLIC dptest dpengine dpmsg) - + set(dpengine_tests + test/handle_annotations.c + test/handle_layers.c + test/handle_metadata.c + test/handle_timeline.c + test/image_thumbnail.c + test/model_changes.c + test/read_write_image.c + test/render_recording.c + test/resize_image.c) + + add_library(dptest_engine) + target_sources(dptest_engine PRIVATE + test/dptest/dptest_engine.c + test/dptest/dptest_engine.h + ) + target_include_directories(dptest_engine PUBLIC + "${CMAKE_CURRENT_LIST_DIR}/test/dptest" + ) + target_link_libraries(dptest_engine + PUBLIC + dptest + dpengine + dpmsg + dpcommon + parson + ) add_dptest_targets(engine dptest_engine dpengine_tests) endif() @@ -183,11 +186,9 @@ if(BUILD_BENCHMARKS) find_package(benchmark CONFIG REQUIRED) function(add_benchmark NAME SOURCES) - add_clang_format_files("${SOURCES}") - add_executable("${NAME}" "${SOURCES}") set_dp_target_properties("${NAME}" CXX NO_WARNINGS) - target_link_libraries("${NAME}" PUBLIC dpcommon dpengine dpmsg benchmark::benchmark benchmark::benchmark_main) + target_link_libraries("${NAME}" PRIVATE dpcommon dpengine dpmsg benchmark::benchmark benchmark::benchmark_main) endfunction() add_benchmark(blending_simd_bench benchmark/blending_simd_bench.cpp) diff --git a/libengine/dpengine/brush.h b/libengine/dpengine/brush.h index df8ca84..2167cd1 100644 --- a/libengine/dpengine/brush.h +++ b/libengine/dpengine/brush.h @@ -24,7 +24,11 @@ #include "pixels.h" #include #include +#ifdef DP_BUNDLED_LIBMYPAINT +#include "libmypaint/mypaint-brush-settings-gen.h" +#else #include +#endif #define DP_CLASSIC_BRUSH_CURVE_VALUE_COUNT 256 #define DP_MYPAINT_CONTROL_POINTS_COUNT 64 diff --git a/libmsg/CMakeLists.txt b/libmsg/CMakeLists.txt index 8814e0e..79b9822 100644 --- a/libmsg/CMakeLists.txt +++ b/libmsg/CMakeLists.txt @@ -1,24 +1,7 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT -set(dpmsg_sources +dp_add_library(dpmsg) +dp_target_sources(dpmsg dpmsg/acl.c dpmsg/binary_reader.c dpmsg/binary_writer.c @@ -28,9 +11,7 @@ set(dpmsg_sources dpmsg/message_queue.c dpmsg/msg_internal.c dpmsg/text_reader.c - dpmsg/text_writer.c) - -set(dpmsg_headers + dpmsg/text_writer.c dpmsg/acl.h dpmsg/disconnect_reason.h dpmsg/binary_reader.h @@ -41,27 +22,25 @@ set(dpmsg_headers dpmsg/message_queue.h dpmsg/msg_internal.h dpmsg/text_reader.h - dpmsg/text_writer.h) - -set(dpmsg_tests - test/read_write_roundtrip.c) - -add_clang_format_files("${dpmsg_sources}" "${dpmsg_headers}" "${dpmsg_tests}") - -add_library(dpmsg_interface INTERFACE) -set_dp_target_properties(dpmsg_interface) -target_link_libraries(dpmsg_interface INTERFACE dpcommon) -target_include_directories(dpmsg_interface INTERFACE - "${CMAKE_CURRENT_LIST_DIR}") - -add_library(dpmsg STATIC "${dpmsg_sources}" "${dpmsg_headers}") -set_dp_target_properties(dpmsg) -target_link_libraries(dpmsg PUBLIC dpmsg_interface parson uthash) - -if(LINK_WITH_LIBM) - target_link_libraries(dpmsg PUBLIC m) -endif() + dpmsg/text_writer.h +) +target_include_directories(dpmsg PUBLIC + $ + $ +) +target_link_libraries(dpmsg PRIVATE + dpcommon + $ + $ +) +target_compile_definitions(dpmsg INTERFACE $) +install( + FILES "${CMAKE_SOURCE_DIR}/3rdparty/parson/parson.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/dpmsg/parson" +) if(BUILD_TESTS) - add_dptest_targets(msg dptest dpmsg_tests) + add_dptest_targets(msg dptest + test/read_write_roundtrip.c + ) endif() diff --git a/libmsg/dpmsg/binary_writer.h b/libmsg/dpmsg/binary_writer.h index 6afad84..79dcb3e 100644 --- a/libmsg/dpmsg/binary_writer.h +++ b/libmsg/dpmsg/binary_writer.h @@ -22,7 +22,11 @@ #ifndef DPMSG_BINARY_WRITER_H #define DPMSG_BINARY_WRITER_H #include +#ifdef DP_BUNDLED_PARSON +#include "parson/parson.h" +#else #include +#endif typedef struct DP_Message DP_Message; typedef struct DP_Output DP_Output; diff --git a/libmsg/dpmsg/text_writer.h b/libmsg/dpmsg/text_writer.h index 45dfb08..8493ae5 100644 --- a/libmsg/dpmsg/text_writer.h +++ b/libmsg/dpmsg/text_writer.h @@ -22,7 +22,11 @@ #ifndef DPMSG_TEXT_WRITER_H #define DPMSG_TEXT_WRITER_H #include +#ifdef DP_BUNDLED_PARSON +#include "parson/parson.h" +#else #include +#endif typedef struct DP_Message DP_Message; typedef struct DP_Output DP_Output; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0e37809..5b714b3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,29 +1,10 @@ -# Copyright (c) 2022 askmeaboutloom -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# SPDX-License-Identifier: MIT -add_clang_format_files(dptest/dptest.c dptest/dptest.h) - -if(BUILD_TESTS) - add_library(dptest STATIC dptest/dptest.c dptest/dptest.h) - set_dp_target_properties(dptest NO_EXPORT) - target_include_directories(dptest INTERFACE - "${CMAKE_CURRENT_LIST_DIR}/dptest") - target_link_libraries(dptest PUBLIC dpcommon) -endif() +add_library(dptest) +target_sources(dptest PRIVATE + dptest/dptest.c + dptest/dptest.h +) +target_include_directories(dptest INTERFACE + "${CMAKE_CURRENT_LIST_DIR}/dptest") +target_link_libraries(dptest PRIVATE dpcommon)