diff --git a/CMakeLists.txt b/CMakeLists.txt index d6641ee..a9cd092 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,3 +5,4 @@ # https://github.com/desktop-app/legal/blob/master/LEGAL add_subdirectory(external) +add_subdirectory(linux_glibc_wraps) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 5e6d6fd..93b469f 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(auto_updates) add_subdirectory(crash_reports) +add_subdirectory(ffmpeg) add_subdirectory(gsl) add_subdirectory(iconv) add_subdirectory(lz4) diff --git a/external/auto_updates/xz/CMakeLists.txt b/external/auto_updates/xz/CMakeLists.txt index 8c506c0..fcf5845 100644 --- a/external/auto_updates/xz/CMakeLists.txt +++ b/external/auto_updates/xz/CMakeLists.txt @@ -12,9 +12,14 @@ if (APPLE AND NOT build_osx) INTERFACE /usr/local/macos/lib/liblzma.a ) -else() +elseif (APPLE) target_link_libraries(external_xz INTERFACE - /usr/local/lib/liblzma.a + /usr/local/liblzma.a + ) +else() + target_link_static_libraries(external_xz + INTERFACE + lzma ) endif() diff --git a/external/crash_reports/breakpad/CMakeLists.txt b/external/crash_reports/breakpad/CMakeLists.txt index bd1d56d..c09243d 100644 --- a/external/crash_reports/breakpad/CMakeLists.txt +++ b/external/crash_reports/breakpad/CMakeLists.txt @@ -21,4 +21,9 @@ if (WIN32) ${breakpad_lib_loc}/windows/handler/exception_handler.lib ${breakpad_lib_loc}/windows/crash_generation/crash_generation_client.lib ) +elseif (LINUX) + target_link_static_libraries(external_breakpad + INTERFACE + breakpad_client + ) endif() diff --git a/external/ffmpeg/CMakeLists.txt b/external/ffmpeg/CMakeLists.txt new file mode 100644 index 0000000..014fb06 --- /dev/null +++ b/external/ffmpeg/CMakeLists.txt @@ -0,0 +1,38 @@ +# This file is part of Desktop App Toolkit, +# a set of libraries for developing nice desktop applications. +# +# For license and copyright information please follow this link: +# https://github.com/desktop-app/legal/blob/master/LEGAL + +add_library(external_ffmpeg INTERFACE IMPORTED GLOBAL) +add_library(desktop-app::external_ffmpeg ALIAS external_ffmpeg) + +target_include_directories(external_ffmpeg SYSTEM +INTERFACE + ${libs_loc}/ffmpeg +) + +set(ffmpeg_lib_loc ${libs_loc}/ffmpeg) + +target_link_libraries(external_ffmpeg +INTERFACE + ${ffmpeg_lib_loc}/libavformat/libavformat.a + ${ffmpeg_lib_loc}/libavcodec/libavcodec.a + ${ffmpeg_lib_loc}/libswresample/libswresample.a + ${ffmpeg_lib_loc}/libswscale/libswscale.a + ${ffmpeg_lib_loc}/libavutil/libavutil.a +) +if (LINUX) + target_link_static_libraries(external_ffmpeg + INTERFACE + va-x11 + va-drm + va + vdpau + drm + Xi + Xext + Xfixes + Xrender + ) +endif() diff --git a/external/iconv/CMakeLists.txt b/external/iconv/CMakeLists.txt index 32989f6..5db2c1f 100644 --- a/external/iconv/CMakeLists.txt +++ b/external/iconv/CMakeLists.txt @@ -7,14 +7,14 @@ add_library(external_iconv INTERFACE IMPORTED GLOBAL) add_library(desktop-app::external_iconv ALIAS external_iconv) -if (build_osx) - target_link_libraries(external_iconv - INTERFACE - /usr/local/lib/libiconv.a - ) -else() +if (APPLE AND NOT build_osx) target_link_libraries(external_iconv INTERFACE /usr/local/macos/lib/libiconv.a ) +elseif (APPLE) + target_link_libraries(external_iconv + INTERFACE + /usr/local/lib/libiconv.a + ) endif() diff --git a/external/openal/CMakeLists.txt b/external/openal/CMakeLists.txt index 9714ce8..e2e4992 100644 --- a/external/openal/CMakeLists.txt +++ b/external/openal/CMakeLists.txt @@ -16,7 +16,7 @@ if (WIN32) INTERFACE ${libs_loc}/openal-soft/build/$,Debug,Release>/OpenAL32.lib ) -else() +elseif(APPLE AND NOT build_osx) target_include_directories(external_openal SYSTEM INTERFACE /usr/local/macos/include @@ -25,6 +25,15 @@ else() INTERFACE /usr/local/macos/lib/libopenal.a ) +else() + target_include_directories(external_openal SYSTEM + INTERFACE + /usr/local/include + ) + target_link_static_libraries(external_openal + INTERFACE + openal + ) endif() target_compile_definitions(external_openal diff --git a/external/openssl/CMakeLists.txt b/external/openssl/CMakeLists.txt index c1565e4..9c67afa 100644 --- a/external/openssl/CMakeLists.txt +++ b/external/openssl/CMakeLists.txt @@ -7,7 +7,12 @@ add_library(external_openssl INTERFACE IMPORTED GLOBAL) add_library(desktop-app::external_openssl ALIAS external_openssl) -if (NOT APPLE OR NOT build_osx) +if (LINUX) + target_include_directories(external_openssl SYSTEM + INTERFACE + /usr/local/desktop-app/openssl-1.1.1/include + ) +elseif (NOT APPLE OR NOT build_osx) target_include_directories(external_openssl SYSTEM INTERFACE ${libs_loc}/openssl_1_1_1/include @@ -30,11 +35,21 @@ else() else() set(openssl_lib_loc ${libs_loc}/openssl) endif() + else() + set(openssl_lib_loc /usr/local/desktop-app/openssl-1.1.1/lib) endif() endif() target_link_libraries(external_openssl INTERFACE - ${openssl_lib_loc}/libcrypto.${openssl_lib_ext} ${openssl_lib_loc}/libssl.${openssl_lib_ext} + ${openssl_lib_loc}/libcrypto.${openssl_lib_ext} + pthread ) + +if (LINUX) + target_link_libraries(external_openssl + INTERFACE + desktop-app::linux_glibc_wraps + ) +endif() diff --git a/external/opus/CMakeLists.txt b/external/opus/CMakeLists.txt index 29b0c1e..07dd094 100644 --- a/external/opus/CMakeLists.txt +++ b/external/opus/CMakeLists.txt @@ -25,8 +25,8 @@ elseif (APPLE AND NOT build_osx) /usr/local/macos/lib/libopus.a ) else() - target_link_libraries(external_opus + target_link_static_libraries(external_opus INTERFACE - /usr/local/lib/libopus.a + opus ) endif() diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index c7fcaec..5697dbd 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -8,7 +8,7 @@ add_library(external_qt INTERFACE IMPORTED GLOBAL) add_library(desktop-app::external_qt ALIAS external_qt) if (LINUX) - if (CMAKE_SIZEOF_VOID_P EQUAL 8) + if (NOT build_linux32) target_compile_definitions(external_qt INTERFACE Q_OS_LINUX64) else() target_compile_definitions(external_qt INTERFACE Q_OS_LINUX32) @@ -43,7 +43,11 @@ if (WIN32) set(qt_lib_suffix $<$:d>.lib) else() set(qt_lib_prefix lib) - set(qt_lib_suffix $<$:_debug>.a) + if (APPLE) + set(qt_lib_suffix $<$:_debug>.a) + else() + set(qt_lib_suffix .a) + endif() endif() set(common_qt_libs @@ -112,9 +116,90 @@ elseif (APPLE) desktop-app::external_zlib cups ) +else() + set(qt_libs + plugins/platforminputcontexts/${qt_lib_prefix}composeplatforminputcontextplugin + plugins/platforminputcontexts/${qt_lib_prefix}ibusplatforminputcontextplugin + plugins/platforminputcontexts/${qt_lib_prefix}fcitxplatforminputcontextplugin + plugins/platforminputcontexts/${qt_lib_prefix}himeplatforminputcontextplugin + plugins/platforminputcontexts/${qt_lib_prefix}nimfplatforminputcontextplugin + plugins/platforms/${qt_lib_prefix}qxcb + lib/${qt_lib_prefix}Qt5XcbQpa + lib/${qt_lib_prefix}Qt5LinuxAccessibilitySupport + lib/${qt_lib_prefix}Qt5ServiceSupport + lib/${qt_lib_prefix}Qt5EdidSupport + plugins/bearer/${qt_lib_prefix}qconnmanbearer + plugins/bearer/${qt_lib_prefix}qgenericbearer + plugins/bearer/${qt_lib_prefix}qnmbearer + ${common_qt_libs} + lib/${qt_lib_prefix}Qt5DBus + lib/${qt_lib_prefix}Qt5Core + lib/${qt_lib_prefix}qtpcre2 + lib/${qt_lib_prefix}xcb-static + ) + foreach (lib ${qt_libs}) + list(APPEND qt_libs_list "${qt_loc}/${lib}${qt_lib_suffix}") + endforeach() endif() target_link_libraries(external_qt INTERFACE ${qt_libs_list} ) + +if (LINUX) + target_include_directories(external_qt SYSTEM + INTERFACE + ${qt_loc}/mkspecs/linux-g++ + ) + target_link_options(external_qt + INTERFACE + -static-libstdc++ + -pthread + -rdynamic + -Wl,-wrap,aligned_alloc + -Wl,-wrap,secure_getenv + -Wl,-wrap,clock_gettime + -Wl,--no-as-needed,-lrt + ) + if (NOT build_linux32) + target_link_options(external_qt + INTERFACE + -Wl,-wrap,__divmodti4 + ) + else() + target_link_options(external_qt + INTERFACE + -Wl,-wrap,__divmoddi4 + ) + endif() + target_link_static_libraries(external_qt + INTERFACE + SM + ICE + fontconfig + freetype + expat + z + xcb-shm + xcb-xfixes + xcb-render + xkbcommon + xkbcommon-x11 + icutu + icui18n + icuuc + icudata + ) + target_link_libraries(external_qt + INTERFACE + desktop-app::linux_glibc_wraps + xcb + X11 + X11-xcb + dbus-1 + dl + glib-2.0 + pthread + ) +endif() diff --git a/external/zlib/CMakeLists.txt b/external/zlib/CMakeLists.txt index fe76bb6..d2bc1fc 100644 --- a/external/zlib/CMakeLists.txt +++ b/external/zlib/CMakeLists.txt @@ -44,6 +44,8 @@ if (WIN32) set(zlib_lib_loc ${libs_loc}/zlib/contrib/vstudio/vc14/x86/ZlibStat$,Debug,ReleaseWithoutAsm>) target_link_libraries(external_zlib INTERFACE ${zlib_lib_loc}/zlibstat.lib) -else() +elseif (APPLE) target_link_libraries(external_zlib INTERFACE /usr/local/lib/libz.a) +else() + target_link_static_libraries(external_zlib INTERFACE z) endif() diff --git a/generate_target.cmake b/generate_target.cmake index 1fd6f63..611067f 100644 --- a/generate_target.cmake +++ b/generate_target.cmake @@ -4,8 +4,8 @@ # For license and copyright information please follow this link: # https://github.com/desktop-app/legal/blob/master/LEGAL -function(generate_target parent_name postfix generated_files gen_dst) - add_custom_target(${parent_name}_${postfix} DEPENDS ${generated_files}) +function(generate_target parent_name postfix generated_timestamp generated_files gen_dst) + add_custom_target(${parent_name}_${postfix} DEPENDS ${generated_timestamp}) init_target_folder(${parent_name}_${postfix} "(gen)") add_dependencies(${parent_name} ${parent_name}_${postfix}) target_sources(${parent_name} PRIVATE ${generated_files}) diff --git a/init_target.cmake b/init_target.cmake index 23023c5..6eb1a83 100644 --- a/init_target.cmake +++ b/init_target.cmake @@ -34,7 +34,15 @@ function(init_target target_name) # init_target(my_target folder_name) XCODE_ATTRIBUTE_GCC_OPTIMIZATION_LEVEL $,0,fast> XCODE_ATTRIBUTE_LLVM_LTO $,NO,YES> ) - if (NOT APPLE) + if (LINUX) + target_compile_options(${target_name} PUBLIC $,,-g -Ofast -fno-strict-aliasing>) + target_link_options(${target_name} PUBLIC $,,-g -Ofast>) + if (NOT build_linux32) + target_compile_options(${target_name} PUBLIC $,,-flto>) + target_link_options(${target_name} PUBLIC $,,-flto -fuse-linker-plugin>) + endif() + endif() + if (WIN32) set_target_properties(${target_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE True INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO True diff --git a/linux_glibc_wraps/CMakeLists.txt b/linux_glibc_wraps/CMakeLists.txt new file mode 100644 index 0000000..30ef632 --- /dev/null +++ b/linux_glibc_wraps/CMakeLists.txt @@ -0,0 +1,24 @@ +# This file is part of Desktop App Toolkit, +# a set of libraries for developing nice desktop applications. +# +# For license and copyright information please follow this link: +# https://github.com/desktop-app/legal/blob/master/LEGAL + +if (LINUX) + add_library(linux_glibc_wraps STATIC) + add_library(desktop-app::linux_glibc_wraps ALIAS linux_glibc_wraps) + + get_filename_component(src_loc . REALPATH) + + nice_target_sources(linux_glibc_wraps ${src_loc} + PRIVATE + platform/linux/linux_glibc_wraps.c + platform/linux/linux_glibc_wraps_32.c + platform/linux/linux_glibc_wraps_64.c + ) + if (NOT build_linux32) + set_source_files_properties(${src_loc}/platform/linux/linux_glibc_wraps_32.c PROPERTIES HEADER_FILE_ONLY TRUE) + else() + set_source_files_properties(${src_loc}/platform/linux/linux_glibc_wraps_64.c PROPERTIES HEADER_FILE_ONLY TRUE) + endif() +endif() diff --git a/linux_glibc_wraps/platform/linux/linux_glibc_wraps.c b/linux_glibc_wraps/platform/linux/linux_glibc_wraps.c new file mode 100644 index 0000000..1770ab1 --- /dev/null +++ b/linux_glibc_wraps/platform/linux/linux_glibc_wraps.c @@ -0,0 +1,29 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#include +#include +#include + +void *__wrap_aligned_alloc(size_t alignment, size_t size) { + void *result = NULL; + return (posix_memalign(&result, alignment, size) == 0) + ? result + : NULL; +} + +int enable_secure_inited = 0; +int enable_secure = 1; + +char *__wrap_secure_getenv(const char *name) { + if (enable_secure_inited == 0) { + enable_secure_inited = 1; + enable_secure = (geteuid() != getuid()) + || (getegid() != getgid()); + } + return enable_secure ? NULL : getenv(name); +} + diff --git a/linux_glibc_wraps/platform/linux/linux_glibc_wraps.gyp b/linux_glibc_wraps/platform/linux/linux_glibc_wraps.gyp new file mode 100644 index 0000000..fe4cf49 --- /dev/null +++ b/linux_glibc_wraps/platform/linux/linux_glibc_wraps.gyp @@ -0,0 +1,36 @@ +# This file is part of Desktop App Toolkit, +# a set of libraries for developing nice desktop applications. +# +# For license and copyright information please follow this link: +# https://github.com/desktop-app/legal/blob/master/LEGAL + +{ + 'includes': [ + '../../common/common.gypi', + ], + 'targets': [{ + 'target_name': 'linux_glibc_wraps', + 'type': 'static_library', + 'variables': { + 'src_loc': '.', + }, + 'configurations': { + 'Debug': { + }, + 'Release': { + }, + }, + 'sources': [ + '<(src_loc)/linux_glibc_wraps.c', + ], + 'conditions': [[ '" +#include + +#if defined(_M_IX86) || defined(__i386__) +#define GETTIME_GLIBC_VERSION "2.2" +#elif defined(_M_ARM) || defined(__arm__) +#define GETTIME_GLIBC_VERSION "2.4" +#else +#error Please add glibc wraps for your architecture +#endif + +int __clock_gettime_glibc_old(clockid_t clk_id, struct timespec *tp); +__asm__(".symver __clock_gettime_glibc_old,clock_gettime@GLIBC_" GETTIME_GLIBC_VERSION); + +int __wrap_clock_gettime(clockid_t clk_id, struct timespec *tp) { + return __clock_gettime_glibc_old(clk_id, tp); +} + +uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p); + +int64_t __wrap___divmoddi4(int64_t num, int64_t den, int64_t *rem_p) { + int minus = 0; + int64_t v; + + if (num < 0) { + num = -num; + minus = 1; + } + if (den < 0) { + den = -den; + minus ^= 1; + } + + v = __udivmoddi4(num, den, (uint64_t *)rem_p); + if (minus) { + v = -v; + if (rem_p) + *rem_p = -(*rem_p); + } + + return v; +} + diff --git a/linux_glibc_wraps/platform/linux/linux_glibc_wraps_64.c b/linux_glibc_wraps/platform/linux/linux_glibc_wraps_64.c new file mode 100644 index 0000000..b04f513 --- /dev/null +++ b/linux_glibc_wraps/platform/linux/linux_glibc_wraps_64.c @@ -0,0 +1,52 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#include + +#if defined(_M_X64) || defined(__x86_64__) +#define GETTIME_GLIBC_VERSION "2.2.5" +#elif defined(__aarch64__) +#define GETTIME_GLIBC_VERSION "2.17" +#else +#error Please add glibc wraps for your architecture +#endif + +typedef unsigned int UTItype __attribute__ ((mode (TI))); +typedef int TItype __attribute__ ((mode (TI))); + +int __clock_gettime_glibc_old(clockid_t clk_id, struct timespec *tp); +__asm__(".symver __clock_gettime_glibc_old,clock_gettime@GLIBC_" GETTIME_GLIBC_VERSION); + + +int __wrap_clock_gettime(clockid_t clk_id, struct timespec *tp) { + return __clock_gettime_glibc_old(clk_id, tp); +} + +UTItype __udivmodti4(UTItype num, UTItype den, UTItype *rem_p); + +TItype __wrap___divmodti4(TItype num, TItype den, TItype *rem_p) { + int minus = 0; + TItype v; + + if (num < 0) { + num = -num; + minus = 1; + } + if (den < 0) { + den = -den; + minus ^= 1; + } + + v = __udivmodti4(num, den, (UTItype *)rem_p); + if (minus) { + v = -v; + if (rem_p) + *rem_p = -(*rem_p); + } + + return v; +} + diff --git a/nice_target_sources.cmake b/nice_target_sources.cmake index 880ef32..2ac58d4 100644 --- a/nice_target_sources.cmake +++ b/nice_target_sources.cmake @@ -4,7 +4,10 @@ # For license and copyright information please follow this link: # https://github.com/desktop-app/legal/blob/master/LEGAL -function(nice_target_sources target_name src_loc list) +function(nice_target_sources target_name src_loc) + set(list ${ARGV}) + list(REMOVE_AT list 0 1) + set(writing_now "") set(private_sources "") set(public_sources "") diff --git a/options_linux.cmake b/options_linux.cmake index eb476a5..ad14dc5 100644 --- a/options_linux.cmake +++ b/options_linux.cmake @@ -3,3 +3,29 @@ # # For license and copyright information please follow this link: # https://github.com/desktop-app/legal/blob/master/LEGAL + +target_compile_options(common_options +INTERFACE + -g + -pipe + -Wall + -Werror + -W + -fPIC + -Wno-unused-variable + -Wno-unused-parameter + -Wno-unused-function + -Wno-switch + -Wno-comment + -Wno-unused-but-set-variable + -Wno-missing-field-initializers + -Wno-sign-compare + -Wno-attributes + -Wno-parentheses + -Wno-stringop-overflow + -Wno-error=class-memaccess +) +target_link_options(common_options +INTERFACE + -g +) diff --git a/target_link_static_libraries.cmake b/target_link_static_libraries.cmake new file mode 100644 index 0000000..2aa2875 --- /dev/null +++ b/target_link_static_libraries.cmake @@ -0,0 +1,45 @@ +# This file is part of Desktop App Toolkit, +# a set of libraries for developing nice desktop applications. +# +# For license and copyright information please follow this link: +# https://github.com/desktop-app/legal/blob/master/LEGAL + +function(target_link_static_libraries target_name) + set(list ${ARGV}) + list(REMOVE_AT list 0) + + set(writing_now "") + set(private_libs "") + set(public_libs "") + set(interface_libs "") + foreach (entry ${list}) + if (${entry} STREQUAL "PRIVATE" OR ${entry} STREQUAL "PUBLIC" OR ${entry} STREQUAL "INTERFACE") + set(writing_now ${entry}) + else() + find_library(static_lib_${entry} lib${entry}.a) + set(full_path "${static_lib_${entry}}") + if (${full_path} STREQUAL static_lib_${entry}-NOTFOUND) + message(FATAL_ERROR "Could not find static library lib${entry}.a") + endif() + if ("${writing_now}" STREQUAL "PRIVATE") + list(APPEND private_libs ${full_path}) + elseif ("${writing_now}" STREQUAL "PUBLIC") + list(APPEND public_libs ${full_path}) + elseif ("${writing_now}" STREQUAL "INTERFACE") + list(APPEND interface_libs ${full_path}) + else() + message(FATAL_ERROR "Unknown frameworks scope for target ${target_name}") + endif() + endif() + endforeach() + + if (NOT "${public_libs}" STREQUAL "") + target_link_libraries(${target_name} PUBLIC ${public_libs}) + endif() + if (NOT "${private_libs}" STREQUAL "") + target_link_libraries(${target_name} PRIVATE ${private_libs}) + endif() + if (NOT "${interface_libs}" STREQUAL "") + target_link_libraries(${target_name} INTERFACE ${interface_libs}) + endif() +endfunction() diff --git a/variables.cmake b/variables.cmake index a338607..e358d27 100644 --- a/variables.cmake +++ b/variables.cmake @@ -29,6 +29,7 @@ endif() set(build_osx 0) set(build_macstore 0) set(build_winstore 0) +set(build_linux32 0) if (WIN32) if (DESKTOP_APP_SPECIAL_TARGET STREQUAL "uwp") @@ -49,17 +50,24 @@ elseif (APPLE) endif() else() set(LINUX 1) + execute_process(COMMAND uname -m OUTPUT_VARIABLE machine_uname) + if (NOT ${machine_uname} MATCHES "x86_64" AND NOT ${machine_uname} MATCHES "aarch64") + set(build_linux32 1) + endif() if (DESKTOP_APP_SPECIAL_TARGET STREQUAL "linux") - if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8) + if (build_linux32) report_bad_special_target() endif() elseif (DESKTOP_APP_SPECIAL_TARGET STREQUAL "linux32") - if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4) + if (NOT build_linux32) report_bad_special_target() endif() elseif (NOT DESKTOP_APP_SPECIAL_TARGET STREQUAL "") report_bad_special_target() endif() + set(CMAKE_AR /usr/bin/gcc-ar) + set(CMAKE_RANLIB /usr/bin/gcc-ranlib) + set(CMAKE_NM /usr/bin/gcc-nm) endif() if (NOT APPLE OR build_osx)