From ff239670efd6ba76fe80b8a6f5cdc562fbb8b38f Mon Sep 17 00:00:00 2001 From: Aetf Date: Thu, 4 Oct 2018 16:16:11 -0400 Subject: [PATCH 01/20] gtktsm: fix calling to tsm API which was changed to 64bit character id --- src/gtktsm/gtktsm-terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gtktsm/gtktsm-terminal.c b/src/gtktsm/gtktsm-terminal.c index dcccc7b..d6023ba 100644 --- a/src/gtktsm/gtktsm-terminal.c +++ b/src/gtktsm/gtktsm-terminal.c @@ -937,7 +937,7 @@ static void renderer_blend(struct gtktsm_renderer *rend, } static int renderer_draw_cell(struct tsm_screen *screen, - uint32_t id, + uint64_t id, const uint32_t *ch, size_t len, unsigned int cwidth, From 8450985e204f58ee3eebf6c24fa558cc67e1798e Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 2 Oct 2018 15:52:36 -0400 Subject: [PATCH 02/20] build: add initial CMake support for the main library and example Signed-off-by: Aetf --- .gitignore | 3 +- CMakeLists.txt | 175 ++++++++ COPYING | 4 + cmake/BuildTypes.cmake | 64 +++ cmake/CompileOptions.cmake | 86 ++++ cmake/Utilities.cmake | 240 ++++++++++ cmake/modules/FindPangoCairo.cmake | 67 +++ cmake/modules/FindXKBCommon.cmake | 110 +++++ cmake/modules/gnome-cmake/.gitignore | 3 + cmake/modules/gnome-cmake/COPYING | 20 + cmake/modules/gnome-cmake/README.md | 33 ++ .../modules/gnome-cmake/modules/FindATK.cmake | 89 ++++ .../gnome-cmake/modules/FindCairo.cmake | 88 ++++ .../gnome-cmake/modules/FindGDK3.cmake | 89 ++++ .../gnome-cmake/modules/FindGDKPixbuf.cmake | 81 ++++ .../modules/gnome-cmake/modules/FindGIO.cmake | 199 +++++++++ .../gnome-cmake/modules/FindGLib.cmake | 83 ++++ .../gnome-cmake/modules/FindGObject.cmake | 82 ++++ .../modules/FindGObjectIntrospection.cmake | 98 +++++ .../gnome-cmake/modules/FindGTK3.cmake | 94 ++++ .../gnome-cmake/modules/FindPango.cmake | 87 ++++ .../gnome-cmake/modules/FindSoup.cmake | 87 ++++ .../gnome-cmake/modules/FindVala.cmake | 410 ++++++++++++++++++ .../gnome-cmake/modules/FindValadoc.cmake | 105 +++++ etc/libtsm.pc.in | 11 + external/CMakeLists.txt | 15 + src/CMakeLists.txt | 6 + src/config.h.in | 10 + src/gtktsm/CMakeLists.txt | 26 ++ src/shared/CMakeLists.txt | 17 + src/tsm/CMakeLists.txt | 36 ++ src/tsm/libtsm.pc.in | 11 - src/tsm/tsm-unicode.c | 2 +- 33 files changed, 2518 insertions(+), 13 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/BuildTypes.cmake create mode 100644 cmake/CompileOptions.cmake create mode 100644 cmake/Utilities.cmake create mode 100644 cmake/modules/FindPangoCairo.cmake create mode 100644 cmake/modules/FindXKBCommon.cmake create mode 100644 cmake/modules/gnome-cmake/.gitignore create mode 100644 cmake/modules/gnome-cmake/COPYING create mode 100644 cmake/modules/gnome-cmake/README.md create mode 100644 cmake/modules/gnome-cmake/modules/FindATK.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindCairo.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindGDK3.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindGDKPixbuf.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindGIO.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindGLib.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindGObject.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindGObjectIntrospection.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindGTK3.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindPango.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindSoup.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindVala.cmake create mode 100644 cmake/modules/gnome-cmake/modules/FindValadoc.cmake create mode 100644 etc/libtsm.pc.in create mode 100644 external/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/config.h.in create mode 100644 src/gtktsm/CMakeLists.txt create mode 100644 src/shared/CMakeLists.txt create mode 100644 src/tsm/CMakeLists.txt delete mode 100644 src/tsm/libtsm.pc.in diff --git a/.gitignore b/.gitignore index 887d827..8099e9a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ aclocal.m4 autom4te.cache/ build-aux/ config.h -config.h.in +/config.h.in config.h.in~ config.log config.status @@ -31,3 +31,4 @@ test_symbol test_valgrind *.kdev4 build +.idea diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..daf5bf2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,175 @@ +cmake_minimum_required(VERSION 3.6) + +project(libtsm VERSION 4.0.0 LANGUAGES C) + +# Some meta data +## TODO: merge into project above after we require cmake 3.12 +set(PROJECT_HOMEPAGE_URL "https://github.com/Aetf/libtsm") +## TODO: merge into project above after we require cmake 3.10 +set(PROJECT_DESCRIPTION "terminal-emulator state machine") + +#--------------------------------------------------------------------------------------- +# Initial setups +#--------------------------------------------------------------------------------------- +# Ensure out-of-source build +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "Usage: mkdir build; cmake ..") +endif() + +# Include utilities +include(cmake/Utilities.cmake) +# For feature_summary +include(FeatureSummary) + +# Extra build types +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() +include(cmake/BuildTypes.cmake) + +#--------------------------------------------------------------------------------------- +# Options +#--------------------------------------------------------------------------------------- +option(BUILD_TESTING "Whether to build test suite in default target" OFF) +add_feature_info(tests BUILD_TESTING "build unit tests") + +# We enable a lot of debug options by default, so this option is really only for +# extended developer debug modes. +option(ENABLE_EXTRA_DEBUG "Whether to enable several non-standard debug options." OFF) +add_feature_info(extra_debugging ENABLE_EXTRA_DEBUG "enable additional non-standard debug options") + +# Defined after find packages +#option(BUILD_GTKTSM "Whether to build gtktsm, defaults to ON if dependencies are met" ${BUILD_GTKTSM_INITIAL}) + +#--------------------------------------------------------------------------------------- +# Find packages +#--------------------------------------------------------------------------------------- +# Additional find modules +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/gnome-cmake/modules) + +# GNU filesystem layout +include(GNUInstallDirs) + +# Extra cmake helpers +find_package(ECM REQUIRED NO_MODULE REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${ECM_FIND_MODULE_DIR}) + +# We need xkbcommon for keysym definitions. If it's not found, we use our own +# private copy of xkbcommon-keysyms.h. +find_package(XKBCommon COMPONENTS KeySyms) +set_package_properties(XKBCommon PROPERTIES + TYPE OPTIONAL + PURPOSE "Needed for keysym definitions. Will use private copy if not found." +) + +# Optionally, look for gtk+-3 and friends for gtktsm +if(DEFINED BUILD_GTKTSM) + set(BUILD_GTKTSM_INITIAL ${BUILD_GTKTSM}) +else() + # set to ON at first, and change to OFF if dependencies are not met + set(BUILD_GTKTSM_INITIAL ON) +endif() + +if(BUILD_GTKTSM_INITIAL) + find_package(GTK3) + set_package_properties(GTK3 PROPERTIES + TYPE OPTIONAL + PURPOSE "For gtktsm example" + ) + + find_package(Cairo) + set_package_properties(Cairo PROPERTIES + TYPE OPTIONAL + PURPOSE "For gtktsm example" + ) + + find_package(Pango) + set_package_properties(Pango PROPERTIES + TYPE OPTIONAL + PURPOSE "For gtktsm example" + ) + + find_package(PangoCairo) + set_package_properties(PangoCairo PROPERTIES + TYPE OPTIONAL + PURPOSE "For gtktsm example" + ) + + find_package(XKBCommon COMPONENTS XKBCommon) + set_package_properties(XKBCommon PROPERTIES + TYPE OPTIONAL + PURPOSE "For gtktsm example" + ) + + # If the user requested to build gtktsm, then the dependencies becomes required + if((DEFINED BUILD_GTKTSM) AND BUILD_GTKTSM) + set_package_properties(GTK3 PROPERTIES TYPE REQUIRED) + set_package_properties(PangoCairo PROPERTIES TYPE REQUIRED) + set_package_properties(XKBCommon PROPERTIES TYPE REQUIRED) + endif() +endif() + +# we will build gtktsm if the user requested so or if the dependencies are met +if(NOT DEFINED BUILD_GTKTSM) + if(GTK3_FOUND AND PangoCairo_FOUND AND XKBCommon_FOUND) + set(BUILD_GTKTSM_INITIAL ON) + else() + set(BUILD_GTKTSM_INITIAL OFF) + endif() +endif() + +# Whether to our gtktsm example. This is linux-only as it uses epoll and friends. +# Therefore, it's disabled by default. +option(BUILD_GTKTSM "Whether to build gtktsm, defaults to ON if dependencies are met" ${BUILD_GTKTSM_INITIAL}) +# We defer the feature info after depencency checking +add_feature_info(gtktsm BUILD_GTKTSM "build the gtktsm example, it requires gtk+-3 and friends and is linux-only.") + +feature_summary(INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES WHAT ALL) + +#--------------------------------------------------------------------------------------- +# Set compiler options and features +#--------------------------------------------------------------------------------------- +# Only set compile options after any inclusion of third party code +include(cmake/CompileOptions.cmake) + +# Pass infomation to config header +if(XKBCommon_KeySyms_FOUND) + set(BUILD_HAVE_XKBCOMMON ON) +endif() +if(ENABLE_EXTRA_DEBUG) + set(BUILD_ENABLE_DEBUG ON) +endif(ENABLE_EXTRA_DEBUG) +configure_file(src/config.h.in ${CMAKE_BINARY_DIR}/config.h) +include_directories(${CMAKE_BINARY_DIR}) + +#--------------------------------------------------------------------------------------- +# Put code together +#--------------------------------------------------------------------------------------- +# Venderoized external code +add_subdirectory(external) + +add_subdirectory(src) + +if(BUILD_TESTING) + add_subdirectory(tests) +endif(BUILD_TESTING) + +#--------------------------------------------------------------------------------------- +# Installation +#--------------------------------------------------------------------------------------- +configure_file(etc/libtsm.pc.in libtsm.pc @ONLY) +install(FILES libtsm.pc DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig) + +# TODO: installation +# +#install(TARGETS libtsm libtsm_static +# LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +# ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +# PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libtsm" +#) +#install(TARGETS libtsm libtsm_static +# LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +# ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +# PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libtsm" +#) diff --git a/COPYING b/COPYING index e2132cf..1ec310d 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,7 @@ = Authors = This software was written by: + Aetf David Herrmann Ran Benita @@ -12,6 +13,7 @@ source file for the related copyright notice and license. If a file does not contain a copright notice, the following license shall apply: + Copyright (c) 2017-2018 Aetf Copyright (c) 2011-2013 David Herrmann Permission is hereby granted, free of charge, to any person obtaining @@ -34,6 +36,8 @@ apply: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. == Third-Party Source == +Various cmake find modules in cmake/modules/gnome-cmake is from +https://github.com/nemequ/gnome-cmake, see cmake/modules/gnome-cmake/COPYING The hash-table implementation in src/shared/shl-htable.* uses internally the htable from CCAN, see LICENSE_htable. diff --git a/cmake/BuildTypes.cmake b/cmake/BuildTypes.cmake new file mode 100644 index 0000000..e90d8f8 --- /dev/null +++ b/cmake/BuildTypes.cmake @@ -0,0 +1,64 @@ +# Add new build types for sanitizer and profiler +# Address sanitizer and undefined beheavior sanitizer +set(CMAKE_CXX_FLAGS_ASAN "-g -O1 -fno-omit-frame-pointer -fsanitize=address" + CACHE STRING "Flags used by the C++ compiler during ASan builds." FORCE) + +set(CMAKE_C_FLAGS_ASAN "${CMAKE_CXX_FLAGS_ASAN}" + CACHE STRING "Flags used by the C compiler during ASan builds." FORCE) + +set(CMAKE_EXE_LINKER_FLAGS_ASAN "-fsanitize=address" + CACHE STRING "Flags used for linking binaries during ASan builds." FORCE) + +set(CMAKE_SHARED_LINKER_FLAGS_ASAN "-fsanitize=address" + CACHE STRING "Flags used by the shared libraries linker during ASan builds." FORCE) + +# Thread sanitizer +set(CMAKE_CXX_FLAGS_TSAN "-DNDEBUG -g -O0 -fno-omit-frame-pointer -fsanitize=thread" + CACHE STRING "Flags used by the C++ compiler during TSan builds." FORCE) + +set(CMAKE_C_FLAGS_TSAN "${CMAKE_CXX_FLAGS_TSAN}" + CACHE STRING "Flags used by the C compiler during TSan builds." FORCE) + +set(CMAKE_EXE_LINKER_FLAGS_TSAN "-fsanitize=thread" + CACHE STRING "Flags used for linking binaries during TSan builds." FORCE) + +set(CMAKE_SHARED_LINKER_FLAGS_TSAN "-fsanitize=thread" + CACHE STRING "Flags used by the shared libraries linker during TSan builds." FORCE) + +# Memory sanitizer +set(CMAKE_CXX_FLAGS_MSAN "-DNDEBUG -g -O1 -fno-omit-frame-pointer -fsanitize=memory" + CACHE STRING "Flags used by the C++ compiler during MSan builds." FORCE) + +set(CMAKE_C_FLAGS_MSAN "${CMAKE_CXX_FLAGS_MSAN}" + CACHE STRING "Flags used by the C compiler during MSan builds." FORCE) + +set(CMAKE_EXE_LINKER_FLAGS_MSAN "-fsanitize=memory" + CACHE STRING "Flags used for linking binaries during MSan builds." FORCE) + +set(CMAKE_SHARED_LINKER_FLAGS_MSAN "-fsanitize=memory" + CACHE STRING "Flags used by the shared libraries linker during MSan builds." FORCE) + +set(KNOWN_BUILD_TYPES "") +foreach(build IN ITEMS ASan TSan MSan) + string(TOUPPER ${build} build_upper) + mark_as_advanced( + CMAKE_CXX_FLAGS_${build_upper} + CMAKE_C_FLAGS_${build_upper} + CMAKE_EXE_LINKER_FLAGS_${build_upper} + CMAKE_SHARED_LINKER_FLAGS_${build_upper} + ) + list(APPEND KNOWN_BUILD_TYPES ${build}) +endforeach() +list(APPEND KNOWN_BUILD_TYPES Debug Release RelWithDebInfo MinSizeRel) + +if (NOT CMAKE_BUILD_TYPE IN_LIST KNOWN_BUILD_TYPES) + message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}. Choices are ${KNOWN_BUILD_TYPES}") +endif() + +# Update the documentation string of CMAKE_BUILD_TYPE for GUIs +set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" + CACHE STRING + "Choose the type of build, options are: None;${KNOWN_BUILD_TYPES}." + FORCE) + +message(STATUS "Using build type: ${CMAKE_BUILD_TYPE}") diff --git a/cmake/CompileOptions.cmake b/cmake/CompileOptions.cmake new file mode 100644 index 0000000..6ad4320 --- /dev/null +++ b/cmake/CompileOptions.cmake @@ -0,0 +1,86 @@ +# Set compiler flags +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) + +# analogous to AC_USE_SYSTEM_EXTENSIONS in configure.ac +add_definitions(-D_POSIX_C_SOURCE=199309L -D_GNU_SOURCE) + +# copied from Autoconf's AC_SYS_LARGEFILE +if(NOT WIN32) + add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE) +endif(NOT WIN32) + +# Set compiler flags for warnings +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + # using Clang or AppleClang + + # reasonable and standard + add_compile_options_with_check(-Weverything) + add_compile_options_with_check(-Werror) + add_compile_options_with_check(-Wfatal-errors) + + add_compile_options_with_check(-Wold-style-cast) + # helps catch hard to track down memory errors + add_compile_options_with_check(-Wnon-virtual-dtor) + # warn for potential performance problem casts + add_compile_options_with_check(-Wcast-align) + # warn if you overload (not override) a virtual function + add_compile_options_with_check(-Woverloaded-virtual) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + # using GCC + + # reasonable and standard + add_compile_options_with_check(-Wall) + add_compile_options_with_check(-Wextra) + add_compile_options_with_check(-pedantic) + add_compile_options_with_check(-Werror) + #add_compile_options_with_check(-Wfatal-errors) + + add_compile_options_with_check(-Wold-style-cast) + # helps catch hard to track down memory errors + add_compile_options_with_check(-Wnon-virtual-dtor) + # warn for potential performance problem casts + add_compile_options_with_check(-Wcast-align) + # warn if you overload (not override) a virtual function + add_compile_options_with_check(-Woverloaded-virtual) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + # using Intel C++ + message(WARNING "Using of Intel C++ is not supported, you are on your own.") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # using Visual Studio C++ + + # all reasonable warnings + add_compile_options_with_check(/W4) + # treat warnings as errors + add_compile_options_with_check(/Wx) + # enable warning on thread un-safe static member initialization + add_compile_options_with_check(/W44640) +endif() + +# Other flags are not added directly globally, but using a function +# so later when defining targets, it can be set per target +function(add_libtsm_compile_options target) + # Make all files include "config.h" by default. This shouldn't cause any + # problems and we cannot forget to include it anymore. + target_compile_options(${target} PRIVATE + -include ${CMAKE_BINARY_DIR}/config.h + -pipe + -fno-common + -ffast-math + -fno-strict-aliasing + -ffunction-sections + -fdata-sections + ) + + # Linker flags + ## Make the linker discard all unused symbols. + if(APPLE) + set(LDFLAGS "-Wl,-dead_strip -Wl,-dead_strip_dylibs -Wl,-bind_at_load") + elseif(UNIX) + set(LDFLAGS "-Wl,--as-needed -Wl,--gc-sections -Wl,-z,relro -Wl,-z,now") + else() + message("Unsupported platform, you are on your own.") + endif() + + set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " ${LDFLAGS}") +endfunction() diff --git a/cmake/Utilities.cmake b/cmake/Utilities.cmake new file mode 100644 index 0000000..766be3d --- /dev/null +++ b/cmake/Utilities.cmake @@ -0,0 +1,240 @@ +include(CheckCCompilerFlag) + +# +# Check compiler flag support with cached support. +# Shadows the internal check_c_compiler_flag +# +macro(libtsm_check_c_compiler_flag flag retvar) + string(REPLACE "-" "_" cache_name "COMPILER_SUPPORT_${flag}") + check_c_compiler_flag(${flag} ${cache_name}) + set(${retvar} ${cache_name}) +endmacro() + +# Add a global default compile option +function(add_compile_options_with_check flag) + libtsm_check_c_compiler_flag(${flag} ret) + if(${ret}) + add_compile_options(${flag}) + endif() +endfunction() + +# Add a new private compile option to a target +function(target_compile_options_with_check target flag) + libtsm_check_c_compiler_flag(${flag} ret) + if(${ret}) + target_compile_options(${target} PRIVATE ${flag}) + endif() +endfunction() + +# Add compile option to a build type with check +function(build_type_add_compile_option_with_check buildtype flag) + libtsm_check_c_compiler_flag(${flag} ret) + if(${ret}) + set(CMAKE_CXX_FLAGS_${buildtype} "${CMAKE_CXX_FLAGS_${buildtype}}" ${flag}) + endif() +endfunction() + +# Print all properties for a target +# From https://stackoverflow.com/questions/32183975/how-to-print-all-the-properties-of-a-target-in-cmake + +# Get all propreties that cmake supports +execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST) +# Convert command output into a CMake list +STRING(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") +STRING(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") + +function(print_properties) + message ("CMAKE_PROPERTY_LIST = ${CMAKE_PROPERTY_LIST}") +endfunction(print_properties) + +function(print_target_properties tgt) + if(NOT TARGET ${tgt}) + message("There is no target named '${tgt}'") + return() + endif() + + foreach (prop ${CMAKE_PROPERTY_LIST}) + string(REPLACE "" "${CMAKE_BUILD_TYPE}" prop ${prop}) + # Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i + if(prop STREQUAL "LOCATION" OR prop MATCHES "^LOCATION_" OR prop MATCHES "_LOCATION$") + continue() + endif() + # message ("Checking ${prop}") + get_property(propval TARGET ${tgt} PROPERTY ${prop} SET) + if (propval) + get_target_property(propval ${tgt} ${prop}) + message ("${tgt} ${prop} = ${propval}") + endif() + endforeach(prop) +endfunction(print_target_properties) + +# Add and initialize a thirdparty submodule +# Usage: add_submodule( [THIRDPARTY_DIR ] [PATCHES ...]) +# Args: +# - The name and path of the library submodule to add +# - [Optional] The root directory for thirdparty code +# - [Optional] Additional patches to apply to the library +function(add_submodule library_name) + set(options "") + set(oneValueArgs "THIRDPARTY_DIR") + set(multiValueArgs PATCHES) + cmake_parse_arguments(ADD_SUBMODULE + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN} + ) + + if(EXISTS ADD_SUBMODULE_THIRDPARTY_DIR) + set(third_party_dir ${ADD_SUBMODULE_THIRDPARTY_DIR}) + else() + set(third_party_dir ${CMAKE_SOURCE_DIR}/thirdparty) + endif() + + if(NOT EXISTS ${third_party_dir}/${library_name}/CMakeLists.txt) + message(STATUS " Initializing submodule") + execute_process(COMMAND "git" "submodule" "update" "--init" "${third_party_dir}/${library_name}" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + RESULT_VARIABLE retcode + ) + if(NOT "${retcode}" STREQUAL "0") + message(FATAL_ERROR "Failed to checkout ${library_name} as submodule: ${retcode}") + endif(NOT "${retcode}" STREQUAL "0") + + foreach(patch IN LISTS ADD_SUBMODULE_PATCHES) + message(STATUS " Applying patch ${patch}") + get_filename_component(abs_patch ${patch} ABSOLUTE) + execute_process(COMMAND "git" "apply" "${abs_patch}" + WORKING_DIRECTORY "${third_party_dir}/${library_name}" + RESULT_VARIABLE retcode + ) + if(NOT "${retcode}" STREQUAL "0") + message(FATAL_ERROR "Failed to intialize ${library_name} when applying ${abs_patch}: ${retcode}") + endif(NOT "${retcode}" STREQUAL "0") + endforeach(patch) + endif(NOT EXISTS ${third_party_dir}/${library_name}/CMakeLists.txt) + + message("-- ${library_name} version: bundled") + add_subdirectory(${third_party_dir}/${library_name}) +endfunction(add_submodule) + +# +# Creates an imported library target for each component. See ECM's documentation for usage. +# +# This version addtionally treats empty __lib variable as an indication for interface only library +# +# The following additionall keyword arguments are accepted: +# NAMESPACE - The namespace to use for the imported target, default to +# +macro(find_package_handle_library_components module_name) + set(fphlc_options SKIP_PKG_CONFIG SKIP_DEPENDENCY_HANDLING) + set(fphlc_oneValueArgs NAMESPACE) + set(fphlc_multiValueArgs COMPONENTS) + cmake_parse_arguments(FPHLC "${fphlc_options}" "${fphlc_oneValueArgs}" "${fphlc_multiValueArgs}" ${ARGN}) + + if(FPHLC_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unexpected arguments to find_package_handle_components: ${FPHLC_UNPARSED_ARGUMENTS}") + endif() + if(NOT FPHLC_COMPONENTS) + message(FATAL_ERROR "Missing COMPONENTS argument to find_package_handle_components") + endif() + + if(NOT FPHLC_NAMESPACE) + set(FPHLC_NAMESPACE ${module_name}) + endif() + + include(FindPackageHandleStandardArgs) + find_package(PkgConfig QUIET) + foreach(fphlc_comp ${FPHLC_COMPONENTS}) + set(fphlc_dep_vars) + set(fphlc_dep_targets) + if(NOT SKIP_DEPENDENCY_HANDLING) + foreach(fphlc_dep ${${module_name}_${fphlc_comp}_component_deps}) + list(APPEND fphlc_dep_vars "${module_name}_${fphlc_dep}_FOUND") + list(APPEND fphlc_dep_targets "${FPHLC_NAMESPACE}::${fphlc_dep}") + endforeach() + endif() + + if(NOT FPHLC_SKIP_PKG_CONFIG AND ${module_name}_${fphlc_comp}_pkg_config) + pkg_check_modules(PKG_${module_name}_${fphlc_comp} QUIET + ${${module_name}_${fphlc_comp}_pkg_config}) + endif() + + if("${${module_name}_${fphlc_comp}_lib}" STREQUAL "") + set(fphlc_library_type INTERFACE) + set(fphlc_required_vars "${module_name}_${fphlc_comp}_INCLUDE_DIR") + else() + set(fphlc_library_type UNKNOWN) + set(fphlc_required_vars "${module_name}_${fphlc_comp}_LIBRARY;${module_name}_${fphlc_comp}_INCLUDE_DIR") + endif() + + find_path(${module_name}_${fphlc_comp}_INCLUDE_DIR + NAMES ${${module_name}_${fphlc_comp}_header} + HINTS ${PKG_${module_name}_${fphlc_comp}_INCLUDE_DIRS} + PATH_SUFFIXES ${${module_name}_${fphlc_comp}_header_subdir} + ) + find_library(${module_name}_${fphlc_comp}_LIBRARY + NAMES ${${module_name}_${fphlc_comp}_lib} + HINTS ${PKG_${module_name}_${fphlc_comp}_LIBRARY_DIRS} + ) + + set(${module_name}_${fphlc_comp}_VERSION "${PKG_${module_name}_${fphlc_comp}_VERSION}") + if(NOT ${module_name}_VERSION) + set(${module_name}_VERSION ${${module_name}_${fphlc_comp}_VERSION}) + endif() + + find_package_handle_standard_args(${module_name}_${fphlc_comp} + FOUND_VAR + ${module_name}_${fphlc_comp}_FOUND + REQUIRED_VARS + ${fphlc_required_vars} + ${fphlc_dep_vars} + VERSION_VAR + ${module_name}_${fphlc_comp}_VERSION + ) + + mark_as_advanced( + ${module_name}_${fphlc_comp}_LIBRARY + ${module_name}_${fphlc_comp}_INCLUDE_DIR + ) + + if(${module_name}_${fphlc_comp}_FOUND) + if("${fphlc_library_type}" STREQUAL "UNKNOWN") + list(APPEND ${module_name}_LIBRARIES + "${${module_name}_${fphlc_comp}_LIBRARY}") + endif() + list(APPEND ${module_name}_INCLUDE_DIRS + "${${module_name}_${fphlc_comp}_INCLUDE_DIR}") + set(${module_name}_DEFINITIONS + ${${module_name}_DEFINITIONS} + ${PKG_${module_name}_${fphlc_comp}_DEFINITIONS}) + if(NOT TARGET ${FPHLC_NAMESPACE}::${fphlc_comp}) + add_library(${FPHLC_NAMESPACE}::${fphlc_comp} ${fphlc_library_type} IMPORTED) + set_target_properties(${FPHLC_NAMESPACE}::${fphlc_comp} PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PKG_${module_name}_${fphlc_comp}_DEFINITIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${${module_name}_${fphlc_comp}_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${fphlc_dep_targets}" + ) + if("${fphlc_library_type}" STREQUAL "UNKNOWN") + set_target_properties(${FPHLC_NAMESPACE}::${fphlc_comp} PROPERTIES + IMPORTED_LOCATION "${${module_name}_${fphlc_comp}_LIBRARY}" + ) + endif() + endif() + list(APPEND ${module_name}_TARGETS + "${FPHLC_NAMESPACE}::${fphlc_comp}") + endif() + endforeach() + if(${module_name}_LIBRARIES) + list(REMOVE_DUPLICATES ${module_name}_LIBRARIES) + endif() + if(${module_name}_INCLUDE_DIRS) + list(REMOVE_DUPLICATES ${module_name}_INCLUDE_DIRS) + endif() + if(${module_name}_DEFINITIONS) + list(REMOVE_DUPLICATES ${module_name}_DEFINITIONS) + endif() + if(${module_name}_TARGETS) + list(REMOVE_DUPLICATES ${module_name}_TARGETS) + endif() +endmacro() diff --git a/cmake/modules/FindPangoCairo.cmake b/cmake/modules/FindPangoCairo.cmake new file mode 100644 index 0000000..44e5972 --- /dev/null +++ b/cmake/modules/FindPangoCairo.cmake @@ -0,0 +1,67 @@ +# FindPangoCairo.cmake +# +# CMake support for PangoCairo. +# +find_package(PkgConfig QUIET) + +set(PangoCairo_DEPS + Pango + Cairo +) + +if(PKG_CONFIG_FOUND) + pkg_search_module(PangoCairo_PKG pangocairo) +endif() + +find_library(PangoCairo_LIBRARY pangocairo-1.0 HINTS ${PangoCairo_PKG_LIBRARY_DIRS}) +set(PangoCairo pangocairo) + +if(PangoCairo_LIBRARY AND NOT TARGET ${PangoCairo}) + add_library(${PangoCairo} SHARED IMPORTED) + set_property(TARGET ${PangoCairo} PROPERTY IMPORTED_LOCATION "${PangoCairo_LIBRARY}") + set_property(TARGET ${PangoCairo} PROPERTY INTERFACE_COMPILE_OPTIONS "${PangoCairo_PKG_CFLAGS_OTHER}") + + find_path(PangoCairo_INCLUDE_DIR "pango/pangocairo.h" + HINTS + ${PangoCairo_PKG_INCLUDE_DIRS} + ) + + if(PangoCairo_INCLUDE_DIR) + file(STRINGS "${PangoCairo_INCLUDE_DIR}/pango/pango-features.h" PangoCairo_MAJOR_VERSION REGEX "^#define PANGO_VERSION_MAJOR +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define PANGO_VERSION_MAJOR \\(?([0-9]+)\\)?" "\\1" PangoCairo_MAJOR_VERSION "${PangoCairo_MAJOR_VERSION}") + file(STRINGS "${PangoCairo_INCLUDE_DIR}/pango/pango-features.h" PangoCairo_MINOR_VERSION REGEX "^#define PANGO_VERSION_MINOR +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define PANGO_VERSION_MINOR \\(?([0-9]+)\\)?" "\\1" PangoCairo_MINOR_VERSION "${PangoCairo_MINOR_VERSION}") + file(STRINGS "${PangoCairo_INCLUDE_DIR}/pango/pango-features.h" PangoCairo_MICRO_VERSION REGEX "^#define PANGO_VERSION_MICRO +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define PANGO_VERSION_MICRO \\(?([0-9]+)\\)?" "\\1" PangoCairo_MICRO_VERSION "${PangoCairo_MICRO_VERSION}") + set(PangoCairo_VERSION "${PangoCairo_MAJOR_VERSION}.${PangoCairo_MINOR_VERSION}.${PangoCairo_MICRO_VERSION}") + unset(PangoCairo_MAJOR_VERSION) + unset(PangoCairo_MINOR_VERSION) + unset(PangoCairo_MICRO_VERSION) + + list(APPEND PangoCairo_INCLUDE_DIRS ${PangoCairo_INCLUDE_DIR}) + set_property(TARGET ${PangoCairo} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PangoCairo_INCLUDE_DIR}") + endif() +endif() + +set(PangoCairo_DEPS_FOUND_VARS) +include(CMakeFindDependencyMacro) +foreach(pangocairo_dep ${PangoCairo_DEPS}) + find_dependency(${pangocairo_dep}) + + list(APPEND PangoCairo_DEPS_FOUND_VARS "${pangocairo_dep}_FOUND") + list(APPEND PangoCairo_INCLUDE_DIRS ${${pangocairo_dep}_INCLUDE_DIRS}) + + set_property (TARGET "${PangoCairo}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${pango_dep}}") +endforeach(pangocairo_dep) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PangoCairo + REQUIRED_VARS + PangoCairo_LIBRARY + PangoCairo_INCLUDE_DIRS + ${PangoCairo_DEPS_FOUND_VARS} + VERSION_VAR + PangoCairo_VERSION +) + +unset(PangoCairo_DEPS_FOUND_VARS) diff --git a/cmake/modules/FindXKBCommon.cmake b/cmake/modules/FindXKBCommon.cmake new file mode 100644 index 0000000..b3a72aa --- /dev/null +++ b/cmake/modules/FindXKBCommon.cmake @@ -0,0 +1,110 @@ +# Try to find xkbcommon +# +# Available components: +# XKBCommon - The whole xkbcommon library +# KeySyms - The interface library containing only xkbcommon-keysyms.h +# +# This will define: +# +# XKBCommon_FOUND - True if xkbcommon is available +# XKBCommon_LIBRARIES - Found libraries for xkbcommon +# XKBCommon_INCLUDE_DIRS - Include directory for xkbcommon +# XKBCommon_DEFINITIONS - Compiler flags for using xkbcommon +# +# Additionally, the following imported targets will be defined: +# +# XKB::XKBCommon +# XKB::KeySyms +# +include(ECMFindModuleHelpersStub) +include(FindPackageHandleStandardArgs) + +ecm_find_package_version_check(XKBCommon) + +# Note that this list needs to be ordered such that any component appears after its dependencies +set(XKBCommon_known_components + XKBCommon + KeySyms +) + +set(XKBCommon_XKBCommon_component_deps) +set(XKBCommon_XKBCommon_pkg_config "xkbcommon") +set(XKBCommon_XKBCommon_lib "xkbcommon") +set(XKBCommon_XKBCommon_header "xkbcommon/xkbcommon.h") + +set(XKBCommon_KeySyms_component_deps) +set(XKBCommon_KeySyms_pkg_config "xkbcommon") +set(XKBCommon_KeySyms_lib) +set(XKBCommon_KeySyms_header "xkbcommon/xkbcommon-keysyms.h") + +# Parse components +ecm_find_package_parse_components(XKBCommon + RESULT_VAR XKBCommon_components + KNOWN_COMPONENTS ${XKBCommon_known_components} +) + +# Find each component +# use our private version of find_package_handle_library_components +# that also handles interface library +find_package_handle_library_components(XKBCommon + NAMESPACE XKB + COMPONENTS ${XKBCommon_components} +) + +set(XKBCommon_component_FOUND_VARS) +foreach(comp ${XKBCommon_components}) + list(APPEND XKBCommon_component_FOUND_VARS "XKBCommon_${comp}_FOUND") +endforeach(comp) + +find_package_handle_standard_args(XKBCommon + FOUND_VAR + XKBCommon_FOUND + REQUIRED_VARS + ${XKBCommon_component_FOUND_VARS} + VERSION_VAR + XKBCommon_VERSION + HANDLE_COMPONENTS +) + +unset(XKBCommon_component_FOUND_VARS) + +## Use pkg-config to get the directories and then use these values +## in the FIND_PATH() and FIND_LIBRARY() calls +#find_package(PkgConfig) +#pkg_check_modules(PKG_XKB QUIET xkbcommon) +# +#set(XKBCommonKeySyms_DEFINITIONS ${PKG_XKB_CFLAGS_OTHER}) +# +#find_path(XKBCommonKeySyms_INCLUDE_DIR +# NAMES +# xkbcommon/xkbcommon-keysyms.h +# HINTS +# ${PKG_XKB_INCLUDE_DIRS} +#) +# +#set(XKBCommonKeySyms_INCLUDE_DIRS ${XKBCommonKeySyms_INCLUDE_DIR}) +#set(XKBCommonKeySyms_VERSION ${PKG_XKB_VERSION}) +# +#include(FindPackageHandleStandardArgs) +#find_package_handle_standard_args(XKB +# FOUND_VAR +# XKBCommonKeySyms_FOUND +# REQUIRED_VARS +# XKBCommonKeySyms_INCLUDE_DIRS +# VERSION_VAR +# XKBCommonKeySyms_VERSION +#) +# +#if(XKBCommonKeySyms_FOUND AND NOT TARGET XKB::KeySyms) +# add_library(XKB::KeySyms INTERFACE IMPORTED) +# set_target_properties(XKB::KeySyms PROPERTIES +# INTERFACE_COMPILE_OPTIONS "${XKBCommonKeySyms_DEFINITIONS}" +# INTERFACE_INCLUDE_DIRECTORIES "${XKBCommonKeySyms_INCLUDE_DIRS}" +# ) +#endif() + +include(FeatureSummary) +set_package_properties(XKBCommon PROPERTIES + URL "http://xkbcommon.org" + DESCRIPTION "Keyboard handling library using XKB data" +) diff --git a/cmake/modules/gnome-cmake/.gitignore b/cmake/modules/gnome-cmake/.gitignore new file mode 100644 index 0000000..5370f6a --- /dev/null +++ b/cmake/modules/gnome-cmake/.gitignore @@ -0,0 +1,3 @@ +*~ +*.# +*.bak diff --git a/cmake/modules/gnome-cmake/COPYING b/cmake/modules/gnome-cmake/COPYING new file mode 100644 index 0000000..630eb0e --- /dev/null +++ b/cmake/modules/gnome-cmake/COPYING @@ -0,0 +1,20 @@ +Copyright (c) 2016 Evan Nemerson + +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. diff --git a/cmake/modules/gnome-cmake/README.md b/cmake/modules/gnome-cmake/README.md new file mode 100644 index 0000000..22517a4 --- /dev/null +++ b/cmake/modules/gnome-cmake/README.md @@ -0,0 +1,33 @@ +# CMake modules for GNOME libraries and tools + +This is a collection of CMake modules to support using GNOME libraries +and tools from CMake-based projects. These modules were initially +intended for use from Vala projects, but many can be used for other +languages as well. + +There are currently modules for: + +* ATK +* Cairo +* GDK3 +* GDKPixbuf +* GIO +* GLib +* GObject +* GObjectIntrospection +* GTK3 +* Pango +* Soup +* Vala +* Valadoc + +Packages for libraries create imported targets with the same name as +the pkg-config file. + +Several of the modules also contain functions for utilizing them; for +example, the Vala contains a function to use the Vala compiler, +GObjectIntrospection contains a function to generate a typelib from a +GIR, and so on. + +This is still very much a work in progress, but it is already fairly +useful. diff --git a/cmake/modules/gnome-cmake/modules/FindATK.cmake b/cmake/modules/gnome-cmake/modules/FindATK.cmake new file mode 100644 index 0000000..02463d6 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindATK.cmake @@ -0,0 +1,89 @@ +# FindPango.cmake +# +# +# CMake support for ATK. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(ATK_DEPS + GLib) + +if(PKG_CONFIG_FOUND) + pkg_search_module(ATK_PKG atk) +endif() + +find_library(ATK_LIBRARY atk-1.0 HINTS ${ATK_PKG_LIBRARY_DIRS}) +set(ATK "atk-1.0") + +if(ATK_LIBRARY AND NOT TARGET ${ATK}) + add_library(${ATK} SHARED IMPORTED) + set_property(TARGET ${ATK} PROPERTY IMPORTED_LOCATION "${ATK_LIBRARY}") + set_property(TARGET ${ATK} PROPERTY INTERFACE_COMPILE_OPTIONS "${ATK_PKG_CFLAGS_OTHER}") + + find_path(ATK_INCLUDE_DIR "atk/atk.h" + HINTS ${ATK_PKG_INCLUDE_DIRS}) + + if(ATK_INCLUDE_DIR) + file(STRINGS "${ATK_INCLUDE_DIR}/atk/atkversion.h" ATK_MAJOR_VERSION REGEX "^#define ATK_MAJOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define ATK_MAJOR_VERSION \\(([0-9]+)\\)$" "\\1" ATK_MAJOR_VERSION "${ATK_MAJOR_VERSION}") + file(STRINGS "${ATK_INCLUDE_DIR}/atk/atkversion.h" ATK_MINOR_VERSION REGEX "^#define ATK_MINOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define ATK_MINOR_VERSION \\(([0-9]+)\\)$" "\\1" ATK_MINOR_VERSION "${ATK_MINOR_VERSION}") + file(STRINGS "${ATK_INCLUDE_DIR}/atk/atkversion.h" ATK_MICRO_VERSION REGEX "^#define ATK_MICRO_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define ATK_MICRO_VERSION \\(([0-9]+)\\)$" "\\1" ATK_MICRO_VERSION "${ATK_MICRO_VERSION}") + set(ATK_VERSION "${ATK_MAJOR_VERSION}.${ATK_MINOR_VERSION}.${ATK_MICRO_VERSION}") + unset(ATK_MAJOR_VERSION) + unset(ATK_MINOR_VERSION) + unset(ATK_MICRO_VERSION) + + list(APPEND ATK_INCLUDE_DIRS ${ATK_INCLUDE_DIR}) + set_property(TARGET ${ATK} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ATK_INCLUDE_DIR}") + endif() +endif() + +set(ATK_DEPS_FOUND_VARS) +include(CMakeFindDependencyMacro) +foreach(atk_dep ${ATK_DEPS}) + find_dependency(${atk_dep}) + + list(APPEND ATK_DEPS_FOUND_VARS "${atk_dep}_FOUND") + list(APPEND ATK_INCLUDE_DIRS ${${atk_dep}_INCLUDE_DIRS}) + + set_property (TARGET "${ATK}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${atk_dep}}") +endforeach(atk_dep) +unset(_required) +unset(_quiet) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ATK + REQUIRED_VARS + ATK_LIBRARY + ATK_INCLUDE_DIRS + ${ATK_DEPS_FOUND_VARS} + VERSION_VAR + ATK_VERSION) + +unset(ATK_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindCairo.cmake b/cmake/modules/gnome-cmake/modules/FindCairo.cmake new file mode 100644 index 0000000..9fab87d --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindCairo.cmake @@ -0,0 +1,88 @@ +# FindCairo.cmake +# +# +# CMake support for Cairo. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(Cairo_DEPS) + +if(PKG_CONFIG_FOUND) + pkg_search_module(Cairo_PKG cairo) +endif() + +find_library(Cairo_LIBRARY cairo HINTS ${Cairo_PKG_LIBRARY_DIRS}) +set(Cairo cairo) + +if(Cairo_LIBRARY AND NOT TARGET ${Cairo}) + add_library(${Cairo} SHARED IMPORTED) + set_property(TARGET ${Cairo} PROPERTY IMPORTED_LOCATION "${Cairo_LIBRARY}") + set_property(TARGET ${Cairo} PROPERTY INTERFACE_COMPILE_OPTIONS "${Cairo_PKG_CFLAGS_OTHER}") + + set(Cairo_INCLUDE_DIRS) + + find_path(Cairo_INCLUDE_DIR "cairo.h" + HINTS ${Cairo_PKG_INCLUDE_DIRS}) + + if(Cairo_INCLUDE_DIR) + file(STRINGS "${Cairo_INCLUDE_DIR}/cairo-version.h" Cairo_VERSION_MAJOR REGEX "^#define CAIRO_VERSION_MAJOR +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define CAIRO_VERSION_MAJOR \\(?([0-9]+)\\)?$" "\\1" Cairo_VERSION_MAJOR "${Cairo_VERSION_MAJOR}") + file(STRINGS "${Cairo_INCLUDE_DIR}/cairo-version.h" Cairo_VERSION_MINOR REGEX "^#define CAIRO_VERSION_MINOR +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define CAIRO_VERSION_MINOR \\(?([0-9]+)\\)?$" "\\1" Cairo_VERSION_MINOR "${Cairo_VERSION_MINOR}") + file(STRINGS "${Cairo_INCLUDE_DIR}/cairo-version.h" Cairo_VERSION_MICRO REGEX "^#define CAIRO_VERSION_MICRO +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define CAIRO_VERSION_MICRO \\(?([0-9]+)\\)?$" "\\1" Cairo_VERSION_MICRO "${Cairo_VERSION_MICRO}") + set(Cairo_VERSION "${Cairo_VERSION_MAJOR}.${Cairo_VERSION_MINOR}.${Cairo_VERSION_MICRO}") + unset(Cairo_VERSION_MAJOR) + unset(Cairo_VERSION_MINOR) + unset(Cairo_VERSION_MICRO) + + list(APPEND Cairo_INCLUDE_DIRS ${Cairo_INCLUDE_DIR}) + set_property(TARGET ${Cairo} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${Cairo_INCLUDE_DIR}") + endif() +endif() + +set(Cairo_DEPS_FOUND_VARS) +include(CMakeFindDependencyMacro) +foreach(cairo_dep ${Cairo_DEPS}) + find_dependency(${cairo_dep}) + + list(APPEND Cairo_DEPS_FOUND_VARS "${cairo_dep}_FOUND") + list(APPEND Cairo_INCLUDE_DIRS ${${cairo_dep}_INCLUDE_DIRS}) + + set_property (TARGET ${Cairo} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${cairo_dep}}") +endforeach(cairo_dep) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Cairo + REQUIRED_VARS + Cairo_LIBRARY + Cairo_INCLUDE_DIRS + ${Cairo_DEPS_FOUND_VARS} + VERSION_VAR + Cairo_VERSION) + +unset(Cairo_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindGDK3.cmake b/cmake/modules/gnome-cmake/modules/FindGDK3.cmake new file mode 100644 index 0000000..6db4f72 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindGDK3.cmake @@ -0,0 +1,89 @@ +# FindGDK3.cmake +# +# +# CMake support for GDK 3. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(GDK3_DEPS + Pango) + +if(PKG_CONFIG_FOUND) + pkg_search_module(GDK3_PKG gdk-3.0) +endif() + +find_library(GDK3_LIBRARY gdk-3 HINTS ${GDK3_PKG_LIBRARY_DIRS}) +set(GDK3 "gdk-3") + +if(GDK3_LIBRARY AND NOT TARGET ${GDK3}) + add_library(${GDK3} SHARED IMPORTED) + set_property(TARGET ${GDK3} PROPERTY IMPORTED_LOCATION "${GDK3_LIBRARY}") + set_property(TARGET ${GDK3} PROPERTY INTERFACE_COMPILE_OPTIONS "${GDK3_PKG_CFLAGS_OTHER}") + + set(GDK3_INCLUDE_DIRS) + + find_path(GDK3_INCLUDE_DIR "gdk/gdk.h" + HINTS ${GDK3_PKG_INCLUDE_DIRS}) + + if(GDK3_INCLUDE_DIR) + file(STRINGS "${GDK3_INCLUDE_DIR}/gdk/gdkversionmacros.h" GDK3_MAJOR_VERSION REGEX "^#define GDK_MAJOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define GDK_MAJOR_VERSION \\(?([0-9]+)\\)?$" "\\1" GDK3_MAJOR_VERSION "${GDK3_MAJOR_VERSION}") + file(STRINGS "${GDK3_INCLUDE_DIR}/gdk/gdkversionmacros.h" GDK3_MINOR_VERSION REGEX "^#define GDK_MINOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define GDK_MINOR_VERSION \\(?([0-9]+)\\)?$" "\\1" GDK3_MINOR_VERSION "${GDK3_MINOR_VERSION}") + file(STRINGS "${GDK3_INCLUDE_DIR}/gdk/gdkversionmacros.h" GDK3_MICRO_VERSION REGEX "^#define GDK_MICRO_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define GDK_MICRO_VERSION \\(?([0-9]+)\\)?$" "\\1" GDK3_MICRO_VERSION "${GDK3_MICRO_VERSION}") + set(GDK3_VERSION "${GDK3_MAJOR_VERSION}.${GDK3_MINOR_VERSION}.${GDK3_MICRO_VERSION}") + unset(GDK3_MAJOR_VERSION) + unset(GDK3_MINOR_VERSION) + unset(GDK3_MICRO_VERSION) + + list(APPEND GDK3_INCLUDE_DIRS ${GDK3_INCLUDE_DIR}) + set_property(TARGET ${GDK3} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GDK3_INCLUDE_DIR}") + endif() +endif() + +set(GDK3_DEPS_FOUND_VARS) +include(CMakeFindDependencyMacro) +foreach(gdk3_dep ${GDK3_DEPS}) + find_dependency(${gdk3_dep}) + + list(APPEND GDK3_DEPS_FOUND_VARS "${gdk3_dep}_FOUND") + list(APPEND GDK3_INCLUDE_DIRS ${${gdk3_dep}_INCLUDE_DIRS}) + + set_property (TARGET ${GDK3} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${gdk3_dep}}") +endforeach(gdk3_dep) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GDK3 + REQUIRED_VARS + GDK3_LIBRARY + GDK3_INCLUDE_DIRS + ${GDK3_DEPS_FOUND_VARS} + VERSION_VAR + GDK3_VERSION) + +unset(GDK3_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindGDKPixbuf.cmake b/cmake/modules/gnome-cmake/modules/FindGDKPixbuf.cmake new file mode 100644 index 0000000..a90bdcb --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindGDKPixbuf.cmake @@ -0,0 +1,81 @@ +# FindGDKPixbuf.cmake +# +# +# CMake support for GDK Pixbuf. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(GDKPixbuf_DEPS + GLib) + +if(PKG_CONFIG_FOUND) + pkg_search_module(GDKPixbuf_PKG gdk-pixbuf-2.0) +endif() + +find_library(GDKPixbuf_LIBRARY gdk_pixbuf-2.0 HINTS ${GDKPixbuf_PKG_LIBRARY_DIRS}) +set(GDKPixbuf "gdk_pixbuf-2.0") + +if(GDKPixbuf_LIBRARY AND NOT TARGET ${GDKPixbuf}) + add_library(${GDKPixbuf} SHARED IMPORTED) + set_property(TARGET ${GDKPixbuf} PROPERTY IMPORTED_LOCATION "${GDKPixbuf_LIBRARY}") + set_property(TARGET ${GDKPixbuf} PROPERTY INTERFACE_COMPILE_OPTIONS "${GDKPixbuf_PKG_CFLAGS_OTHER}") + + set(GDKPixbuf_INCLUDE_DIRS) + + find_path(GDKPixbuf_INCLUDE_DIR "gdk-pixbuf/gdk-pixbuf.h" + HINTS ${GDKPixbuf_PKG_INCLUDE_DIRS}) + + if(GDKPixbuf_INCLUDE_DIR) + file(STRINGS "${GDKPixbuf_INCLUDE_DIR}/gdk-pixbuf/gdk-pixbuf-features.h" GDKPixbuf_VERSION REGEX "^#define GDKPIXBUF_VERSION \\\"[^\\\"]+\\\"") + string(REGEX REPLACE "^#define GDKPIXBUF_VERSION \\\"([0-9]+)\\.([0-9]+)\\.([0-9]+)\\\"$" "\\1.\\2.\\3" GDKPixbuf_VERSION "${GDKPixbuf_VERSION}") + + list(APPEND GDKPixbuf_INCLUDE_DIRS ${GDKPixbuf_INCLUDE_DIR}) + set_property(TARGET ${GDKPixbuf} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GDKPixbuf_INCLUDE_DIR}") + endif() +endif() + +set(GDKPixbuf_DEPS_FOUND_VARS) +include(CMakeFindDependencyMacro) +foreach(gdkpixbuf_dep ${GDKPixbuf_DEPS}) + find_dependency(${gdkpixbuf_dep}) + + list(APPEND GDKPixbuf_DEPS_FOUND_VARS "${gdkpixbuf_dep}_FOUND") + list(APPEND GDKPixbuf_INCLUDE_DIRS ${${gdkpixbuf_dep}_INCLUDE_DIRS}) + + set_property (TARGET ${GDKPixbuf} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${gdkpixbuf_dep}}") +endforeach(gdkpixbuf_dep) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GDKPixbuf + REQUIRED_VARS + GDKPixbuf_LIBRARY + GDKPixbuf_INCLUDE_DIRS + ${GDKPixbuf_DEPS_FOUND_VARS} + VERSION_VAR + GDKPixbuf_VERSION) + +unset(GDKPixbuf_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindGIO.cmake b/cmake/modules/gnome-cmake/modules/FindGIO.cmake new file mode 100644 index 0000000..26e5fa5 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindGIO.cmake @@ -0,0 +1,199 @@ +# FindGIO.cmake +# +# +# CMake support for GIO. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(GIO_DEPS + GObject) + +if(PKG_CONFIG_FOUND) + pkg_search_module(GIO_PKG gio-2.0) +endif() + +find_library(GIO_LIBRARY gio-2.0 HINTS ${GIO_PKG_LIBRARY_DIRS}) +set(GIO "gio-2.0") + +if(GIO_LIBRARY AND NOT TARGET ${GIO}) + add_library(${GIO} SHARED IMPORTED) + set_property(TARGET ${GIO} PROPERTY IMPORTED_LOCATION "${GIO_LIBRARY}") + set_property(TARGET ${GIO} PROPERTY INTERFACE_COMPILE_OPTIONS "${GIO_PKG_CFLAGS_OTHER}") + + find_path(GIO_INCLUDE_DIR "gio/gio.h" + HINTS ${GIO_PKG_INCLUDE_DIRS}) + + include(CMakeFindDependencyMacro) + find_dependency(GLib) + find_dependency(GObject) + set(GIO_VERSION "${GLib_VERSION}") + + list(APPEND GIO_DEPS_FOUND_VARS "GObject_FOUND") + list(APPEND GIO_INCLUDE_DIRS ${GObject_INCLUDE_DIRS}) + + set_property (TARGET "${GIO}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "gobject-2.0") + set_property(TARGET ${GIO} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GIO_INCLUDE_DIR}") +endif() + +find_program(GLib_COMPILE_SCHEMAS glib-compile-schemas) +if(GLib_COMPILE_SCHEMAS AND NOT TARGET glib-compile-schemas) + add_executable(glib-compile-schemas IMPORTED) + set_property(TARGET glib-compile-schemas PROPERTY IMPORTED_LOCATION "${GLib_COMPILE_SCHEMAS}") +endif() + +# glib_install_schemas( +# [DESTINATION directory] +# schemas…) +# +# Validate and install the listed schemas. +function(glib_install_schemas) + set (options) + set (oneValueArgs DESTINATION) + set (multiValueArgs) + cmake_parse_arguments(GSCHEMA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + unset (options) + unset (oneValueArgs) + unset (multiValueArgs) + + foreach(schema ${GSCHEMA_UNPARSED_ARGUMENTS}) + get_filename_component(schema_name "${schema}" NAME) + string(REGEX REPLACE "^(.+)\.gschema.xml$" "\\1" schema_name "${schema_name}") + set(schema_output "${CMAKE_CURRENT_BINARY_DIR}/${schema_name}.gschema.xml.valid") + + add_custom_command( + OUTPUT "${schema_output}" + COMMAND glib-compile-schemas + --strict + --dry-run + --schema-file="${schema}" + COMMAND "${CMAKE_COMMAND}" ARGS -E touch "${schema_output}" + DEPENDS "${schema}" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT "Validating ${schema}") + + add_custom_target("gsettings-schema-${schema_name}" ALL + DEPENDS "${schema_output}") + + if(CMAKE_INSTALL_FULL_DATADIR) + set(SCHEMADIR "${CMAKE_INSTALL_FULL_DATADIR}/glib-2.0/schemas") + else() + set(SCHEMADIR "${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas") + endif() + install(FILES "${schema}" + DESTINATION "${SCHEMADIR}") + install(CODE "execute_process(COMMAND \"${GLib_COMPILE_SCHEMAS}\" \"${SCHEMADIR}\")") + endforeach() +endfunction() + +find_program(GLib_COMPILE_RESOURCES glib-compile-resources) +if(GLib_COMPILE_RESOURCES AND NOT TARGET glib-compile-resources) + add_executable(glib-compile-resources IMPORTED) + set_property(TARGET glib-compile-resources PROPERTY IMPORTED_LOCATION "${GLib_COMPILE_RESOURCES}") +endif() + +function(glib_compile_resources SPEC_FILE) + set (options INTERNAL) + set (oneValueArgs TARGET SOURCE_DIR HEADER SOURCE C_NAME) + set (multiValueArgs) + cmake_parse_arguments(GLib_COMPILE_RESOURCES "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + unset (options) + unset (oneValueArgs) + unset (multiValueArgs) + + if(NOT GLib_COMPILE_RESOURCES_SOURCE_DIR) + set(GLib_COMPILE_RESOURCES_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + + set(FLAGS) + + if(GLib_COMPILE_RESOURCES_INTERNAL) + list(APPEND FLAGS "--internal") + endif() + + if(GLib_COMPILE_RESOURCES_C_NAME) + list(APPEND FLAGS "--c-name" "${GLib_COMPILE_RESOURCES_C_NAME}") + endif() + + get_filename_component(SPEC_FILE "${SPEC_FILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + + execute_process( + COMMAND glib-compile-resources + --generate-dependencies + --sourcedir "${GLib_COMPILE_RESOURCES_SOURCE_DIR}" + "${SPEC_FILE}" + OUTPUT_VARIABLE deps + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REPLACE "\n" ";" deps ${deps}) + + if(GLib_COMPILE_RESOURCES_HEADER) + get_filename_component(GLib_COMPILE_RESOURCES_HEADER "${GLib_COMPILE_RESOURCES_HEADER}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}") + + add_custom_command( + OUTPUT "${GLib_COMPILE_RESOURCES_HEADER}" + COMMAND glib-compile-resources + --sourcedir "${GLib_COMPILE_RESOURCES_SOURCE_DIR}" + --generate-header + --target "${GLib_COMPILE_RESOURCES_HEADER}" + ${FLAGS} + "${SPEC_FILE}" + DEPENDS "${SPEC_FILE}" ${deps} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + + if(GLib_COMPILE_RESOURCES_SOURCE) + get_filename_component(GLib_COMPILE_RESOURCES_SOURCE "${GLib_COMPILE_RESOURCES_SOURCE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}") + + add_custom_command( + OUTPUT "${GLib_COMPILE_RESOURCES_SOURCE}" + COMMAND glib-compile-resources + --sourcedir "${GLib_COMPILE_RESOURCES_SOURCE_DIR}" + --generate-source + --target "${GLib_COMPILE_RESOURCES_SOURCE}" + ${FLAGS} + "${SPEC_FILE}" + DEPENDS "${SPEC_FILE}" ${deps} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + endif() +endfunction() + +find_program(GDBUS_CODEGEN gdbus-codegen) +if(GDBUS_CODEGEN AND NOT TARGET gdbus-codegen) + add_executable(gdbus-codegen IMPORTED) + set_property(TARGET gdbus-codegen PROPERTY IMPORTED_LOCATION "${GDBUS_CODEGEN}") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GIO + REQUIRED_VARS + GIO_LIBRARY + GIO_INCLUDE_DIRS + ${GIO_DEPS_FOUND_VARS} + VERSION_VAR + GIO_VERSION) + +unset(GIO_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindGLib.cmake b/cmake/modules/gnome-cmake/modules/FindGLib.cmake new file mode 100644 index 0000000..d6de066 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindGLib.cmake @@ -0,0 +1,83 @@ +# FindGLib.cmake +# +# +# CMake support for GLib/GObject/GIO. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +if(PKG_CONFIG_FOUND) + pkg_search_module(GLib_PKG glib-2.0) +endif() + +find_library(GLib_LIBRARY glib-2.0 HINTS ${GLib_PKG_LIBRARY_DIRS}) +set(GLib glib-2.0) + +if(GLib_LIBRARY AND NOT TARGET ${GLib}) + add_library(${GLib} SHARED IMPORTED) + set_property(TARGET ${GLib} PROPERTY IMPORTED_LOCATION "${GLib_LIBRARY}") + set_property(TARGET ${GLib} PROPERTY INTERFACE_COMPILE_OPTIONS "${GLib_PKG_CFLAGS_OTHER}") + + find_path(GLib_INCLUDE_DIRS "glib.h" + HINTS ${GLib_PKG_INCLUDE_DIRS} + PATH_SUFFIXES "glib-2.0") + + get_filename_component(GLib_LIBDIR "${GLib}" DIRECTORY) + find_path(GLib_CONFIG_INCLUDE_DIR "glibconfig.h" + HINTS + ${GLib_LIBDIR} + ${GLib_PKG_INCLUDE_DIRS} + PATHS + "${CMAKE_LIBRARY_PATH}" + PATH_SUFFIXES + "glib-2.0/include" + "glib-2.0") + unset(GLib_LIBDIR) + + if(GLib_CONFIG_INCLUDE_DIR) + file(STRINGS "${GLib_CONFIG_INCLUDE_DIR}/glibconfig.h" GLib_MAJOR_VERSION REGEX "^#define GLIB_MAJOR_VERSION +([0-9]+)") + string(REGEX REPLACE "^#define GLIB_MAJOR_VERSION ([0-9]+)$" "\\1" GLib_MAJOR_VERSION "${GLib_MAJOR_VERSION}") + file(STRINGS "${GLib_CONFIG_INCLUDE_DIR}/glibconfig.h" GLib_MINOR_VERSION REGEX "^#define GLIB_MINOR_VERSION +([0-9]+)") + string(REGEX REPLACE "^#define GLIB_MINOR_VERSION ([0-9]+)$" "\\1" GLib_MINOR_VERSION "${GLib_MINOR_VERSION}") + file(STRINGS "${GLib_CONFIG_INCLUDE_DIR}/glibconfig.h" GLib_MICRO_VERSION REGEX "^#define GLIB_MICRO_VERSION +([0-9]+)") + string(REGEX REPLACE "^#define GLIB_MICRO_VERSION ([0-9]+)$" "\\1" GLib_MICRO_VERSION "${GLib_MICRO_VERSION}") + set(GLib_VERSION "${GLib_MAJOR_VERSION}.${GLib_MINOR_VERSION}.${GLib_MICRO_VERSION}") + unset(GLib_MAJOR_VERSION) + unset(GLib_MINOR_VERSION) + unset(GLib_MICRO_VERSION) + + list(APPEND GLib_INCLUDE_DIRS ${GLib_CONFIG_INCLUDE_DIR}) + set_property(TARGET ${GLib} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GLib_INCLUDE_DIRS}") + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLib + REQUIRED_VARS + GLib_LIBRARY + GLib_INCLUDE_DIRS + VERSION_VAR + GLib_VERSION) diff --git a/cmake/modules/gnome-cmake/modules/FindGObject.cmake b/cmake/modules/gnome-cmake/modules/FindGObject.cmake new file mode 100644 index 0000000..6938e05 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindGObject.cmake @@ -0,0 +1,82 @@ +# FindGObject.cmake +# +# +# CMake support for GObject. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(GObject_DEPS + GLib) + +if(PKG_CONFIG_FOUND) + pkg_search_module(GObject_PKG gobject-2.0) +endif() + +find_library(GObject_LIBRARY gobject-2.0 HINTS ${GObject_PKG_LIBRARY_DIRS}) +set(GObject gobject-2.0) + +if(GObject_LIBRARY AND NOT TARGET ${GObject}) + add_library(${GObject} SHARED IMPORTED) + set_property(TARGET ${GObject} PROPERTY IMPORTED_LOCATION "${GObject_LIBRARY}") + set_property(TARGET ${GObject} PROPERTY INTERFACE_COMPILE_OPTIONS "${GObject_PKG_CFLAGS_OTHER}") + + find_path(GObject_INCLUDE_DIR "gobject/gobject.h" + HINTS ${GObject_PKG_INCLUDE_DIRS}) + + include(CMakeFindDependencyMacro) + find_dependency(GLib) + set(GObject_VERSION "${GLib_VERSION}") + + list(APPEND GObject_DEPS_FOUND_VARS "GLib_FOUND") + list(APPEND GObject_INCLUDE_DIRS ${GLib_INCLUDE_DIRS}) + set_property(TARGET ${GObject} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GObject_INCLUDE_DIR}") + + set_property (TARGET "${GObject}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${GLib}") +endif() + +find_program(GLib_GENMARSHAL glib-genmarshal) +if(GLib_GENMARSHAL AND NOT TARGET glib-genmarshal) + add_executable(glib-genmarshal IMPORTED) + set_property(TARGET glib-genmarshal PROPERTY IMPORTED_LOCATION "${GLib_GENMARSHAL}") +endif() + +find_program(GLib_MKENUMS glib-mkenums) +if(GLib_MKENUMS AND NOT TARGET glib-mkenums) + add_executable(glib-mkenums IMPORTED) + set_property(TARGET glib-mkenums PROPERTY IMPORTED_LOCATION "${GLib_MKENUMS}") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GObject + REQUIRED_VARS + GObject_LIBRARY + GObject_INCLUDE_DIRS + ${GObject_DEPS_FOUND_VARS} + VERSION_VAR + GObject_VERSION) + +unset(GObject_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindGObjectIntrospection.cmake b/cmake/modules/gnome-cmake/modules/FindGObjectIntrospection.cmake new file mode 100644 index 0000000..4628a55 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindGObjectIntrospection.cmake @@ -0,0 +1,98 @@ +# FindGObjectIntrospection.cmake +# +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_program(GObjectIntrospection_COMPILER_EXECUTABLE g-ir-compiler) +find_program(GObjectIntrospection_SCANNER_EXECUTABLE g-ir-scanner) + +if(CMAKE_INSTALL_FULL_DATADIR) + set(GObjectIntrospection_REPOSITORY_DIR "${CMAKE_INSTALL_FULL_DATADIR}/gir-1.0") +else() + set(GObjectIntrospection_REPOSITORY_DIR "${CMAKE_INSTALL_PREFIX}/share/gir-1.0") +endif() + +if(CMAKE_INSTALL_FULL_LIBDIR) + set(GObjectIntrospection_TYPELIB_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/girepository-1.0") +else() + set(GObjectIntrospection_TYPELIB_DIR "${CMAKE_INSTALL_LIBDIR}/girepository-1.0") +endif() + +if(GObjectIntrospection_COMPILER_EXECUTABLE AND NOT TARGET g-ir-compiler) + # Imported target + add_executable(g-ir-compiler IMPORTED) + set_property(TARGET g-ir-compiler PROPERTY IMPORTED_LOCATION "${GObjectIntrospection_COMPILER_EXECUTABLE}") +endif() + +if(GObjectIntrospection_SCANNER_EXECUTABLE AND NOT TARGET g-ir-scanner) + # Imported target + add_executable(g-ir-scanner IMPORTED) + set_property(TARGET g-ir-scanner PROPERTY IMPORTED_LOCATION "${GObjectIntrospection_SCANNER_EXECUTABLE}") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GObjectIntrospection + REQUIRED_VARS + GObjectIntrospection_COMPILER_EXECUTABLE + GObjectIntrospection_SCANNER_EXECUTABLE) + +function(gobject_introspection_compile TYPELIB) + set (options DEBUG VERBOSE) + set (oneValueArgs MODULE SHARED_LIBRARY) + set (multiValueArgs FLAGS INCLUDE_DIRS) + cmake_parse_arguments(GObjectIntrospection_COMPILER "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + unset (options) + unset (oneValueArgs) + unset (multiValueArgs) + + get_filename_component(TYPELIB "${TYPELIB}" ABSOLUTE + BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}") + + if(GObjectIntrospection_COMPILER_DEBUG) + list(APPEND GObjectIntrospection_COMPILER_FLAGS "--debug") + endif() + + if(GObjectIntrospection_COMPILER_VERBOSE) + list(APPEND GObjectIntrospection_COMPILER_FLAGS "--verbose") + endif() + + if(GObjectIntrospection_SHARED_LIBRARY) + list(APPEND GObjectIntrospection_COMPILER_FLAGS "--shared-library" "${GObjectIntrospection_SHARED_LIBRARY}") + endif() + + foreach(include_dir ${GObjectIntrospection_COMPILER_INCLUDE_DIRS}) + list(APPEND GObjectIntrospection_COMPILER_FLAGS "--includedir" "${include_dir}") + endforeach() + + add_custom_command( + OUTPUT "${TYPELIB}" + COMMAND g-ir-compiler + ARGS + "-o" "${TYPELIB}" + ${GObjectIntrospection_COMPILER_FLAGS} + ${GObjectIntrospection_COMPILER_UNPARSED_ARGUMENTS} + DEPENDS + ${GObjectIntrospection_COMPILER_UNPARSED_ARGUMENTS}) +endfunction() diff --git a/cmake/modules/gnome-cmake/modules/FindGTK3.cmake b/cmake/modules/gnome-cmake/modules/FindGTK3.cmake new file mode 100644 index 0000000..f0a9ca4 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindGTK3.cmake @@ -0,0 +1,94 @@ +# FindGTK3.cmake +# +# +# CMake support for GTK+ 3. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(GTK3_DEPS + GIO + ATK + GDK3 + Pango + Cairo + GDKPixbuf) + +if(PKG_CONFIG_FOUND) + pkg_search_module(GTK3_PKG QUIET gtk+-3.0) +endif() + +find_library(GTK3_LIBRARY gtk-3 HINTS ${GTK3_PKG_LIBRARY_DIRS}) +set(GTK3 gtk-3) + +if(GTK3_LIBRARY AND NOT TARGET ${GTK3}) + add_library(${GTK3} SHARED IMPORTED) + set_property(TARGET ${GTK3} PROPERTY IMPORTED_LOCATION "${GTK3_LIBRARY}") + set_property(TARGET ${GTK3} PROPERTY INTERFACE_COMPILE_OPTIONS "${GTK3_PKG_CFLAGS_OTHER}") + + set(GTK3_INCLUDE_DIRS) + + find_path(GTK3_INCLUDE_DIR "gtk/gtk.h" + HINTS ${GTK3_PKG_INCLUDE_DIRS}) + + if(GTK3_INCLUDE_DIR) + file(STRINGS "${GTK3_INCLUDE_DIR}/gtk/gtkversion.h" GTK3_MAJOR_VERSION REGEX "^#define GTK_MAJOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define GTK_MAJOR_VERSION \\(?([0-9]+)\\)?$" "\\1" GTK3_MAJOR_VERSION "${GTK3_MAJOR_VERSION}") + file(STRINGS "${GTK3_INCLUDE_DIR}/gtk/gtkversion.h" GTK3_MINOR_VERSION REGEX "^#define GTK_MINOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define GTK_MINOR_VERSION \\(?([0-9]+)\\)?$" "\\1" GTK3_MINOR_VERSION "${GTK3_MINOR_VERSION}") + file(STRINGS "${GTK3_INCLUDE_DIR}/gtk/gtkversion.h" GTK3_MICRO_VERSION REGEX "^#define GTK_MICRO_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define GTK_MICRO_VERSION \\(?([0-9]+)\\)?$" "\\1" GTK3_MICRO_VERSION "${GTK3_MICRO_VERSION}") + set(GTK3_VERSION "${GTK3_MAJOR_VERSION}.${GTK3_MINOR_VERSION}.${GTK3_MICRO_VERSION}") + unset(GTK3_MAJOR_VERSION) + unset(GTK3_MINOR_VERSION) + unset(GTK3_MICRO_VERSION) + + list(APPEND GTK3_INCLUDE_DIRS ${GTK3_INCLUDE_DIR}) + set_property(TARGET ${GTK3} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GTK3_INCLUDE_DIR}") + endif() +endif() + +set(GTK3_DEPS_FOUND_VARS) +include(CMakeFindDependencyMacro) +foreach(gtk3_dep ${GTK3_DEPS}) + find_dependency(${gtk3_dep}) + + list(APPEND GTK3_DEPS_FOUND_VARS "${gtk3_dep}_FOUND") + list(APPEND GTK3_INCLUDE_DIRS ${${gtk3_dep}_INCLUDE_DIRS}) + + set_property (TARGET "${GTK3}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${gtk3_dep}}") +endforeach(gtk3_dep) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GTK3 + REQUIRED_VARS + GTK3_LIBRARY + GTK3_INCLUDE_DIRS + ${GTK3_DEPS_FOUND_VARS} + VERSION_VAR + GTK3_VERSION) + +unset(GTK3_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindPango.cmake b/cmake/modules/gnome-cmake/modules/FindPango.cmake new file mode 100644 index 0000000..931fe57 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindPango.cmake @@ -0,0 +1,87 @@ +# FindPango.cmake +# +# +# CMake support for Pango. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(Pango_DEPS + GLib) + +if(PKG_CONFIG_FOUND) + pkg_search_module(Pango_PKG pango) +endif() + +find_library(Pango_LIBRARY pango-1.0 HINTS ${Pango_PKG_LIBRARY_DIRS}) +set(Pango pango-1.0) + +if(Pango_LIBRARY AND NOT TARGET ${Pango}) + add_library(${Pango} SHARED IMPORTED) + set_property(TARGET ${Pango} PROPERTY IMPORTED_LOCATION "${Pango_LIBRARY}") + set_property(TARGET ${Pango} PROPERTY INTERFACE_COMPILE_OPTIONS "${Pango_PKG_CFLAGS_OTHER}") + + find_path(Pango_INCLUDE_DIR "pango/pango.h" + HINTS ${Pango_PKG_INCLUDE_DIRS}) + + if(Pango_INCLUDE_DIR) + file(STRINGS "${Pango_INCLUDE_DIR}/pango/pango-features.h" Pango_MAJOR_VERSION REGEX "^#define PANGO_VERSION_MAJOR +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define PANGO_VERSION_MAJOR \\(?([0-9]+)\\)?" "\\1" Pango_MAJOR_VERSION "${Pango_MAJOR_VERSION}") + file(STRINGS "${Pango_INCLUDE_DIR}/pango/pango-features.h" Pango_MINOR_VERSION REGEX "^#define PANGO_VERSION_MINOR +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define PANGO_VERSION_MINOR \\(?([0-9]+)\\)?" "\\1" Pango_MINOR_VERSION "${Pango_MINOR_VERSION}") + file(STRINGS "${Pango_INCLUDE_DIR}/pango/pango-features.h" Pango_MICRO_VERSION REGEX "^#define PANGO_VERSION_MICRO +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define PANGO_VERSION_MICRO \\(?([0-9]+)\\)?" "\\1" Pango_MICRO_VERSION "${Pango_MICRO_VERSION}") + set(Pango_VERSION "${Pango_MAJOR_VERSION}.${Pango_MINOR_VERSION}.${Pango_MICRO_VERSION}") + unset(Pango_MAJOR_VERSION) + unset(Pango_MINOR_VERSION) + unset(Pango_MICRO_VERSION) + + list(APPEND Pango_INCLUDE_DIRS ${Pango_INCLUDE_DIR}) + set_property(TARGET ${Pango} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${Pango_INCLUDE_DIR}") + endif() +endif() + +set(Pango_DEPS_FOUND_VARS) +include(CMakeFindDependencyMacro) +foreach(pango_dep ${Pango_DEPS}) + find_dependency(${pango_dep}) + + list(APPEND Pango_DEPS_FOUND_VARS "${pango_dep}_FOUND") + list(APPEND Pango_INCLUDE_DIRS ${${pango_dep}_INCLUDE_DIRS}) + + set_property (TARGET "${Pango}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${pango_dep}}") +endforeach(pango_dep) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Pango + REQUIRED_VARS + Pango_LIBRARY + Pango_INCLUDE_DIRS + ${Pango_DEPS_FOUND_VARS} + VERSION_VAR + Pango_VERSION) + +unset(Pango_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindSoup.cmake b/cmake/modules/gnome-cmake/modules/FindSoup.cmake new file mode 100644 index 0000000..f287e6c --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindSoup.cmake @@ -0,0 +1,87 @@ +# FindSoup.cmake +# +# +# CMake support for libsoup. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_package(PkgConfig QUIET) + +set(Soup_DEPS + GIO) + +if(PKG_CONFIG_FOUND) + pkg_search_module(Soup_PKG libsoup-2.4) +endif() + +find_library(Soup_LIBRARY soup-2.4 HINTS ${Soup_PKG_LIBRARY_DIRS}) +set(Soup soup-2.4) + +if(Soup_LIBRARY AND NOT TARGET ${Soup}) + add_library(${Soup} SHARED IMPORTED) + set_property(TARGET ${Soup} PROPERTY IMPORTED_LOCATION "${Soup_LIBRARY}") + set_property(TARGET ${Soup} PROPERTY INTERFACE_COMPILE_OPTIONS "${Soup_PKG_CFLAGS_OTHER}") + + find_path(Soup_INCLUDE_DIR "libsoup/soup.h" + HINTS ${Soup_PKG_INCLUDE_DIRS}) + + if(Soup_INCLUDE_DIR) + file(STRINGS "${Soup_INCLUDE_DIR}/libsoup/soup-version.h" Soup_MAJOR_VERSION REGEX "^#define SOUP_MAJOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define SOUP_MAJOR_VERSION \\(([0-9]+)\\)$" "\\1" Soup_MAJOR_VERSION "${Soup_MAJOR_VERSION}") + file(STRINGS "${Soup_INCLUDE_DIR}/libsoup/soup-version.h" Soup_MINOR_VERSION REGEX "^#define SOUP_MINOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define SOUP_MINOR_VERSION \\(([0-9]+)\\)$" "\\1" Soup_MINOR_VERSION "${Soup_MINOR_VERSION}") + file(STRINGS "${Soup_INCLUDE_DIR}/libsoup/soup-version.h" Soup_MICRO_VERSION REGEX "^#define SOUP_MICRO_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define SOUP_MICRO_VERSION \\(([0-9]+)\\)$" "\\1" Soup_MICRO_VERSION "${Soup_MICRO_VERSION}") + set(Soup_VERSION "${Soup_MAJOR_VERSION}.${Soup_MINOR_VERSION}.${Soup_MICRO_VERSION}") + unset(Soup_MAJOR_VERSION) + unset(Soup_MINOR_VERSION) + unset(Soup_MICRO_VERSION) + + list(APPEND Soup_INCLUDE_DIRS ${Soup_INCLUDE_DIR}) + set_property(TARGET ${Soup} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${Soup_INCLUDE_DIR}") + endif() +endif() + +set(Soup_DEPS_FOUND_VARS) +include(CMakeFindDependencyMacro) +foreach(soup_dep ${Soup_DEPS}) + find_dependency(${soup_dep}) + + list(APPEND Soup_DEPS_FOUND_VARS "${soup_dep}_FOUND") + list(APPEND Soup_INCLUDE_DIRS ${${soup_dep}_INCLUDE_DIRS}) + + set_property (TARGET "${Soup}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${soup_dep}}") +endforeach(soup_dep) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Soup + REQUIRED_VARS + Soup_LIBRARY + Soup_INCLUDE_DIRS + ${Soup_DEPS_FOUND_VARS} + VERSION_VAR + Soup_VERSION) + +unset(Soup_DEPS_FOUND_VARS) diff --git a/cmake/modules/gnome-cmake/modules/FindVala.cmake b/cmake/modules/gnome-cmake/modules/FindVala.cmake new file mode 100644 index 0000000..4ce8171 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindVala.cmake @@ -0,0 +1,410 @@ +# FindVala.cmake +# +# +# This file contains functions which can be used to integrate Vala +# compilation with CMake. It is intended as a replacement for Jakob +# Westhoff's FindVala.cmake and UseVala.cmake. It uses fast-vapis for +# faster parallel compilation, and per-target directories for +# generated sources to allow reusing source files across, even with +# different options. +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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(VALAC_NAMES valac) + +set(_FIND_VALA_CURRENT_VERSION 98) +while(_FIND_VALA_CURRENT_VERSION GREATER 0) + list(APPEND VALAC_NAME "valac-1.${_FIND_VALA_CURRENT_VERSION}") + math(EXPR _FIND_VALA_CURRENT_VERSION "${_FIND_VALA_CURRENT_VERSION} - 2") +endwhile() +set(_FIND_VALA_CURRENT_VERSION 98) +while(_FIND_VALA_CURRENT_VERSION GREATER 0) + list(APPEND VALAC_NAME "valac-1.${_FIND_VALA_CURRENT_VERSION}") + math(EXPR _FIND_VALA_CURRENT_VERSION "${_FIND_VALA_CURRENT_VERSION} - 2") +endwhile() +unset(_FIND_VALA_CURRENT_VERSION) + +find_program(VALA_EXECUTABLE + NAMES ${VALAC_NAMES}) +mark_as_advanced(VALA_EXECUTABLE) + +unset(VALAC_NAMES) + +if(VALA_EXECUTABLE AND NOT TARGET valac) + # Determine valac version + execute_process(COMMAND ${VALA_EXECUTABLE} "--version" + OUTPUT_VARIABLE VALA_VERSION) + string(REGEX REPLACE "^.*Vala ([0-9]+\\.[0-9]+\\.[0-9]+(\\.[0-9]+(\\-[0-9a-f]+)?)?).*$" "\\1" VALA_VERSION "${VALA_VERSION}") + + add_executable(valac IMPORTED) + set_property(TARGET valac PROPERTY IMPORTED_LOCATION "${VALA_EXECUTABLE}") +endif(VALA_EXECUTABLE) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Vala + REQUIRED_VARS VALA_EXECUTABLE + VERSION_VAR VALA_VERSION) + +function(_vala_mkdir_for_file file) + get_filename_component(dir "${file}" DIRECTORY) + file(MAKE_DIRECTORY "${dir}") +endfunction() + +macro(_vala_parse_source_file_path source) + set (options) + set (oneValueArgs SOURCE TYPE OUTPUT_PATH OUTPUT_DIR GENERATED_SOURCE FAST_VAPI) + set (multiValueArgs) + cmake_parse_arguments(VALAPATH "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + unset (options) + unset (oneValueArgs) + unset (multiValueArgs) + + if(VALAPATH_SOURCE) + get_filename_component("${VALAPATH_SOURCE}" "${source}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + + if(VALAPATH_TYPE) + string(REGEX MATCH "[^\\.]+$" "${VALAPATH_TYPE}" "${source}") + string(TOLOWER "${${VALAPATH_TYPE}}" "${VALAPATH_TYPE}") + endif() + + if(VALAPATH_OUTPUT_PATH OR VALAPATH_GENERATED_SOURCE OR VALAPATH_OUTPUT_DIR OR VALAPATH_FAST_VAPI) + get_filename_component(srcfile "${source}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + + string(LENGTH "${CMAKE_BINARY_DIR}" dirlen) + string(SUBSTRING "${srcfile}" 0 ${dirlen} tmp) + if("${CMAKE_BINARY_DIR}" STREQUAL "${tmp}") + string(SUBSTRING "${srcfile}" ${dirlen} -1 tmp) + set(outpath "build${tmp}") + else() + string(LENGTH "${CMAKE_SOURCE_DIR}" dirlen) + string(SUBSTRING "${srcfile}" 0 ${dirlen} tmp) + if("${CMAKE_SOURCE_DIR}" STREQUAL "${tmp}") + string(SUBSTRING "${srcfile}" ${dirlen} -1 tmp) + set(outpath "source${tmp}") + else () + # TODO: this probably doesn't work correctly on Windows… + set(outpath "root${tmp}") + endif() + endif() + + unset(tmp) + unset(dirlen) + unset(srcfile) + endif() + + if(VALAPATH_OUTPUT_PATH) + set("${VALAPATH_OUTPUT_PATH}" "${outpath}") + endif() + + if(VALAPATH_GENERATED_SOURCE) + string(REGEX REPLACE "\\.(vala|gs)$" ".c" "${VALAPATH_GENERATED_SOURCE}" "${outpath}") + endif() + + if(VALAPATH_FAST_VAPI) + string(REGEX REPLACE "\\.(vala|gs)$" ".vapi" "${VALAPATH_FAST_VAPI}" "${outpath}") + endif() + + if(VALAPATH_OUTPUT_DIR) + get_filename_component("${VALAPATH_OUTPUT_DIR}" "${outpath}" DIRECTORY) + endif() + + unset(outpath) +endmacro() + +# vala_precompile_target( +# TARGET +# GENERATED_SOURCES +# SOURCES… +# [VAPI vapi-name.vapi] +# [GIR name-version.gir] +# [HEADER name.h] +# [FLAGS …] +# [PACKAGES …] +# [DEPENDS …]) +# +# This function will use valac to generate C code. +# +# This function uses fast VAPIs to help improve parallelization and +# incremental build times. The problem with this is that CMake +# doesn't allow file-level dependencies across directories; if you're +# generating code in one directory (for example, a library) and would +# like to use it in another directory and are building in parallel, +# the build can fail. To prevent this, this function will create a +# ${TARGET}-vala top-level target (which *is* usable from other +# directories). +# +# Options: +# +# TARGET +# Target to create; it's generally best to make this similar to +# your executable or library target name (e.g., for a "foo" +# executable, "foo-vala" might be a good name), but not +# technically required. +# GENERATED_SOURCES +# Variable in which to store the list of generated sources (which +# you should pass to add_executable or add_library). +# SOURCES +# Vala sources to generate C from. You should include *.vala, +# *.gs, and uninstalled *.vapi files here; you may also include +# C/C++ sources (they will simply be passed directly through to +# the GENERATED_SOURCES variable). +# VAPI name.vapi +# If you would like to have valac generate a VAPI (basically, if +# you are generating a library not an executable), pass the file +# name here. +# GIR name-version.gir +# If you would like to have valac generate a GIR, pass the file +# name here. +# HEADER name.h +# If you would like to have valac generate a C header, pass the +# file name here. +# FLAGS … +# List of flags you wish to pass to valac. They will be added to +# the flags in VALA_COMPILER_FLAGS and VALA_COMPILER_FLAGS_DEBUG +# (for Debug builds) or VALA_COMPILER_FLAGS_RELEASE (for Release +# builds). +# PACKAGES +# List of dependencies to pass to valac. +# DEPENDS +# Any additional dependencies you would like. +macro(vala_precompile_target TARGET GENERATED_SOURCES) + set (options) + set (oneValueArgs VAPI GIR HEADER) + set (multiValueArgs FLAGS PACKAGES DEPENDS) + cmake_parse_arguments(VALAC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + unset (options) + unset (oneValueArgs) + unset (multiValueArgs) + + set(VALA_SOURCES) + set(VALA_VAPIS) + set(VALA_OUTPUT_SOURCES) + + if(VALAC_VAPI) + list(APPEND non_source_out_files "${VALAC_VAPI}") + list(APPEND non_source_valac_args "--vapi" "${VALAC_VAPI}") + endif() + + if(VALAC_GIR) + list(APPEND non_source_out_files "${VALAC_GIR}") + list(APPEND non_source_valac_args + "--gir" "${VALAC_GIR}" + "--library" "${TARGET}" + "--shared-library" "${CMAKE_SHARED_LIBRARY_PREFIX}${TARGET}${CMAKE_SHARED_LIBRARY_SUFFIX}") + endif() + + if(VALAC_HEADER) + list(APPEND non_source_out_files "${VALAC_HEADER}") + list(APPEND non_source_valac_args --header "${VALAC_HEADER}") + endif() + + # Split up the input files into three lists; one containing vala and + # genie sources, one containing VAPIs, and one containing C files + # (which may seem a bit silly, but it does open up the possibility + # of declaring your source file list once instead of having separate + # lists for Vala and C). + foreach(source ${VALAC_UNPARSED_ARGUMENTS}) + _vala_parse_source_file_path("${source}" + SOURCE source_full + TYPE type) + + if("vala" STREQUAL "${type}" OR "gs" STREQUAL "${type}") + list(APPEND VALA_SOURCES "${source_full}") + elseif("vapi" STREQUAL "${type}") + list(APPEND VALA_VAPIS "${source_full}") + elseif( + "c" STREQUAL "${type}" OR + "h" STREQUAL "${type}" OR + "cc" STREQUAL "${type}" OR + "cpp" STREQUAL "${type}" OR + "cxx" STREQUAL "${type}" OR + "hpp" STREQUAL "${type}") + list(APPEND VALA_OUTPUT_SOURCES "${source_full}") + endif() + + unset(type) + unset(source_full) + endforeach() + + # Set the common flags to pass to every valac invocation. + set(VALAFLAGS ${VALAC_FLAGS} ${VALA_VAPIS}) + foreach(pkg ${VALAC_PACKAGES}) + list(APPEND VALAFLAGS "--pkg" "${pkg}") + endforeach() + list(APPEND VALAFLAGS ${VALA_COMPILER_FLAGS}) + if (CMAKE_BUILD_TYPE MATCHES "Debug") + list(APPEND VALAFLAGS ${VALA_COMPILER_FLAGS_DEBUG}) + elseif(CMAKE_BUILD_TYPE MATCHES "Release") + list(APPEND VALAFLAGS ${VALA_COMPILER_FLAGS_RELEASE}) + endif() + + # Where to put the output + set(TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}") + + set(FAST_VAPI_STAMPS) + + # Create fast VAPI targets for each vala source + foreach(source ${VALA_SOURCES}) + _vala_parse_source_file_path("${source}" + FAST_VAPI fast_vapi_path) + + # We need somewhere to put the output… + _vala_mkdir_for_file("${TARGET_DIR}/${fast_vapi_path}") + + # Create the target + add_custom_command( + OUTPUT "${TARGET_DIR}/${fast_vapi_path}.stamp" + BYPRODUCTS "${TARGET_DIR}/${fast_vapi_path}" + DEPENDS + "${source}" + ${VALA_VAPIS} + ${VALAC_DEPENDS} + COMMAND "${VALA_EXECUTABLE}" + ARGS + "${source}" + --fast-vapi "${TARGET_DIR}/${fast_vapi_path}" + ${VALAFLAGS} + COMMAND "${CMAKE_COMMAND}" ARGS -E touch "${TARGET_DIR}/${fast_vapi_path}.stamp" + COMMENT "Generating fast VAPI ${TARGET_DIR}/${fast_vapi_path}") + + list(APPEND FAST_VAPI_STAMPS "${TARGET_DIR}/${fast_vapi_path}.stamp") + + unset(fast_vapi_path) + endforeach() + + # Create a ${TARGET_DIR}-fast-vapis target which depens on all the fast + # vapi stamps. We can use this as a dependency to make sure all + # fast-vapis are up to date. + add_custom_command( + OUTPUT "${TARGET_DIR}/fast-vapis.stamp" + COMMAND "${CMAKE_COMMAND}" ARGS -E touch "${TARGET_DIR}/fast-vapis.stamp" + DEPENDS + ${FAST_VAPI_STAMPS} + ${VALAC_DEPENDS} + COMMENT "Generating fast VAPIs for ${TARGET}") + + add_custom_target("${TARGET}-fast-vapis" + DEPENDS "${TARGET_DIR}/fast-vapis.stamp") + + set(VALA_GENERATED_SOURCE_STAMPS) + + # Add targets to generate C sources + foreach(source ${VALA_SOURCES}) + _vala_parse_source_file_path("${source}" + OUTPUT_PATH output_path + OUTPUT_DIR output_dir + GENERATED_SOURCE generated_source) + + set(use_fast_vapi_flags) + foreach(src ${VALA_SOURCES}) + if(NOT "${src}" STREQUAL "${source}") + _vala_parse_source_file_path("${src}" + FAST_VAPI src_fast_vapi_path) + + list(APPEND use_fast_vapi_flags --use-fast-vapi "${TARGET_DIR}/${src_fast_vapi_path}") + + unset(src_fast_vapi_path) + endif() + endforeach() + + add_custom_command( + OUTPUT "${TARGET_DIR}/${generated_source}.stamp" + BYPRODUCTS "${TARGET_DIR}/${generated_source}" + COMMAND "${VALA_EXECUTABLE}" + ARGS + -d "${TARGET_DIR}/${output_dir}" + -C + "${source}" + ${VALAFLAGS} + ${use_fast_vapi_flags} + COMMAND "${CMAKE_COMMAND}" ARGS -E touch "${TARGET_DIR}/${generated_source}.stamp" + DEPENDS + "${TARGET}-fast-vapis" + "${source}" + ${VALA_VAPIS} + COMMENT "Generating ${TARGET_DIR}/${generated_source}") + unset(use_fast_vapi_flags) + + list(APPEND VALA_OUTPUT_SOURCES "${TARGET_DIR}/${generated_source}") + list(APPEND VALA_GENERATED_SOURCE_STAMPS "${TARGET_DIR}/${generated_source}.stamp") + + unset(fast_vapi_path) + unset(output_dir) + unset(generated_source) + endforeach() + + add_custom_command( + OUTPUT "${TARGET_DIR}/stamp" + COMMAND "${CMAKE_COMMAND}" ARGS -E touch "${TARGET_DIR}/stamp" + DEPENDS ${VALA_GENERATED_SOURCE_STAMPS} + COMMENT "Generating sources from Vala for ${TARGET}") + + set("${GENERATED_SOURCES}" ${VALA_OUTPUT_SOURCES}) + + if(non_source_out_files) + set(use_fast_vapi_flags) + foreach(source ${VALA_SOURCES}) + _vala_parse_source_file_path("${source}" + FAST_VAPI fast_vapi_path) + + list(APPEND use_fast_vapi_flags --use-fast-vapi "${TARGET_DIR}/${fast_vapi_path}") + + unset(fast_vapi_path) + endforeach() + + add_custom_command(OUTPUT ${non_source_out_files} + COMMAND ${VALA_EXECUTABLE} + ARGS + -C + ${non_source_valac_args} + ${VALAFLAGS} + ${use_fast_vapi_flags} + DEPENDS + "${TARGET}-fast-vapis" + ${VALA_VAPIS}) + unset(use_fast_vapi_flags) + endif() + + # CMake doesn't allow file-level dependencies across directories, so + # we provide a target we can depend on from other directories. + add_custom_target("${TARGET}" + DEPENDS + "${TARGET_DIR}/stamp" + ${non_source_out_files} + ${VALAC_DEPENDS} + ${VALA_GENERATED_SOURCE_STAMPS}) + + unset(non_source_out_files) + unset(non_source_valac_args) + + unset(VALA_GENERATED_SOURCE_STAMPS) + unset(FAST_VAPI_STAMPS) + unset(TARGET_DIR) + unset(VALAFLAGS) + unset(VALA_SOURCES) + unset(VALA_VAPIS) + unset(VALA_OUTPUT_SOURCES) +endmacro() diff --git a/cmake/modules/gnome-cmake/modules/FindValadoc.cmake b/cmake/modules/gnome-cmake/modules/FindValadoc.cmake new file mode 100644 index 0000000..1433e08 --- /dev/null +++ b/cmake/modules/gnome-cmake/modules/FindValadoc.cmake @@ -0,0 +1,105 @@ +# FindValadoc.cmake +# +# +# License: +# +# Copyright (c) 2016 Evan Nemerson +# +# 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. + +find_program(VALADOC_EXECUTABLE + NAMES valadoc + DOC "Valadoc") + +if(VALADOC_EXECUTABLE AND NOT TARGET valadoc) + # Get valadoc version + execute_process(COMMAND ${VALADOC_EXECUTABLE} "--version" OUTPUT_VARIABLE VALADOC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + string(SUBSTRING "${VALADOC_VERSION}" 8 -1 VALADOC_VERSION) + + # Imported target + add_executable(valadoc IMPORTED) + set_property(TARGET valadoc PROPERTY IMPORTED_LOCATION "${VALADOC_EXECUTABLE}") +endif() + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Valadoc + FOUND_VAR VALADOC_FOUND + REQUIRED_VARS VALADOC_EXECUTABLE + VERSION_VAR VALADOC_VERSION) + +# valadoc_generate(OUTPUT_DIR +# PACKAGE_NAME name +# [PACKAGE_VERSION version] +# [FLAGS flags…] +# [PACKAGES packages…] +# [DOCLET doclet] +# [ALL]) +# +# PACKAGE_NAME name +# VAPI name to generate documentation for. +# PACKAGE_VERSION version +# Version number of the package. +# FLAGS … +# List of flags you wish to pass to valadoc. +# PACKAGES +# List of dependencies to pass to valac. +# DOCLET doclet-name +# Name of the doclet to use (default: html) +function(valadoc_generate OUTPUT_DIR) + set (options) + set (oneValueArgs DOCLET PACKAGE_NAME PACKAGE_VERSION) + set (multiValueArgs SOURCES PACKAGES FLAGS DEFINITIONS CUSTOM_VAPIS) + cmake_parse_arguments(VALADOC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + unset (options) + unset (oneValueArgs) + unset (multiValueArgs) + + if("${VALADOC_DOCLET}" STREQUAL "") + list(APPEND VALADOC_FLAGS "--doclet=html") + else() + list(APPEND VALADOC_FLAGS "--doclet=${VALADOC_DOCLET}") + endif() + + if(NOT "${VALADOC_PACKAGE_NAME}" STREQUAL "") + list(APPEND VALADOC_FLAGS "--package-name=${VALADOC_PACKAGE_NAME}") + endif() + + if(NOT "${VALADOC_PACKAGE_VERSION}" STREQUAL "") + list(APPEND VALADOC_FLAGS "--package-version=${VALADOC_PACKAGE_VERSION}") + endif() + + foreach(pkg ${VALADOC_PACKAGES}) + list(APPEND VALADOC_FLAGS "--pkg=${pkg}") + endforeach(pkg) + + add_custom_command( + OUTPUT "${OUTPUT_DIR}" + COMMAND valadoc + ARGS + --force + -o "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_DIR}" + ${VALADOC_FLAGS} + ${VALADOC_SOURCES} + DEPENDS + ${VALADOC_SOURCES} + COMMENT "Generating documentation with Valadoc" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +endfunction() diff --git a/etc/libtsm.pc.in b/etc/libtsm.pc.in new file mode 100644 index 0000000..ffcb90a --- /dev/null +++ b/etc/libtsm.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix}; +libdir=@CMAKE_INSTALL_LIBDIR@ +includedir=@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +URL: @PROJECT_HOMEPAGE_URL@ +Version: @PROJECT_VERSION@ +Libs: -L${libdir} -ltsm +Cflags: -I${includedir} diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 0000000..669ebf9 --- /dev/null +++ b/external/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# External vendorized code +# build everything into a static library for ease of use internally +# +add_library(external STATIC + wcwidth/wcwidth.c +) + +target_include_directories(external + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/wcwidth +) +set_property(TARGET external PROPERTY C_VISIBILITY_PRESET hidden) +add_libtsm_compile_options(external) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..adab1a4 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ +add_subdirectory(shared) +add_subdirectory(tsm) + +if(BUILD_GTKTSM) + add_subdirectory(gtktsm) +endif() diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 0000000..635deeb --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,10 @@ +#ifndef LIBTSM_CONFIG_H +#define LIBTSM_CONFIG_H + +/* Enable debug mode */ +#cmakedefine BUILD_ENABLE_DEBUG + +/* Have xkbcommon library */ +#cmakedefine BUILD_HAVE_XKBCOMMON + +#endif // LIBTSM_CONFIG_H diff --git a/src/gtktsm/CMakeLists.txt b/src/gtktsm/CMakeLists.txt new file mode 100644 index 0000000..4d5855f --- /dev/null +++ b/src/gtktsm/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# GtkTsm - Example +# +add_executable(gtktsm + gtktsm.c + gtktsm-app.c + gtktsm-terminal.c + gtktsm-win.c +) +target_link_libraries(gtktsm + PRIVATE + tsm + shl + + m + gtk-3 + cairo + pango-1.0 + pangocairo + XKB::XKBCommon +) +add_libtsm_compile_options(gtktsm) + +#install(TARGETS libtsm_main +# RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" +#) diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt new file mode 100644 index 0000000..a7b82f0 --- /dev/null +++ b/src/shared/CMakeLists.txt @@ -0,0 +1,17 @@ +# +# SHL - Static Helper Library +# The SHL subsystem contains several small code pieces used all over libtsm and +# other applications. +# +add_library(shl STATIC + shl-htable.c + shl-pty.c + shl-ring.c +) + +target_include_directories(shl + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) +set_property(TARGET shl PROPERTY C_VISIBILITY_PRESET hidden) +add_libtsm_compile_options(shl) diff --git a/src/tsm/CMakeLists.txt b/src/tsm/CMakeLists.txt new file mode 100644 index 0000000..01b9e3e --- /dev/null +++ b/src/tsm/CMakeLists.txt @@ -0,0 +1,36 @@ +# +# libtsm +# Main library build instructions +# +add_library(tsm SHARED + tsm-render.c + tsm-screen.c + tsm-selection.c + tsm-unicode.c + tsm-vte.c + tsm-vte-charsets.c +) +target_link_libraries(tsm + PRIVATE + external + shl +) +if(XKBCommon_KeySyms_FOUND) + target_link_libraries(tsm + PRIVATE + XKB::KeySyms + ) +endif() +target_include_directories(tsm + PUBLIC + $ + $ +) +set_target_properties(tsm PROPERTIES + C_VISIBILITY_PRESET hidden + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}" + PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/libtsm.h" +) +set_property(TARGET tsm APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/libtsm.sym\"") +add_libtsm_compile_options(tsm) diff --git a/src/tsm/libtsm.pc.in b/src/tsm/libtsm.pc.in deleted file mode 100644 index cc1aa6f..0000000 --- a/src/tsm/libtsm.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libtsm -Description: @PACKAGE_DESCRIPTION@ -URL: @PACKAGE_URL@ -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -ltsm -Cflags: -I${includedir} diff --git a/src/tsm/tsm-unicode.c b/src/tsm/tsm-unicode.c index f06eae8..bc1609a 100644 --- a/src/tsm/tsm-unicode.c +++ b/src/tsm/tsm-unicode.c @@ -57,7 +57,7 @@ #include #include #include -#include "external/wcwidth/wcwidth.h" +#include "wcwidth/wcwidth.h" #include "libtsm.h" #include "libtsm-int.h" #include "shl-array.h" From a76ef59a63566f5b4a695e78e9598ac31bdab404 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 2 Oct 2018 22:15:57 -0400 Subject: [PATCH 03/20] build: implement installation rules in CMake Signed-off-by: Aetf --- CMakeLists.txt | 109 ++++++++++++++++++------------------- cmake/Utilities.cmake | 32 +++++++++++ etc/libtsm-config.cmake.in | 13 +++++ etc/libtsm.pc.in | 4 +- external/CMakeLists.txt | 9 ++- src/gtktsm/CMakeLists.txt | 11 ++-- src/shared/CMakeLists.txt | 7 ++- src/tsm/CMakeLists.txt | 22 +++++++- 8 files changed, 138 insertions(+), 69 deletions(-) create mode 100644 etc/libtsm-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index daf5bf2..54558e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,16 +30,21 @@ include(cmake/BuildTypes.cmake) #--------------------------------------------------------------------------------------- # Options #--------------------------------------------------------------------------------------- +option(BUILD_SHARED_LIBS "Build as shared libraries" ON) +add_feature_info(BUILD_SHARED_LIBS BUILD_SHARED_LIBS "build as shared libraries") + option(BUILD_TESTING "Whether to build test suite in default target" OFF) -add_feature_info(tests BUILD_TESTING "build unit tests") +add_feature_info(BUILD_TESTING BUILD_TESTING "build unit tests") # We enable a lot of debug options by default, so this option is really only for # extended developer debug modes. option(ENABLE_EXTRA_DEBUG "Whether to enable several non-standard debug options." OFF) -add_feature_info(extra_debugging ENABLE_EXTRA_DEBUG "enable additional non-standard debug options") +add_feature_info(ENABLE_EXTRA_DEBUG ENABLE_EXTRA_DEBUG "enable additional non-standard debug options") -# Defined after find packages -#option(BUILD_GTKTSM "Whether to build gtktsm, defaults to ON if dependencies are met" ${BUILD_GTKTSM_INITIAL}) +# Whether to our gtktsm example. This is linux-only as it uses epoll and friends. +# Therefore, it's disabled by default. +option(BUILD_GTKTSM "Whether to build the gtktsm example" OFF) +add_feature_info(BUILD_GTKTSM BUILD_GTKTSM "build the gtktsm example, it requires gtk+-3 and friends and is linux-only.") #--------------------------------------------------------------------------------------- # Find packages @@ -64,67 +69,38 @@ set_package_properties(XKBCommon PROPERTIES ) # Optionally, look for gtk+-3 and friends for gtktsm -if(DEFINED BUILD_GTKTSM) - set(BUILD_GTKTSM_INITIAL ${BUILD_GTKTSM}) -else() - # set to ON at first, and change to OFF if dependencies are not met - set(BUILD_GTKTSM_INITIAL ON) -endif() - -if(BUILD_GTKTSM_INITIAL) +if(BUILD_GTKTSM) find_package(GTK3) set_package_properties(GTK3 PROPERTIES - TYPE OPTIONAL + TYPE REQUIRED PURPOSE "For gtktsm example" ) find_package(Cairo) set_package_properties(Cairo PROPERTIES - TYPE OPTIONAL + TYPE REQUIRED PURPOSE "For gtktsm example" ) find_package(Pango) set_package_properties(Pango PROPERTIES - TYPE OPTIONAL + TYPE REQUIRED PURPOSE "For gtktsm example" ) find_package(PangoCairo) set_package_properties(PangoCairo PROPERTIES - TYPE OPTIONAL + TYPE REQUIRED PURPOSE "For gtktsm example" ) find_package(XKBCommon COMPONENTS XKBCommon) set_package_properties(XKBCommon PROPERTIES - TYPE OPTIONAL + TYPE REQUIRED PURPOSE "For gtktsm example" ) - - # If the user requested to build gtktsm, then the dependencies becomes required - if((DEFINED BUILD_GTKTSM) AND BUILD_GTKTSM) - set_package_properties(GTK3 PROPERTIES TYPE REQUIRED) - set_package_properties(PangoCairo PROPERTIES TYPE REQUIRED) - set_package_properties(XKBCommon PROPERTIES TYPE REQUIRED) - endif() -endif() - -# we will build gtktsm if the user requested so or if the dependencies are met -if(NOT DEFINED BUILD_GTKTSM) - if(GTK3_FOUND AND PangoCairo_FOUND AND XKBCommon_FOUND) - set(BUILD_GTKTSM_INITIAL ON) - else() - set(BUILD_GTKTSM_INITIAL OFF) - endif() endif() -# Whether to our gtktsm example. This is linux-only as it uses epoll and friends. -# Therefore, it's disabled by default. -option(BUILD_GTKTSM "Whether to build gtktsm, defaults to ON if dependencies are met" ${BUILD_GTKTSM_INITIAL}) -# We defer the feature info after depencency checking -add_feature_info(gtktsm BUILD_GTKTSM "build the gtktsm example, it requires gtk+-3 and friends and is linux-only.") - feature_summary(INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES WHAT ALL) #--------------------------------------------------------------------------------------- @@ -156,20 +132,43 @@ if(BUILD_TESTING) endif(BUILD_TESTING) #--------------------------------------------------------------------------------------- -# Installation +# Installation of other files #--------------------------------------------------------------------------------------- -configure_file(etc/libtsm.pc.in libtsm.pc @ONLY) -install(FILES libtsm.pc DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig) - -# TODO: installation -# -#install(TARGETS libtsm libtsm_static -# LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" -# ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" -# PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libtsm" -#) -#install(TARGETS libtsm libtsm_static -# LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" -# ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" -# PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libtsm" -#) +# pkgconfig file for backward compatibility +configure_file(etc/libtsm.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libtsm.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtsm.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + +#Export the targets to a script +set(INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/libtsm) +install(EXPORT tsm-targets + FILE + libtsm-targets.cmake + NAMESPACE + libtsm:: + DESTINATION + ${INSTALL_CMAKEDIR} +) + +#Create a ConfigVersion.cmake file +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/libtsm-config-version.cmake + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file( + ${CMAKE_SOURCE_DIR}/etc/libtsm-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libtsm-config.cmake + PATH_VARS + INSTALL_CMAKEDIR + INSTALL_DESTINATION + ${INSTALL_CMAKEDIR} + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +#Install the config, configversion and custom find modules +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/libtsm-config-version.cmake + ${CMAKE_CURRENT_BINARY_DIR}/libtsm-config.cmake + DESTINATION ${INSTALL_CMAKEDIR} +) diff --git a/cmake/Utilities.cmake b/cmake/Utilities.cmake index 766be3d..7f95148 100644 --- a/cmake/Utilities.cmake +++ b/cmake/Utilities.cmake @@ -238,3 +238,35 @@ macro(find_package_handle_library_components module_name) list(REMOVE_DUPLICATES ${module_name}_TARGETS) endif() endmacro() + +# +# Link to an object library privately without polluting target exports +# +# this is done by not involving target_link_libraries but directly set +# properties. +# +# This is needed because we don't want the consumer target to have to +# export the object library +# See: https://gitlab.kitware.com/cmake/cmake/issues/17357 +function(target_link_object_libraries target) + set(tlol_options) + set(tlol_oneValueArgs) + set(tlol_multiValueArgs PRIVATE) + cmake_parse_arguments(TLOL "${tlol_options}" "${tlol_oneValueArgs}" "${tlol_multiValueArgs}" ${ARGN}) + + if(TLOL_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unexpected arguments to target_link_object_libraries: ${TLOL_UNPARSED_ARGUMENTS}, note that only PRIVATE is allowed") + endif() + + if(NOT TLOL_PRIVATE) + message(FATAL_ERROR "Missing PRIVATE argument to target_link_object_libraries") + endif() + + foreach(lib IN LISTS TLOL_PRIVATE) + target_sources(${target} PRIVATE $) + target_include_directories(${target} PRIVATE $) + target_compile_options(${target} PRIVATE $) + # This is not supported + #target_link_libraries(${target} PRIVATE $) + endforeach() +endfunction() diff --git a/etc/libtsm-config.cmake.in b/etc/libtsm-config.cmake.in new file mode 100644 index 0000000..8044bbb --- /dev/null +++ b/etc/libtsm-config.cmake.in @@ -0,0 +1,13 @@ +# +# libtsm +# ------ +# +# The following imported targets are created: +# libtsm::libtsm +# + +@PACKAGE_INIT@ + +if(NOT TARGET libtsm::tsm) + include("${CMAKE_CURRENT_LIST_DIR}/libtsm-targets.cmake") +endif() diff --git a/etc/libtsm.pc.in b/etc/libtsm.pc.in index ffcb90a..05cf530 100644 --- a/etc/libtsm.pc.in +++ b/etc/libtsm.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix}; -libdir=@CMAKE_INSTALL_LIBDIR@ -includedir=@CMAKE_INSTALL_INCLUDEDIR@ +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ Name: @PROJECT_NAME@ Description: @PROJECT_DESCRIPTION@ diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 669ebf9..dd69c7b 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,8 +1,8 @@ # # External vendorized code -# build everything into a static library for ease of use internally +# build everything into a object library for ease of use internally # -add_library(external STATIC +add_library(external OBJECT wcwidth/wcwidth.c ) @@ -11,5 +11,8 @@ target_include_directories(external ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/wcwidth ) -set_property(TARGET external PROPERTY C_VISIBILITY_PRESET hidden) +set_target_properties(external PROPERTIES + C_VISIBILITY_PRESET hidden + POSITION_INDEPENDENT_CODE ON +) add_libtsm_compile_options(external) diff --git a/src/gtktsm/CMakeLists.txt b/src/gtktsm/CMakeLists.txt index 4d5855f..5e41da0 100644 --- a/src/gtktsm/CMakeLists.txt +++ b/src/gtktsm/CMakeLists.txt @@ -10,7 +10,6 @@ add_executable(gtktsm target_link_libraries(gtktsm PRIVATE tsm - shl m gtk-3 @@ -19,8 +18,12 @@ target_link_libraries(gtktsm pangocairo XKB::XKBCommon ) +target_link_object_libraries(gtktsm + PRIVATE + shl +) add_libtsm_compile_options(gtktsm) -#install(TARGETS libtsm_main -# RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" -#) +install(TARGETS gtktsm + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" +) diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index a7b82f0..4fd8e73 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -3,7 +3,7 @@ # The SHL subsystem contains several small code pieces used all over libtsm and # other applications. # -add_library(shl STATIC +add_library(shl OBJECT shl-htable.c shl-pty.c shl-ring.c @@ -13,5 +13,8 @@ target_include_directories(shl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) -set_property(TARGET shl PROPERTY C_VISIBILITY_PRESET hidden) +set_target_properties(shl PROPERTIES + C_VISIBILITY_PRESET hidden + POSITION_INDEPENDENT_CODE ON +) add_libtsm_compile_options(shl) diff --git a/src/tsm/CMakeLists.txt b/src/tsm/CMakeLists.txt index 01b9e3e..7f7a22a 100644 --- a/src/tsm/CMakeLists.txt +++ b/src/tsm/CMakeLists.txt @@ -2,7 +2,7 @@ # libtsm # Main library build instructions # -add_library(tsm SHARED +add_library(tsm tsm-render.c tsm-screen.c tsm-selection.c @@ -10,7 +10,12 @@ add_library(tsm SHARED tsm-vte.c tsm-vte-charsets.c ) -target_link_libraries(tsm + +# Add an alias so that library can be used inside the build tree, e.g. when testing +add_library(libtsm::tsm ALIAS tsm) + +# Link to dependencies +target_link_object_libraries(tsm PRIVATE external shl @@ -27,10 +32,21 @@ target_include_directories(tsm $ ) set_target_properties(tsm PROPERTIES + POSITION_INDEPENDENT_CODE ON C_VISIBILITY_PRESET hidden VERSION "${PROJECT_VERSION}" SOVERSION "${PROJECT_VERSION_MAJOR}" PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/libtsm.h" ) -set_property(TARGET tsm APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/libtsm.sym\"") +set_property(TARGET tsm APPEND_STRING + PROPERTY + LINK_FLAGS " -Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/libtsm.sym\"" +) add_libtsm_compile_options(tsm) + +# Installation +install(TARGETS tsm EXPORT tsm-targets + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) From 521df915fbf4e854c9e32f8d58abfe1dbf480507 Mon Sep 17 00:00:00 2001 From: Aetf Date: Wed, 3 Oct 2018 16:26:46 -0400 Subject: [PATCH 04/20] build: implement rule for build testing Signed-off-by: Aetf --- CMakeLists.txt | 23 ++++-- cmake/Utilities.cmake | 36 ++++++--- cmake/modules/FindCheck.cmake | 85 ++++++++++++++++++++ cmake/modules/FindPangoCairo.cmake | 2 +- external/{ => xkbcommon}/xkbcommon-keysyms.h | 0 src/tsm/CMakeLists.txt | 76 ++++++++++++----- src/tsm/tsm-vte.c | 6 +- test/CMakeLists.txt | 32 ++++++++ test/test_common.h | 3 - test/test_htable.c | 1 + test/test_symbol.c | 2 + 11 files changed, 219 insertions(+), 47 deletions(-) create mode 100644 cmake/modules/FindCheck.cmake rename external/{ => xkbcommon}/xkbcommon-keysyms.h (100%) create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 54558e1..29dc180 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,14 @@ -cmake_minimum_required(VERSION 3.6) +cmake_minimum_required(VERSION 3.10) -project(libtsm VERSION 4.0.0 LANGUAGES C) +project(libtsm + LANGUAGES C + VERSION 4.0.0 + DESCRIPTION "terminal-emulator state machine" +) # Some meta data ## TODO: merge into project above after we require cmake 3.12 set(PROJECT_HOMEPAGE_URL "https://github.com/Aetf/libtsm") -## TODO: merge into project above after we require cmake 3.10 -set(PROJECT_DESCRIPTION "terminal-emulator state machine") #--------------------------------------------------------------------------------------- # Initial setups @@ -58,7 +60,7 @@ include(GNUInstallDirs) # Extra cmake helpers find_package(ECM REQUIRED NO_MODULE REQUIRED) -list(APPEND CMAKE_MODULE_PATH ${ECM_FIND_MODULE_DIR}) +list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_DIR} ${ECM_FIND_MODULE_DIR}) # We need xkbcommon for keysym definitions. If it's not found, we use our own # private copy of xkbcommon-keysyms.h. @@ -101,6 +103,15 @@ if(BUILD_GTKTSM) ) endif() +if(BUILD_TESTING) + enable_testing() + find_package(Check) + set_package_properties(Check PROPERTIES + TYPE REQUIRED + PURPOSE "For testing" + ) +endif() + feature_summary(INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES WHAT ALL) #--------------------------------------------------------------------------------------- @@ -128,7 +139,7 @@ add_subdirectory(external) add_subdirectory(src) if(BUILD_TESTING) - add_subdirectory(tests) + add_subdirectory(test) endif(BUILD_TESTING) #--------------------------------------------------------------------------------------- diff --git a/cmake/Utilities.cmake b/cmake/Utilities.cmake index 7f95148..e8f9d40 100644 --- a/cmake/Utilities.cmake +++ b/cmake/Utilities.cmake @@ -36,7 +36,7 @@ endfunction() # Print all properties for a target # From https://stackoverflow.com/questions/32183975/how-to-print-all-the-properties-of-a-target-in-cmake - +# # Get all propreties that cmake supports execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST) # Convert command output into a CMake list @@ -240,33 +240,45 @@ macro(find_package_handle_library_components module_name) endmacro() # -# Link to an object library privately without polluting target exports +# Helper to link to an object library. +# +# The advantage of using this over target_link_library directly +# is that when used privately, it will not pollute target exports, +# See: https://gitlab.kitware.com/cmake/cmake/issues/17357 # -# this is done by not involving target_link_libraries but directly set +# This is done by not involving target_link_libraries but directly set # properties. # -# This is needed because we don't want the consumer target to have to -# export the object library -# See: https://gitlab.kitware.com/cmake/cmake/issues/17357 function(target_link_object_libraries target) set(tlol_options) set(tlol_oneValueArgs) - set(tlol_multiValueArgs PRIVATE) + set(tlol_multiValueArgs PRIVATE INTERFACE PUBLIC) cmake_parse_arguments(TLOL "${tlol_options}" "${tlol_oneValueArgs}" "${tlol_multiValueArgs}" ${ARGN}) if(TLOL_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unexpected arguments to target_link_object_libraries: ${TLOL_UNPARSED_ARGUMENTS}, note that only PRIVATE is allowed") + message(FATAL_ERROR "Unexpected arguments to target_link_object_libraries: ${TLOL_UNPARSED_ARGUMENTS}") endif() - if(NOT TLOL_PRIVATE) - message(FATAL_ERROR "Missing PRIVATE argument to target_link_object_libraries") + if(NOT TLOL_PRIVATE AND NOT TLOL_INTERFACE AND NOT TLOL_PUBLIC) + message(FATAL_ERROR "Missing PRIVATE|INTERFACE|PUBLIC argument to target_link_object_libraries") endif() foreach(lib IN LISTS TLOL_PRIVATE) - target_sources(${target} PRIVATE $) + target_sources(${target} PRIVATE $ $) target_include_directories(${target} PRIVATE $) target_compile_options(${target} PRIVATE $) - # This is not supported + # This is not supported, as it will make exporting ${target} also needs exporting ${lib} even in PRIVATE mode #target_link_libraries(${target} PRIVATE $) endforeach() + foreach(lib IN LISTS TLOL_INTERFACE) + target_sources(${target} INTERFACE $ $) + target_include_directories(${target} INTERFACE $) + target_compile_options(${target} INTERFACE $) + target_link_libraries(${target} INTERFACE $) + endforeach() + foreach(lib IN LISTS TLOL_PUBLIC) + target_sources(${target} PUBLIC $ $) + target_include_directories(${target} PUBLIC $) + target_compile_options(${target} PUBLIC $) + endforeach() endfunction() diff --git a/cmake/modules/FindCheck.cmake b/cmake/modules/FindCheck.cmake new file mode 100644 index 0000000..2e1d060 --- /dev/null +++ b/cmake/modules/FindCheck.cmake @@ -0,0 +1,85 @@ +# Try to find libcheck +# +# This will define: +# +# Check_FOUND - True if libcheck is available +# Check_LIBRARIES - Found libraries for libcheck +# Check_INCLUDE_DIRS - Include directory for libcheck +# Check_DEFINITIONS - Other compiler flags for using libcheck +# Check_VERSION - Version of the found libcheck +# +# Additionally, the following imported targets will be defined: +# +# check::check +# +include(FindPackageHandleStandardArgs) + +set(module_name Check) + +find_package(PkgConfig QUIET) + +pkg_check_modules(PKG_${module_name} QUIET check) + +find_path(${module_name}_INCLUDE_DIR + NAMES check.h + HINTS ${PKG_${module_name}_INCLUDE_DIRS} +) +find_library(${module_name}_LIBRARY + NAMES check + HINTS ${PKG_${module_name}_LIBRARY_DIRS} +) + +set(${module_name}_VERSION "${PKG_${module_name}_VERSION}") +if(NOT ${module_name}_VERSION) + set(${module_name}_VERSION ${${module_name}_${fphlc_comp}_VERSION}) + + if(${module_name}_INCLUDE_DIR) + file(STRINGS "${${module_name}_INCLUDE_DIR}/check.h" ${module_name}_MAJOR_VERSION REGEX "^#define CHECK_MAJOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define CHECK_MAJOR_VERSION \\(?([0-9]+)\\)?" "\\1" ${module_name}_MAJOR_VERSION "${${module_name}_MAJOR_VERSION}") + file(STRINGS "${${module_name}_INCLUDE_DIR}/check.h" ${module_name}_MINOR_VERSION REGEX "^#define CHECK_MINOR_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define CHECK_MINOR_VERSION \\(?([0-9]+)\\)?" "\\1" ${module_name}_MINOR_VERSION "${${module_name}_MINOR_VERSION}") + file(STRINGS "${${module_name}_INCLUDE_DIR}/check.h" ${module_name}_MICRO_VERSION REGEX "^#define CHECK_MICRO_VERSION +\\(?([0-9]+)\\)?$") + string(REGEX REPLACE "^#define CHECK_MICRO_VERSION \\(?([0-9]+)\\)?" "\\1" ${module_name}_MICRO_VERSION "${${module_name}_MICRO_VERSION}") + set(${module_name}_VERSION "${${module_name}_MAJOR_VERSION}.${${module_name}_MINOR_VERSION}.${${module_name}_MICRO_VERSION}") + unset(${module_name}_MAJOR_VERSION) + unset(${module_name}_MINOR_VERSION) + unset(${module_name}_MICRO_VERSION) + endif() +endif() + +find_package_handle_standard_args(${module_name} + FOUND_VAR + ${module_name}_FOUND + REQUIRED_VARS + ${module_name}_LIBRARY + ${module_name}_INCLUDE_DIR + VERSION_VAR + ${module_name}_VERSION +) + +mark_as_advanced( + ${module_name}_LIBRARY + ${module_name}_INCLUDE_DIR +) + +if(${module_name}_FOUND) + list(APPEND ${module_name}_LIBRARIES "${${module_name}_LIBRARY}") + list(APPEND ${module_name}_INCLUDE_DIRS "${${module_name}_INCLUDE_DIR}") + list(APPEND ${module_name}_DEFINITIONS "${PKG_${module_name}_DEFINITIONS}") + if(NOT TARGET check::check) + add_library(check::check UNKNOWN IMPORTED) + set_target_properties(check::check PROPERTIES + INTERFACE_COMPILE_OPTIONS "${${module_name}_DEFINITIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${${module_name}_INCLUDE_DIR}" + IMPORTED_LOCATION "${${module_name}_LIBRARY}" + ) + endif() +endif() + +include(FeatureSummary) +set_package_properties(${module_name} PROPERTIES + URL "https://libcheck.github.io/check/" + DESCRIPTION "A unit testing framework for C" +) + +unset(module_name) diff --git a/cmake/modules/FindPangoCairo.cmake b/cmake/modules/FindPangoCairo.cmake index 44e5972..3a66be4 100644 --- a/cmake/modules/FindPangoCairo.cmake +++ b/cmake/modules/FindPangoCairo.cmake @@ -51,7 +51,7 @@ foreach(pangocairo_dep ${PangoCairo_DEPS}) list(APPEND PangoCairo_DEPS_FOUND_VARS "${pangocairo_dep}_FOUND") list(APPEND PangoCairo_INCLUDE_DIRS ${${pangocairo_dep}_INCLUDE_DIRS}) - set_property (TARGET "${PangoCairo}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${pango_dep}}") + set_property(TARGET "${PangoCairo}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${pango_dep}}") endforeach(pangocairo_dep) include(FindPackageHandleStandardArgs) diff --git a/external/xkbcommon-keysyms.h b/external/xkbcommon/xkbcommon-keysyms.h similarity index 100% rename from external/xkbcommon-keysyms.h rename to external/xkbcommon/xkbcommon-keysyms.h diff --git a/src/tsm/CMakeLists.txt b/src/tsm/CMakeLists.txt index 7f7a22a..9fed17f 100644 --- a/src/tsm/CMakeLists.txt +++ b/src/tsm/CMakeLists.txt @@ -2,7 +2,11 @@ # libtsm # Main library build instructions # -add_library(tsm + +# +# Use a separate object library that is shared between tsm and tsm_test +# +add_library(tsm_obj OBJECT tsm-render.c tsm-screen.c tsm-selection.c @@ -10,41 +14,73 @@ add_library(tsm tsm-vte.c tsm-vte-charsets.c ) - -# Add an alias so that library can be used inside the build tree, e.g. when testing -add_library(libtsm::tsm ALIAS tsm) - # Link to dependencies -target_link_object_libraries(tsm - PRIVATE +target_link_object_libraries(tsm_obj + PUBLIC external shl ) if(XKBCommon_KeySyms_FOUND) - target_link_libraries(tsm - PRIVATE + target_link_libraries(tsm_obj + INTERFACE XKB::KeySyms ) endif() -target_include_directories(tsm - PUBLIC - $ - $ -) -set_target_properties(tsm PROPERTIES +set_target_properties(tsm_obj PROPERTIES POSITION_INDEPENDENT_CODE ON C_VISIBILITY_PRESET hidden - VERSION "${PROJECT_VERSION}" - SOVERSION "${PROJECT_VERSION_MAJOR}" - PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/libtsm.h" ) + +# Other non-compilation properties shared between tsm and tsm_test +function(apply_properties target) + target_include_directories(${target} + INTERFACE + $ + $ + ) + set_target_properties(${target} PROPERTIES + POSITION_INDEPENDENT_CODE ON + C_VISIBILITY_PRESET hidden + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}" + PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/libtsm.h" + ) + add_libtsm_compile_options(${target}) +endfunction() + +# +# Main production library +# +add_library(tsm) +target_link_object_libraries(tsm PRIVATE tsm_obj) +apply_properties(tsm) +# The production library additionally use version script set_property(TARGET tsm APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/libtsm.sym\"" + LINK_FLAGS " -Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/libtsm.sym\"" ) -add_libtsm_compile_options(tsm) +# Add an alias so that library can be used inside the build tree +add_library(libtsm::tsm ALIAS tsm) + +# +# Add an additional static library for testing +# +if(BUILD_TESTING) + # Must be static to avoid visibility=hidden + add_library(tsm_test STATIC) + target_link_object_libraries(tsm_test PRIVATE tsm_obj) + apply_properties(tsm_test) + # Additionally expose internal private header path + target_include_directories(tsm_test + INTERFACE + $ + ) +endif() + +# # Installation +# install(TARGETS tsm EXPORT tsm-targets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" diff --git a/src/tsm/tsm-vte.c b/src/tsm/tsm-vte.c index 4b3d5b7..6a0ba49 100644 --- a/src/tsm/tsm-vte.c +++ b/src/tsm/tsm-vte.c @@ -53,11 +53,7 @@ #include "libtsm-int.h" #include "shl-llog.h" -#ifdef BUILD_HAVE_XKBCOMMON -# include -#else -# include "external/xkbcommon-keysyms.h" -#endif +#include #define LLOG_SUBSYSTEM "tsm-vte" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..a6267fe --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# Tests +# These tests are included in a separate "test" target that can be run manually via `make test' +# But a more useful way to run the tests is using ctest, which runs valgrind on all tests. +# This is also the setup using in our CI. +# Note that ctest fails if _any_ leak is detected by valgrind. Thus, you +# need to have valgrind installed and libcheck running properly (without leaks) +# to make the tests succeed. + +include(ECMAddTests) + +ecm_add_test(test_htable + LINK_LIBRARIES + check::check +) +target_link_object_libraries(test_htable + PRIVATE + shl +) + +ecm_add_test(test_symbol + LINK_LIBRARIES + tsm_test + check::check +) + +# This is only a quick sanity check that verifies the +# valgrind tests work properly. +ecm_add_test(test_valgrind + LINK_LIBRARIES + check::check +) diff --git a/test/test_common.h b/test/test_common.h index 984ec3f..e9498a8 100644 --- a/test/test_common.h +++ b/test/test_common.h @@ -43,9 +43,6 @@ #include #include #include -#include "tsm/libtsm.h" -#include "tsm/libtsm-int.h" -#include "shl-htable.h" /* lower address-space is protected from user-allocation, so this is invalid */ #define TEST_INVALID_PTR ((void*)0x10) diff --git a/test/test_htable.c b/test/test_htable.c index 74e5c2d..9a4d0bc 100644 --- a/test/test_htable.c +++ b/test/test_htable.c @@ -25,6 +25,7 @@ #include "test_common.h" +#include "shl-htable.h" static struct shl_htable ht = SHL_HTABLE_INIT_STR(ht); static struct shl_htable uht = SHL_HTABLE_INIT_ULONG(uht); diff --git a/test/test_symbol.c b/test/test_symbol.c index d5efb64..0d932db 100644 --- a/test/test_symbol.c +++ b/test/test_symbol.c @@ -24,6 +24,8 @@ */ #include "test_common.h" +#include "libtsm.h" +#include "libtsm-int.h" START_TEST(test_symbol_null) { From 74dbabea2e364b7df5ce1b268c693295db59a0fa Mon Sep 17 00:00:00 2001 From: Aetf Date: Fri, 5 Oct 2018 14:38:53 -0400 Subject: [PATCH 05/20] build: implement ctest script as test runner --- ci.ctest | 27 +++++++++++++++++++++++++++ test.supp => etc/test.supp | 0 2 files changed, 27 insertions(+) create mode 100644 ci.ctest rename test.supp => etc/test.supp (100%) diff --git a/ci.ctest b/ci.ctest new file mode 100644 index 0000000..548a576 --- /dev/null +++ b/ci.ctest @@ -0,0 +1,27 @@ +set(CTEST_PROJECT_NAME libtsm) + +set(CTEST_SOURCE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) +set(CTEST_BINARY_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/build/ctest") + +set(CTEST_CMAKE_GENERATOR "Unix Makefiles") + +set(ENV{CK_FORK} "no") +find_program(VALGRIND valgrind) +if(NOT VALGRIND) + message(FATAL_ERROR "valgrind is required for memcheck") +endif() +set(CTEST_MEMORYCHECK_COMMAND "${VALGRIND}") +string(CONCAT CTEST_MEMORYCHECK_COMMAND_OPTIONS + " --tool=memcheck" + " --leak-check=yes" + " --show-reachable=yes" + " --leak-resolution=high" + " --error-exitcode=1" +) +set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "${CTEST_SOURCE_DIRECTORY}/etc/test.supp") + +ctest_start("Continuous") +ctest_configure(OPTIONS -DBUILD_TESTING=ON) +ctest_build() +ctest_test() +ctest_memcheck() diff --git a/test.supp b/etc/test.supp similarity index 100% rename from test.supp rename to etc/test.supp From 219f218b8c6791126883afaf03a91a2fe41cb311 Mon Sep 17 00:00:00 2001 From: Aetf Date: Fri, 5 Oct 2018 15:20:44 -0400 Subject: [PATCH 06/20] build: add travis ci --- .travis.yml | 25 +++++++++++++++++++++++++ ci.ctest | 30 ++++++++++++++++++++++++++---- cmake/modules/FindCheck.cmake | 2 +- test/CMakeLists.txt | 2 ++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4d4c2b2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +language: cpp + +dist: trusty +sudo: false + +addons: + apt: + packages: + - valgrind + - libgtk-3-dev + - libpango1.0-dev + - check + +matrix: + include: + - os: linux + compiler: gcc + - os: osx + compiler: clang + +install: + - pip install --user --upgrade cmake + +script: + - ctest -VV -S ./ci.ctest diff --git a/ci.ctest b/ci.ctest index 548a576..9c0b6e7 100644 --- a/ci.ctest +++ b/ci.ctest @@ -21,7 +21,29 @@ string(CONCAT CTEST_MEMORYCHECK_COMMAND_OPTIONS set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "${CTEST_SOURCE_DIRECTORY}/etc/test.supp") ctest_start("Continuous") -ctest_configure(OPTIONS -DBUILD_TESTING=ON) -ctest_build() -ctest_test() -ctest_memcheck() + +ctest_configure(OPTIONS "-DBUILD_TESTING=ON;-DBUILD_GTKTSM=ON" RETURN_VALUE ret) +if(NOT ${ret} EQUAL 0) + message(FATAL_ERROR "Configure step failed with ${ret}") +endif() + +ctest_build(RETURN_VALUE ret) +if(NOT ${ret} EQUAL 0) + message(FATAL_ERROR "Build step failed with ${ret}") +endif() + +ctest_test(RETURN_VALUE ret) +if(NOT ${ret} EQUAL 0) + message(FATAL_ERROR "Test step failed with ${ret}") +endif() + +# First make sure valgrind works +ctest_memcheck(INCLUDE_LABEL "memcheck-xfail" RETURN_VALUE ret) +if(${ret} EQUAL 0) + message(FATAL_ERROR "Valgrind may not work correctly. Expected failed test got passed.") +endif() + +ctest_memcheck(EXCLUDE_LABEL "memcheck-xfail" RETURN_VALUE ret) +if(NOT ${ret} EQUAL 0) + message(FATAL_ERROR "Memcheck step failed with ${ret}") +endif() diff --git a/cmake/modules/FindCheck.cmake b/cmake/modules/FindCheck.cmake index 2e1d060..3f60b68 100644 --- a/cmake/modules/FindCheck.cmake +++ b/cmake/modules/FindCheck.cmake @@ -31,7 +31,7 @@ find_library(${module_name}_LIBRARY set(${module_name}_VERSION "${PKG_${module_name}_VERSION}") if(NOT ${module_name}_VERSION) - set(${module_name}_VERSION ${${module_name}_${fphlc_comp}_VERSION}) + set(${module_name}_VERSION ${${module_name}_VERSION}) if(${module_name}_INCLUDE_DIR) file(STRINGS "${${module_name}_INCLUDE_DIR}/check.h" ${module_name}_MAJOR_VERSION REGEX "^#define CHECK_MAJOR_VERSION +\\(?([0-9]+)\\)?$") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a6267fe..c7428e0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,3 +30,5 @@ ecm_add_test(test_valgrind LINK_LIBRARIES check::check ) +# mark the test as will fail in memcheck +set_tests_properties(test_valgrind PROPERTIES LABELS memcheck-xfail) From 88ea6724a85eca92bec96a30d0dc8934d8b804d8 Mon Sep 17 00:00:00 2001 From: Aetf Date: Fri, 5 Oct 2018 15:34:04 -0400 Subject: [PATCH 07/20] build: remove autotools --- .gitignore | 31 +----- Makefile.am | 286 --------------------------------------------------- autogen.sh | 17 --- configure.ac | 200 ----------------------------------- 4 files changed, 2 insertions(+), 532 deletions(-) delete mode 100644 Makefile.am delete mode 100755 autogen.sh delete mode 100644 configure.ac diff --git a/.gitignore b/.gitignore index 8099e9a..5c7cb12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,7 @@ -*.la -*.lo +build *.log *.memlog -*.o *.swp *.tar.xz -*.trs -.deps/ -.dirstamp -.libs/ -Makefile -Makefile.in -aclocal.m4 -autom4te.cache/ -build-aux/ -config.h -/config.h.in -config.h.in~ -config.log -config.status -configure -/gtktsm -libtool -m4/ -src/tsm/libtsm.pc -stamp-h1 -test-suite.log -test_htable -test_symbol -test_valgrind -*.kdev4 -build +*~ .idea diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 18cda4a..0000000 --- a/Makefile.am +++ /dev/null @@ -1,286 +0,0 @@ -# -# libtsm - Global Makefile -# Copyright (c) 2018 Aetf -# Copyright (c) 2012-2013 David Herrmann -# - -# -# Library Version Numbers -# - -LIBTSM_CURRENT = 4 -LIBTSM_REVISION = 0 -LIBTSM_AGE = 0 - -# -# Global Configurations and Initializations -# - -ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} -AM_MAKEFLAGS = --no-print-directory -AUTOMAKE_OPTIONS = color-tests -AM_DISTCHECK_CONFIGURE_FLAGS = \ - --enable-debug \ - --enable-optimizations - -SUBDIRS = . - -.DELETE_ON_ERROR: - -include_HEADERS = -EXTRA_DIST = \ - README \ - COPYING \ - LICENSE_htable \ - NEWS -CLEANFILES = -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = -TPHONY = - -TESTS = -MEMTESTS = -check_PROGRAMS = -bin_PROGRAMS = -lib_LTLIBRARIES = -noinst_LTLIBRARIES = - -# -# Default CFlags -# Make all files include "config.h" by default. This shouldn't cause any -# problems and we cannot forget to include it anymore. -# -# Also make the linker discard all unused symbols. -# -# When compiling in debug mode, we enable debug symbols so debugging with gdb -# is easier. If optimizations are disabled, we pass -O0 to the compiler. -# Otherwise, we use standard optimizations -O2. -# - -AM_CFLAGS = \ - -Wall \ - -pipe \ - -fno-common \ - -ffast-math \ - -fdiagnostics-show-option \ - -fno-strict-aliasing \ - -fvisibility=hidden \ - -ffunction-sections \ - -fdata-sections -AM_CPPFLAGS = \ - -include $(top_builddir)/config.h \ - -I $(srcdir)/src \ - -I $(srcdir)/src/shared -AM_LDFLAGS = - -if BUILD_HAVE_GNU_LD -AM_LDFLAGS += \ - -Wl,--as-needed \ - -Wl,--gc-sections \ - -Wl,-z,relro \ - -Wl,-z,now -else -if BUILD_IS_DARWIN -AM_LDFLAGS += \ - -Wl,-dead_strip \ - -Wl,-dead_strip_dylibs \ - -Wl,-bind_at_load -endif -endif - -if BUILD_ENABLE_DEBUG -AM_CFLAGS += -g -endif - -if BUILD_ENABLE_OPTIMIZATIONS -AM_CFLAGS += -O2 -else -AM_CFLAGS += -O0 -endif - -# -# SHL - Static Helper Library -# The SHL subsystem contains several small code pieces used all over libtsm and -# other applications. -# - -noinst_LTLIBRARIES += libshl.la - -libshl_la_SOURCES = \ - src/shared/shl-array.h \ - src/shared/shl-htable.h \ - src/shared/shl-htable.c \ - src/shared/shl-llog.h \ - src/shared/shl-macro.h \ - src/shared/shl-ring.h \ - src/shared/shl-ring.c -libshl_la_CPPFLAGS = $(AM_CPPFLAGS) -libshl_la_LDFLAGS = $(AM_LDFLAGS) -libshl_la_LIBADD = $(AM_LIBADD) - -# -# libtsm -# Main library build instructions -# - -lib_LTLIBRARIES += libtsm.la -noinst_LTLIBRARIES += libtsm-test.la -include_HEADERS += src/tsm/libtsm.h -pkgconfig_DATA += src/tsm/libtsm.pc -EXTRA_DIST += \ - src/tsm/libtsm.pc.in \ - src/tsm/libtsm.sym - -libtsm_la_SOURCES = \ - src/tsm/libtsm.h \ - src/tsm/libtsm-int.h \ - src/tsm/tsm-render.c \ - src/tsm/tsm-screen.c \ - src/tsm/tsm-selection.c \ - src/tsm/tsm-unicode.c \ - src/tsm/tsm-vte.c \ - src/tsm/tsm-vte-charsets.c \ - external/wcwidth/wcwidth.h \ - external/wcwidth/wcwidth.c \ - external/xkbcommon-keysyms.h -libtsm_test_la_SOURCES = $(libtsm_la_SOURCES) - -libtsm_la_CPPFLAGS = $(AM_CPPFLAGS) -libtsm_test_la_CPPFLAGS = $(AM_CPPFLAGS) - -libtsm_la_LIBADD = libshl.la -libtsm_test_la_LIBADD = libshl.la - -EXTRA_libtsm_la_DEPENDENCIES = $(top_srcdir)/src/tsm/libtsm.sym - -libtsm_la_LDFLAGS = \ - $(AM_LDFLAGS) \ - -version-info $(LIBTSM_CURRENT):$(LIBTSM_REVISION):$(LIBTSM_AGE) - -if BUILD_HAVE_GNU_LD -libtsm_la_LDFLAGS += \ - -Wl,--version-script="$(top_srcdir)/src/tsm/libtsm.sym" -endif - -libtsm_test_la_LDFLAGS = \ - $(AM_LDFLAGS) - -if BUILD_HAVE_XKBCOMMON -libtsm_la_CPPFLAGS += $(XKBCOMMON_CFLAGS) -libtsm_test_la_CPPFLAGS += $(XKBCOMMON_CFLAGS) -endif - -# -# GtkTsm - Example -# - -if BUILD_ENABLE_GTKTSM -bin_PROGRAMS += gtktsm -endif - -gtktsm_SOURCES = \ - src/gtktsm/gtktsm.c \ - src/gtktsm/gtktsm-app.h \ - src/gtktsm/gtktsm-app.c \ - src/gtktsm/gtktsm-terminal.h \ - src/gtktsm/gtktsm-terminal.c \ - src/gtktsm/gtktsm-win.h \ - src/gtktsm/gtktsm-win.c \ - src/shared/shl-pty.h \ - src/shared/shl-pty.c -gtktsm_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -I $(srcdir)/src/tsm \ - $(GTKTSM_CFLAGS) -gtktsm_LDADD = \ - -lm \ - libshl.la \ - libtsm.la \ - $(GTKTSM_LIBS) -gtktsm_LDFLAGS = \ - $(AM_LDFLAGS) - -# -# Tests -# We add a separate "memcheck" target which runs valgrind on all tests in -# MEMTESTS. Note that we fail if _any_ leak is detected by valgrind. Thus, you -# need to have valgrind installed and libcheck running properly (without leaks) -# to make memcheck succeed. -# A separate memcheck-verify actually runs a faulty test and verifies the -# valgrind tests work properly. -# - -if BUILD_HAVE_CHECK -check_PROGRAMS += \ - test_htable \ - test_symbol \ - test_valgrind -TESTS += \ - test_htable \ - test_symbol \ - test_valgrind -MEMTESTS += \ - test_htable \ - test_symbol -endif - -test_sources = \ - test/test_common.h -test_libs = \ - libshl.la \ - libtsm-test.la \ - $(CHECK_LIBS) -test_cflags = \ - $(AM_CPPFLAGS) \ - $(CHECK_CFLAGS) -test_lflags = \ - $(AM_LDFLAGS) - -test_htable_SOURCES = test/test_htable.c $(test_sources) -test_htable_CPPFLAGS = $(test_cflags) -test_htable_LDADD = $(test_libs) -test_htable_LDFLAGS = $(test_lflags) - -test_symbol_SOURCES = test/test_symbol.c $(test_sources) -test_symbol_CPPFLAGS = $(test_cflags) -test_symbol_LDADD = $(test_libs) -test_symbol_LDFLAGS = $(test_lflags) - -test_valgrind_SOURCES = test/test_valgrind.c $(test_sources) -test_valgrind_CPPFLAGS = $(test_cflags) -test_valgrind_LDADD = $(test_libs) -test_valgrind_LDFLAGS = $(test_lflags) - -EXTRA_DIST += test.supp - -VALGRIND = CK_FORK=no valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --leak-resolution=high --error-exitcode=1 --suppressions=$(top_builddir)/test.supp - -# verify that test_valgrind actually leaks data -memcheck-verify: check - $(AM_V_GEN)$(VALGRIND) --log-file=/dev/null ./test_valgrind >/dev/null ; test 1 = $$? - -TPHONY += memcheck-verify - -# run memcheck tests via valgrind -memcheck: memcheck-verify - $(AM_V_GEN)for i in $(MEMTESTS) ; do \ - $(VALGRIND) --log-file=$(top_builddir)/$$i.memlog \ - $(top_builddir)/$$i >/dev/null || (echo "memcheck failed on: $$i" ; exit 1) ; \ - done - -TPHONY += memcheck memcheck-verify - -distcheck-hook: memcheck - -# -# Phony targets -# - -.PHONY: $(TPHONY) - -# -# Empty .SECONDARY target causes alle intermediate files to be treated as -# secondary files. That is, they don't get deleted after make finished. -# - -.SECONDARY: diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 65a6fe1..0000000 --- a/autogen.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -set -e - -srcdir=`dirname $0` -test -z "$srcdir" && srcdir=. - -origdir=`pwd` -cd $srcdir - -mkdir -p m4 -autoreconf -is --force - -cd $origdir - -if test -z "$NOCONFIGURE" ; then - exec $srcdir/configure "$@" -fi diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 38b78b1..0000000 --- a/configure.ac +++ /dev/null @@ -1,200 +0,0 @@ -# -# libtsm - build configuration script -# Copyright (c) 2012-2013 David Herrmann -# - -AC_PREREQ(2.68) - -AC_INIT([libtsm], - [4.0.0], - [https://github.com/Aetf/libtsm/issues/new], - [libtsm], - [https://github.com/Aetf/libtsm]) -AC_CONFIG_SRCDIR([src/tsm/libtsm.h]) -AC_CONFIG_AUX_DIR([build-aux]) -AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_HEADER(config.h) -AC_USE_SYSTEM_EXTENSIONS -AC_SYS_LARGEFILE -AC_CANONICAL_HOST - -AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects dist-xz no-dist-gzip tar-pax -Wall -Werror -Wno-portability]) -AM_SILENT_RULES([yes]) - -AC_SUBST(PACKAGE_DESCRIPTION, ["terminal-emulator state machine"]) - -# -# Don't add a default "-g -O2" if CFLAGS wasn't specified. For debugging it is -# often more convenient to have "-g -O0". You can still override it by -# explicitly setting it on the command line. -# - -: ${CFLAGS=""} - -AC_PROG_CC -AC_PROG_CC_C99 -AM_PROG_CC_C_O -m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) -AC_PROG_SED -AC_PROG_MKDIR_P -AC_PROG_LN_S -AC_PROG_GREP -AC_PROG_AWK - -LT_PREREQ(2.2) -LT_INIT - -# -# We need xkbcommon for keysym definitions. If it's not found, we use our own -# private copy of xkbcommon-keysyms.h. -# - -PKG_CHECK_MODULES([XKBCOMMON], [xkbcommon], - [have_xkbcommon=yes], [have_xkbcommon=no]) -AC_SUBST(XKBCOMMON_CFLAGS) -if test "x$have_xkbcommon" = "xyes" ; then - AC_DEFINE([BUILD_HAVE_XKBCOMMON], [1], [Have xkbcommon library]) -fi -AM_CONDITIONAL([BUILD_HAVE_XKBCOMMON], [test "x$have_xkbcommon" = "xyes"]) - -# -# Test for "check" which we use for our test-suite. If not found, we disable -# all tests. -# - -PKG_CHECK_MODULES([CHECK], [check], - [have_check=yes], [have_check=no]) -AC_SUBST(CHECK_CFLAGS) -AC_SUBST(CHECK_LIBS) -AM_CONDITIONAL([BUILD_HAVE_CHECK], [test "x$have_check" = "xyes"]) - -# -# Optionally, look for gtk+-3 and friends for our gtktsm example. -# This is linux-only as it uses epoll and friends. Therefore, it's disabled by -# default. -# - -AC_MSG_CHECKING([whether to build gtktsm]) -AC_ARG_ENABLE([gtktsm], - [AS_HELP_STRING([--enable-gtktsm], - [whether to build gtktsm])]) -if test "x$enable_gtktsm" = "x" ; then - enable_gtktsm="no (default)" -fi -AC_MSG_RESULT([$enable_gtktsm]) - -PKG_CHECK_MODULES([GTKTSM], [gtk+-3.0 cairo pango pangocairo xkbcommon], - [have_gtktsm=yes], [have_gtktsm=no]) -AC_SUBST(GTKTSM_CFLAGS) -AC_SUBST(GTKTSM_LIBS) - -if test ! "x$have_gtktsm" = "xyes" ; then - if test "x$enable_gtktsm" = "xyes" ; then - AC_ERROR([GtkTsm dependencies not found]) - else - enable_gtktsm="no" - fi -elif test "x${enable_gtktsm% *}" = "xyes" ; then - enable_gtktsm="yes" -else - enable_gtktsm="no" -fi -AM_CONDITIONAL([BUILD_ENABLE_GTKTSM], [test "x$enable_gtktsm" = "xyes"]) - -# -# debug mode -# If --enable-debug is given, we enable several non-standard debug options. We -# enable a lot of debug options by default, so this option is really only for -# extended developer debug modes. -# - -AC_MSG_CHECKING([whether to build with debugging on]) -AC_ARG_ENABLE([debug], - [AS_HELP_STRING([--enable-debug], - [whether to build with debugging on])]) -if test "x$enable_debug" = "x" ; then - enable_debug="yes (default)" -fi -AC_MSG_RESULT([$enable_debug]) - -if test "x${enable_debug% *}" = "xyes" ; then - enable_debug="yes" - AC_DEFINE([BUILD_ENABLE_DEBUG], [1], [Enable debug mode]) -else - enable_debug="no" - AC_DEFINE([NDEBUG], [1], [No Debug]) -fi -AM_CONDITIONAL([BUILD_ENABLE_DEBUG], - [test "x$enable_debug" = "xyes"]) - -# -# Enable gcc compiler optimizations. We enable them by default but allow -# disabling them for better backtraces during debugging. -# - -AC_MSG_CHECKING([whether to enable code optimizations]) -AC_ARG_ENABLE([optimizations], - [AS_HELP_STRING([--disable-optimizations], - [whether to disable code optimizations])]) -if test "x$enable_optimizations" = "x" ; then - enable_optimizations="yes (default)" -fi -AC_MSG_RESULT([$enable_optimizations]) - -if test "x${enable_optimizations% *}" = "xyes" ; then - enable_optimizations="yes" -else - enable_optimizations="no" -fi -AM_CONDITIONAL([BUILD_ENABLE_OPTIMIZATIONS], - [test "x$enable_optimizations" = "xyes"]) - -# -# Check which linker is used -# - -AM_CONDITIONAL([BUILD_HAVE_GNU_LD], - [test "x$with_gnu_ld" = "xyes"]) - -# -# Detect darwin targets -# - -case "$host_os" in - darwin*) - $is_darwin = "xyes";; -esac - -AM_CONDITIONAL([BUILD_IS_DARWIN], - [test "x$is_darwin" = "xyes"]) - -# -# Makefile vars -# After everything is configured, we create all makefiles. -# - -AC_CONFIG_FILES([Makefile - src/tsm/libtsm.pc]) -AC_OUTPUT - -# -# Configuration output -# Show configuration to the user so they can check whether everything was -# configured as expected. -# - -AC_MSG_NOTICE([Build configuration: - - prefix: $prefix - exec-prefix: $exec_prefix - libdir: $libdir - includedir: $includedir - host-os: $host_os - - Miscellaneous Options: - gtktsm: $enable_gtktsm - debug: $enable_debug - optimizations: $enable_optimizations - building tests: $have_check - - Run "${MAKE-make}" to start compilation process]) From 443e3e9ceee012b3670ef6300284216b322b48e7 Mon Sep 17 00:00:00 2001 From: Aetf Date: Fri, 5 Oct 2018 16:28:21 -0400 Subject: [PATCH 08/20] build: drop dependency on extra-cmake-modules Signed-off-by: Aetf --- .travis.yml | 5 ++ CMakeLists.txt | 4 -- cmake/Utilities.cmake | 90 ++++++++++++++++--------------- cmake/modules/FindXKBCommon.cmake | 40 +------------- test/CMakeLists.txt | 19 +++++-- 5 files changed, 67 insertions(+), 91 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d4c2b2..d022136 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,8 @@ install: script: - ctest -VV -S ./ci.ctest + +# blocklist +branches: + except: + - /^feature.*$/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 29dc180..9c7d098 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,10 +58,6 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/gnome-cmake/mo # GNU filesystem layout include(GNUInstallDirs) -# Extra cmake helpers -find_package(ECM REQUIRED NO_MODULE REQUIRED) -list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_DIR} ${ECM_FIND_MODULE_DIR}) - # We need xkbcommon for keysym definitions. If it's not found, we use our own # private copy of xkbcommon-keysyms.h. find_package(XKBCommon COMPONENTS KeySyms) diff --git a/cmake/Utilities.cmake b/cmake/Utilities.cmake index e8f9d40..9cb860b 100644 --- a/cmake/Utilities.cmake +++ b/cmake/Utilities.cmake @@ -68,55 +68,57 @@ function(print_target_properties tgt) endforeach(prop) endfunction(print_target_properties) -# Add and initialize a thirdparty submodule -# Usage: add_submodule( [THIRDPARTY_DIR ] [PATCHES ...]) -# Args: -# - The name and path of the library submodule to add -# - [Optional] The root directory for thirdparty code -# - [Optional] Additional patches to apply to the library -function(add_submodule library_name) - set(options "") - set(oneValueArgs "THIRDPARTY_DIR") - set(multiValueArgs PATCHES) - cmake_parse_arguments(ADD_SUBMODULE - "${options}" - "${oneValueArgs}" - "${multiValueArgs}" - ${ARGN} - ) +# A simpler version to parse package components +# Copied from extra-cmake-modules +macro(find_package_parse_components module_name) + set(fppc_options) + set(fppc_oneValueArgs RESULT_VAR) + set(fppc_multiValueArgs KNOWN_COMPONENTS DEFAULT_COMPONENTS) + cmake_parse_arguments(FPPC "${fppc_options}" "${fppc_oneValueArgs}" "${fppc_multiValueArgs}" ${ARGN}) - if(EXISTS ADD_SUBMODULE_THIRDPARTY_DIR) - set(third_party_dir ${ADD_SUBMODULE_THIRDPARTY_DIR}) - else() - set(third_party_dir ${CMAKE_SOURCE_DIR}/thirdparty) + if(FPPC_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unexpected arguments to find_package_parse_components: ${FPPC_UNPARSED_ARGUMENTS}") + endif() + if(NOT FPPC_RESULT_VAR) + message(FATAL_ERROR "Missing RESULT_VAR argument to find_package_parse_components") + endif() + if(NOT FPPC_KNOWN_COMPONENTS) + message(FATAL_ERROR "Missing KNOWN_COMPONENTS argument to find_package_parse_components") + endif() + if(NOT FPPC_DEFAULT_COMPONENTS) + set(FPPC_DEFAULT_COMPONENTS ${FPPC_KNOWN_COMPONENTS}) endif() - if(NOT EXISTS ${third_party_dir}/${library_name}/CMakeLists.txt) - message(STATUS " Initializing submodule") - execute_process(COMMAND "git" "submodule" "update" "--init" "${third_party_dir}/${library_name}" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - RESULT_VARIABLE retcode - ) - if(NOT "${retcode}" STREQUAL "0") - message(FATAL_ERROR "Failed to checkout ${library_name} as submodule: ${retcode}") - endif(NOT "${retcode}" STREQUAL "0") + if(${module_name}_FIND_COMPONENTS) + set(fppc_requestedComps ${${module_name}_FIND_COMPONENTS}) - foreach(patch IN LISTS ADD_SUBMODULE_PATCHES) - message(STATUS " Applying patch ${patch}") - get_filename_component(abs_patch ${patch} ABSOLUTE) - execute_process(COMMAND "git" "apply" "${abs_patch}" - WORKING_DIRECTORY "${third_party_dir}/${library_name}" - RESULT_VARIABLE retcode - ) - if(NOT "${retcode}" STREQUAL "0") - message(FATAL_ERROR "Failed to intialize ${library_name} when applying ${abs_patch}: ${retcode}") - endif(NOT "${retcode}" STREQUAL "0") - endforeach(patch) - endif(NOT EXISTS ${third_party_dir}/${library_name}/CMakeLists.txt) + list(REMOVE_DUPLICATES fppc_requestedComps) - message("-- ${library_name} version: bundled") - add_subdirectory(${third_party_dir}/${library_name}) -endfunction(add_submodule) + # This makes sure components are listed in the same order as + # KNOWN_COMPONENTS (potentially important for inter-dependencies) + set(${FPPC_RESULT_VAR}) + foreach(fppc_comp ${FPPC_KNOWN_COMPONENTS}) + list(FIND fppc_requestedComps "${fppc_comp}" fppc_index) + if(NOT "${fppc_index}" STREQUAL "-1") + list(APPEND ${FPPC_RESULT_VAR} "${fppc_comp}") + list(REMOVE_AT fppc_requestedComps ${fppc_index}) + endif() + endforeach() + # if there are any left, they are unknown components + if(fppc_requestedComps) + set(fppc_msgType STATUS) + if(${module_name}_FIND_REQUIRED) + set(fppc_msgType FATAL_ERROR) + endif() + if(NOT ${module_name}_FIND_QUIETLY) + message(${fppc_msgType} "${module_name}: requested unknown components ${fppc_requestedComps}") + endif() + return() + endif() + else() + set(${FPPC_RESULT_VAR} ${FPPC_DEFAULT_COMPONENTS}) + endif() +endmacro() # # Creates an imported library target for each component. See ECM's documentation for usage. diff --git a/cmake/modules/FindXKBCommon.cmake b/cmake/modules/FindXKBCommon.cmake index b3a72aa..08d5e4f 100644 --- a/cmake/modules/FindXKBCommon.cmake +++ b/cmake/modules/FindXKBCommon.cmake @@ -16,11 +16,8 @@ # XKB::XKBCommon # XKB::KeySyms # -include(ECMFindModuleHelpersStub) include(FindPackageHandleStandardArgs) -ecm_find_package_version_check(XKBCommon) - # Note that this list needs to be ordered such that any component appears after its dependencies set(XKBCommon_known_components XKBCommon @@ -38,7 +35,7 @@ set(XKBCommon_KeySyms_lib) set(XKBCommon_KeySyms_header "xkbcommon/xkbcommon-keysyms.h") # Parse components -ecm_find_package_parse_components(XKBCommon +find_package_parse_components(XKBCommon RESULT_VAR XKBCommon_components KNOWN_COMPONENTS ${XKBCommon_known_components} ) @@ -68,41 +65,6 @@ find_package_handle_standard_args(XKBCommon unset(XKBCommon_component_FOUND_VARS) -## Use pkg-config to get the directories and then use these values -## in the FIND_PATH() and FIND_LIBRARY() calls -#find_package(PkgConfig) -#pkg_check_modules(PKG_XKB QUIET xkbcommon) -# -#set(XKBCommonKeySyms_DEFINITIONS ${PKG_XKB_CFLAGS_OTHER}) -# -#find_path(XKBCommonKeySyms_INCLUDE_DIR -# NAMES -# xkbcommon/xkbcommon-keysyms.h -# HINTS -# ${PKG_XKB_INCLUDE_DIRS} -#) -# -#set(XKBCommonKeySyms_INCLUDE_DIRS ${XKBCommonKeySyms_INCLUDE_DIR}) -#set(XKBCommonKeySyms_VERSION ${PKG_XKB_VERSION}) -# -#include(FindPackageHandleStandardArgs) -#find_package_handle_standard_args(XKB -# FOUND_VAR -# XKBCommonKeySyms_FOUND -# REQUIRED_VARS -# XKBCommonKeySyms_INCLUDE_DIRS -# VERSION_VAR -# XKBCommonKeySyms_VERSION -#) -# -#if(XKBCommonKeySyms_FOUND AND NOT TARGET XKB::KeySyms) -# add_library(XKB::KeySyms INTERFACE IMPORTED) -# set_target_properties(XKB::KeySyms PROPERTIES -# INTERFACE_COMPILE_OPTIONS "${XKBCommonKeySyms_DEFINITIONS}" -# INTERFACE_INCLUDE_DIRECTORIES "${XKBCommonKeySyms_INCLUDE_DIRS}" -# ) -#endif() - include(FeatureSummary) set_package_properties(XKBCommon PROPERTIES URL "http://xkbcommon.org" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c7428e0..842ca42 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,9 +7,20 @@ # need to have valgrind installed and libcheck running properly (without leaks) # to make the tests succeed. -include(ECMAddTests) +function(libtsm_add_test name) + set(options) + set(oneValueArgs) + set(multiValueArgs LINK_LIBRARIES) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) -ecm_add_test(test_htable + add_executable(${name} ${name}) + if(ARG_LINK_LIBRARIES) + target_link_libraries(${name} ${ARG_LINK_LIBRARIES}) + endif() + add_test(NAME ${name} COMMAND ${name}) +endfunction() + +libtsm_add_test(test_htable LINK_LIBRARIES check::check ) @@ -18,7 +29,7 @@ target_link_object_libraries(test_htable shl ) -ecm_add_test(test_symbol +libtsm_add_test(test_symbol LINK_LIBRARIES tsm_test check::check @@ -26,7 +37,7 @@ ecm_add_test(test_symbol # This is only a quick sanity check that verifies the # valgrind tests work properly. -ecm_add_test(test_valgrind +libtsm_add_test(test_valgrind LINK_LIBRARIES check::check ) From be3a61eb158ecb73b824b9e73c834164a4e0d03b Mon Sep 17 00:00:00 2001 From: Aetf Date: Fri, 5 Oct 2018 17:04:19 -0400 Subject: [PATCH 09/20] build: CI: fix FindCheck.cmake on static check libraries Signed-off-by: Aetf --- .travis.yml | 10 ++++------ ci.ctest | 16 +++++++++++++++- cmake/Utilities.cmake | 5 +++-- cmake/modules/FindCheck.cmake | 29 ++++++++++++++++++++--------- test/CMakeLists.txt | 2 +- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index d022136..2515af8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,13 +10,11 @@ addons: - libgtk-3-dev - libpango1.0-dev - check + - pkg-config -matrix: - include: - - os: linux - compiler: gcc - - os: osx - compiler: clang +compiler: + - gcc + - clang install: - pip install --user --upgrade cmake diff --git a/ci.ctest b/ci.ctest index 9c0b6e7..3c1177c 100644 --- a/ci.ctest +++ b/ci.ctest @@ -20,29 +20,43 @@ string(CONCAT CTEST_MEMORYCHECK_COMMAND_OPTIONS ) set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "${CTEST_SOURCE_DIRECTORY}/etc/test.supp") +function(print_section name) + message(STATUS "********************") + message(STATUS "${name}") + message(STATUS "********************") +endfunction() + +# +# Start the tests +# ctest_start("Continuous") +print_section("Configuring project") ctest_configure(OPTIONS "-DBUILD_TESTING=ON;-DBUILD_GTKTSM=ON" RETURN_VALUE ret) if(NOT ${ret} EQUAL 0) message(FATAL_ERROR "Configure step failed with ${ret}") endif() +print_section("Building project") ctest_build(RETURN_VALUE ret) if(NOT ${ret} EQUAL 0) message(FATAL_ERROR "Build step failed with ${ret}") endif() +print_section("Running tests") ctest_test(RETURN_VALUE ret) if(NOT ${ret} EQUAL 0) - message(FATAL_ERROR "Test step failed with ${ret}") + message(FATAL_ERROR "Tests step failed with ${ret}") endif() # First make sure valgrind works +print_section("Making sure valgrind works") ctest_memcheck(INCLUDE_LABEL "memcheck-xfail" RETURN_VALUE ret) if(${ret} EQUAL 0) message(FATAL_ERROR "Valgrind may not work correctly. Expected failed test got passed.") endif() +print_section("Running memcheck") ctest_memcheck(EXCLUDE_LABEL "memcheck-xfail" RETURN_VALUE ret) if(NOT ${ret} EQUAL 0) message(FATAL_ERROR "Memcheck step failed with ${ret}") diff --git a/cmake/Utilities.cmake b/cmake/Utilities.cmake index 9cb860b..42c68a9 100644 --- a/cmake/Utilities.cmake +++ b/cmake/Utilities.cmake @@ -40,8 +40,9 @@ endfunction() # Get all propreties that cmake supports execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST) # Convert command output into a CMake list -STRING(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") -STRING(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") +string(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") +string(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}") +list(REMOVE_DUPLICATES CMAKE_PROPERTY_LIST) function(print_properties) message ("CMAKE_PROPERTY_LIST = ${CMAKE_PROPERTY_LIST}") diff --git a/cmake/modules/FindCheck.cmake b/cmake/modules/FindCheck.cmake index 3f60b68..49316e7 100644 --- a/cmake/modules/FindCheck.cmake +++ b/cmake/modules/FindCheck.cmake @@ -5,7 +5,7 @@ # Check_FOUND - True if libcheck is available # Check_LIBRARIES - Found libraries for libcheck # Check_INCLUDE_DIRS - Include directory for libcheck -# Check_DEFINITIONS - Other compiler flags for using libcheck +# Check_CFLAGS - Other compiler flags for using libcheck # Check_VERSION - Version of the found libcheck # # Additionally, the following imported targets will be defined: @@ -16,7 +16,8 @@ include(FindPackageHandleStandardArgs) set(module_name Check) -find_package(PkgConfig QUIET) +# We rely on pkg-config to provide dependency info. +find_package(PkgConfig REQUIRED QUIET) pkg_check_modules(PKG_${module_name} QUIET check) @@ -25,7 +26,7 @@ find_path(${module_name}_INCLUDE_DIR HINTS ${PKG_${module_name}_INCLUDE_DIRS} ) find_library(${module_name}_LIBRARY - NAMES check + NAMES check_pic check HINTS ${PKG_${module_name}_LIBRARY_DIRS} ) @@ -63,15 +64,25 @@ mark_as_advanced( ) if(${module_name}_FOUND) - list(APPEND ${module_name}_LIBRARIES "${${module_name}_LIBRARY}") + list(APPEND ${module_name}_LIBRARIES "${PKG_${module_name}_LIBRARIES}") + list(APPEND ${module_name}_CFLAGS "${PKG_${module_name}_CFLAGS_OTHER}") + list(APPEND ${module_name}_LDFLAGS "${PKG_${module_name}_LDFLAGS_OTHER}") + + message("PKG_${module_name}_LDFLAGS_OTHER = ${PKG_${module_name}_LDFLAGS_OTHER}") + + if("-pthread" IN_LIST ${module_name}_LDFLAGS) + include(CMakeFindDependencyMacro) + find_dependency(Threads REQUIRED) + list(APPEND ${module_name}_LIBRARIES Threads::Threads) + endif() + list(APPEND ${module_name}_INCLUDE_DIRS "${${module_name}_INCLUDE_DIR}") - list(APPEND ${module_name}_DEFINITIONS "${PKG_${module_name}_DEFINITIONS}") if(NOT TARGET check::check) - add_library(check::check UNKNOWN IMPORTED) + add_library(check::check INTERFACE IMPORTED) set_target_properties(check::check PROPERTIES - INTERFACE_COMPILE_OPTIONS "${${module_name}_DEFINITIONS}" - INTERFACE_INCLUDE_DIRECTORIES "${${module_name}_INCLUDE_DIR}" - IMPORTED_LOCATION "${${module_name}_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${${module_name}_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${${module_name}_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${${module_name}_LIBRARIES}" ) endif() endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 842ca42..b6f998b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,7 +15,7 @@ function(libtsm_add_test name) add_executable(${name} ${name}) if(ARG_LINK_LIBRARIES) - target_link_libraries(${name} ${ARG_LINK_LIBRARIES}) + target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBRARIES}) endif() add_test(NAME ${name} COMMAND ${name}) endfunction() From ea8d990fb3b0a682fa9df5e706bd3046f710285b Mon Sep 17 00:00:00 2001 From: Aetf Date: Mon, 8 Oct 2018 15:02:33 -0400 Subject: [PATCH 10/20] build: lower cmake requirement to 3.5 which comes with ubuntu 16.04 LTS Signed-off-by: Aetf --- .travis.yml | 3 --- CMakeLists.txt | 5 +++-- README.md | 38 ++++++++++++++++++++++++++++++++++++++ src/tsm/CMakeLists.txt | 31 +++++++++++++++++++------------ 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2515af8..e64610a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,6 @@ compiler: - gcc - clang -install: - - pip install --user --upgrade cmake - script: - ctest -VV -S ./ci.ctest diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c7d098..7983646 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,15 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.5) project(libtsm LANGUAGES C VERSION 4.0.0 - DESCRIPTION "terminal-emulator state machine" ) # Some meta data ## TODO: merge into project above after we require cmake 3.12 set(PROJECT_HOMEPAGE_URL "https://github.com/Aetf/libtsm") +## TODO: merge into project above after we require cmake 3.10 +set(PROJECT_DESCRIPTION "terminal-emulator state machine") #--------------------------------------------------------------------------------------- # Initial setups diff --git a/README.md b/README.md index 4a4b1db..b2c307e 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,41 @@ This is a personal modified version. For more information, please refer to its o * [Fix invalid cpr values](https://github.com/Aetf/libtsm/pull/2) [91335]: https://bugs.freedesktop.org/show_bug.cgi?id=91335 + +## Build +```bash +mkdir build && cd build +cmake .. +make +make install +``` + +### Build options +Options may be supplied when configuring cmake: +```bash +cmake -DOPTION1=VALUE1 -DOPTION2=VALUE2 .. +``` +The following options are available: + +|Name | Description | Default | +|:---:|:---|:---:| +| BUILD_SHARED_LIBS | Whether to build as a shared library | ON | +| BUILD_TESTING | Whether to build test suits | OFF | +| ENABLE_EXTRA_DEBUG | Whether to enable several non-standard debug options. | OFF | +| BUILD_GTKTSM | Whether to build the gtktsm example. This is linux-only as it uses epoll and friends. Therefore is disabled by default. | OFF | + +### Dependencies + +- [cmake](https://cmake.org) >= 3.5 +- `xkbcommon-keysyms.h` from xkbcommon (Optional. Will use private copy if not found.) + +The test suits needs: + +- [check](https://libcheck.github.io/check/) + +The gtktsm example needs: + +- gtk3 +- cairo +- pango +- xkbcommon diff --git a/src/tsm/CMakeLists.txt b/src/tsm/CMakeLists.txt index 9fed17f..3efbb24 100644 --- a/src/tsm/CMakeLists.txt +++ b/src/tsm/CMakeLists.txt @@ -14,25 +14,32 @@ add_library(tsm_obj OBJECT tsm-vte.c tsm-vte-charsets.c ) -# Link to dependencies -target_link_object_libraries(tsm_obj - PUBLIC - external - shl -) -if(XKBCommon_KeySyms_FOUND) - target_link_libraries(tsm_obj - INTERFACE - XKB::KeySyms - ) -endif() set_target_properties(tsm_obj PROPERTIES POSITION_INDEPENDENT_CODE ON C_VISIBILITY_PRESET hidden ) +# Fix include path for tsm_obj because it can't directly link to +# external and shl. TODO: remove after we require 3.12 +foreach(lib IN ITEMS external shl) + target_include_directories(tsm_obj PRIVATE $) +endforeach() + # Other non-compilation properties shared between tsm and tsm_test function(apply_properties target) + # TODO: set this on tsm_obj after we require 3.12 + # Link to dependencies + target_link_object_libraries(${target} + PRIVATE + external + shl + ) + if(XKBCommon_KeySyms_FOUND) + target_link_libraries(${target} + PRIVATE + XKB::KeySyms + ) + endif() target_include_directories(${target} INTERFACE $ From 77f2324d2d6ecbc985d83dd61aac741b6f12503d Mon Sep 17 00:00:00 2001 From: Aetf Date: Mon, 8 Oct 2018 15:29:14 -0400 Subject: [PATCH 11/20] build: minor tweak to readme and pkgconf file Signed-off-by: Aetf --- README.md | 4 +++- etc/libtsm.pc.in | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b2c307e..1728fc5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # TSM - Terminal Emulator State Machine +[![Build Status](https://travis-ci.com/Aetf/libtsm.svg?branch=develop)](https://travis-ci.com/Aetf/libtsm) + TSM is a state machine for DEC VT100-VT520 compatible terminal emulators. It tries to support all common standards while keeping compatibility to existing -emulators like xterm, gnome-terminal, konsole, .. +emulators like xterm, gnome-terminal, konsole, ... This is a personal modified version. For more information, please refer to its original [README](README). diff --git a/etc/libtsm.pc.in b/etc/libtsm.pc.in index 05cf530..a227718 100644 --- a/etc/libtsm.pc.in +++ b/etc/libtsm.pc.in @@ -1,6 +1,6 @@ prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix}; -libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +exec_prefix=${prefix} +libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ Name: @PROJECT_NAME@ From 3cdace1aaf6b1075f3fa0e1a917b08629101ce31 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 9 Oct 2018 11:08:24 -0400 Subject: [PATCH 12/20] build: rebuild shared library when version script changes Signed-off-by: Aetf --- src/tsm/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tsm/CMakeLists.txt b/src/tsm/CMakeLists.txt index 3efbb24..00f1247 100644 --- a/src/tsm/CMakeLists.txt +++ b/src/tsm/CMakeLists.txt @@ -64,7 +64,11 @@ apply_properties(tsm) # The production library additionally use version script set_property(TARGET tsm APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/libtsm.sym\"" + LINK_FLAGS " -Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/libtsm.sym\"" +) +set_property(TARGET tsm APPEND + PROPERTY + LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/libtsm.sym" ) # Add an alias so that library can be used inside the build tree From 02b473f1993486ff6148dfe44dd263f30d5a7d75 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 9 Oct 2018 11:15:37 -0400 Subject: [PATCH 13/20] vte: add configurable color palette, close #7 Signed-off-by: Aetf --- README.md | 8 +- src/tsm/libtsm.h | 87 ++++++++- src/tsm/libtsm.sym | 5 + src/tsm/tsm-vte.c | 443 ++++++++++++++++++++++--------------------- test/CMakeLists.txt | 6 + test/test_common.h | 2 + test/test_valgrind.c | 2 +- test/test_vte.c | 173 +++++++++++++++++ 8 files changed, 511 insertions(+), 215 deletions(-) create mode 100644 test/test_vte.c diff --git a/README.md b/README.md index 1728fc5..c12098c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,11 @@ emulators like xterm, gnome-terminal, konsole, ... This is a personal modified version. For more information, please refer to its original [README](README). ## Added feature -+ Add soft-black and [base16](https://github.com/chriskempson/base16-default-schemes)-light and -dark color palettes ++ More color palettes: + * soft-black + * [base16](https://github.com/chriskempson/base16-default-schemes){-light,-dark} + * solarized{,-black,-white} + * custom: set via API + Support underline/italic rendering (with [a patched version of kmscon](https://github.com/Aetf/kmscon)) + Support 24-bit true color + Support Ctrl + Arrow keys @@ -49,7 +53,7 @@ The following options are available: The test suits needs: -- [check](https://libcheck.github.io/check/) +- [check](https://libcheck.github.io/check/) >= 0.9.10 The gtktsm example needs: diff --git a/src/tsm/libtsm.h b/src/tsm/libtsm.h index 1a06e6d..4c5b64d 100644 --- a/src/tsm/libtsm.h +++ b/src/tsm/libtsm.h @@ -1,6 +1,7 @@ /* * TSM - Main Header * + * Copyright (c) 2018 Aetf * Copyright (c) 2011-2013 David Herrmann * * Permission is hereby granted, free of charge, to any person obtaining @@ -30,6 +31,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -294,6 +296,30 @@ enum tsm_vte_modifier { /* keep in sync with TSM_INPUT_INVALID */ #define TSM_VTE_INVALID 0xffffffff +enum tsm_vte_color { + TSM_COLOR_BLACK, + TSM_COLOR_RED, + TSM_COLOR_GREEN, + TSM_COLOR_YELLOW, + TSM_COLOR_BLUE, + TSM_COLOR_MAGENTA, + TSM_COLOR_CYAN, + TSM_COLOR_LIGHT_GREY, + TSM_COLOR_DARK_GREY, + TSM_COLOR_LIGHT_RED, + TSM_COLOR_LIGHT_GREEN, + TSM_COLOR_LIGHT_YELLOW, + TSM_COLOR_LIGHT_BLUE, + TSM_COLOR_LIGHT_MAGENTA, + TSM_COLOR_LIGHT_CYAN, + TSM_COLOR_WHITE, + + TSM_COLOR_FOREGROUND, + TSM_COLOR_BACKGROUND, + + TSM_COLOR_NUM +}; + typedef void (*tsm_vte_write_cb) (struct tsm_vte *vte, const char *u8, size_t len, @@ -312,7 +338,66 @@ void tsm_vte_unref(struct tsm_vte *vte); void tsm_vte_set_osc_cb(struct tsm_vte *vte, tsm_vte_osc_cb osc_cb, void *osc_data); -int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette); +/** + * @brief Set color palette to one of the predefined palette on the vte object. + * + * Current supported palette names are + * + * - solarized + * - solarized-black + * - solarized-white + * - soft-black + * - base16-dark + * - base16-light + * + * In addition, when palette name is "custom", the custom palette set in + * @link tsm_vte_set_custom_palette is used. + * + * @sa tsm_vte_set_custom_palette to set custom palette. + * + * @param vte The vte object to set on + * @param palette_name Name of the color palette. Pass NULL to reset to default. + * @return 0 on success. -EINVAL if vte is NULL. -ENOMEM if malloc fails. + */ +int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette_name); + +/** + * @brief Set a custom palette on the vte object. + * + * An example: + * + * @code + * static uint8_t color_palette[TSM_COLOR_NUM][3] = { + * [TSM_COLOR_BLACK] = { 0x00, 0x00, 0x00 }, + * [TSM_COLOR_RED] = { 0xab, 0x46, 0x42 }, + * [TSM_COLOR_GREEN] = { 0xa1, 0xb5, 0x6c }, + * [TSM_COLOR_YELLOW] = { 0xf7, 0xca, 0x88 }, + * [TSM_COLOR_BLUE] = { 0x7c, 0xaf, 0xc2 }, + * [TSM_COLOR_MAGENTA] = { 0xba, 0x8b, 0xaf }, + * [TSM_COLOR_CYAN] = { 0x86, 0xc1, 0xb9 }, + * [TSM_COLOR_LIGHT_GREY] = { 0xaa, 0xaa, 0xaa }, + * [TSM_COLOR_DARK_GREY] = { 0x55, 0x55, 0x55 }, + * [TSM_COLOR_LIGHT_RED] = { 0xab, 0x46, 0x42 }, + * [TSM_COLOR_LIGHT_GREEN] = { 0xa1, 0xb5, 0x6c }, + * [TSM_COLOR_LIGHT_YELLOW] = { 0xf7, 0xca, 0x88 }, + * [TSM_COLOR_LIGHT_BLUE] = { 0x7c, 0xaf, 0xc2 }, + * [TSM_COLOR_LIGHT_MAGENTA] = { 0xba, 0x8b, 0xaf }, + * [TSM_COLOR_LIGHT_CYAN] = { 0x86, 0xc1, 0xb9 }, + * [TSM_COLOR_WHITE] = { 0xff, 0xff, 0xff }, + * + * [TSM_COLOR_FOREGROUND] = { 0x18, 0x18, 0x18 }, + * [TSM_COLOR_BACKGROUND] = { 0xd8, 0xd8, 0xd8 }, + * }; + * @endcode + * + * The palette array is copied into the vte object. + * + * @param vte The vte object to set on + * @param palette The palette array, which should has shape uint8_t palette[TSM_COLOR_NUM][3]. + * @return 0 on success. -EINVAL if vte is NULL. -ENOMEM if malloc fails. + */ +int tsm_vte_set_custom_palette(struct tsm_vte *vte, uint8_t (*palette)[3]); + void tsm_vte_get_def_attr(struct tsm_vte *vte, struct tsm_screen_attr *out); void tsm_vte_reset(struct tsm_vte *vte); diff --git a/src/tsm/libtsm.sym b/src/tsm/libtsm.sym index d60dc33..644ccf5 100644 --- a/src/tsm/libtsm.sym +++ b/src/tsm/libtsm.sym @@ -115,3 +115,8 @@ global: tsm_vte_input; tsm_vte_handle_keyboard; } LIBTSM_2; + +LIBTSM_4 { +global: + tsm_vte_set_custom_palette; +} LIBTSM_3; diff --git a/src/tsm/tsm-vte.c b/src/tsm/tsm-vte.c index 6a0ba49..dba86ea 100644 --- a/src/tsm/tsm-vte.c +++ b/src/tsm/tsm-vte.c @@ -1,6 +1,7 @@ /* * libtsm - VT Emulator * + * Copyright (c) 2018 Aetf * Copyright (c) 2011-2013 David Herrmann * * Permission is hereby granted, free of charge, to any person obtaining @@ -168,6 +169,7 @@ struct tsm_vte { unsigned int osc_len; char osc_arg[OSC_MAX_LEN]; + uint8_t (*custom_palette_storage)[3]; uint8_t (*palette)[3]; struct tsm_screen_attr def_attr; struct tsm_screen_attr cattr; @@ -187,180 +189,158 @@ struct tsm_vte { unsigned int alt_cursor_y; }; -enum vte_color { - COLOR_BLACK, - COLOR_RED, - COLOR_GREEN, - COLOR_YELLOW, - COLOR_BLUE, - COLOR_MAGENTA, - COLOR_CYAN, - COLOR_LIGHT_GREY, - COLOR_DARK_GREY, - COLOR_LIGHT_RED, - COLOR_LIGHT_GREEN, - COLOR_LIGHT_YELLOW, - COLOR_LIGHT_BLUE, - COLOR_LIGHT_MAGENTA, - COLOR_LIGHT_CYAN, - COLOR_WHITE, - COLOR_FOREGROUND, - COLOR_BACKGROUND, - COLOR_NUM +static uint8_t color_palette[TSM_COLOR_NUM][3] = { + [TSM_COLOR_BLACK] = { 0, 0, 0 }, /* black */ + [TSM_COLOR_RED] = { 205, 0, 0 }, /* red */ + [TSM_COLOR_GREEN] = { 0, 205, 0 }, /* green */ + [TSM_COLOR_YELLOW] = { 205, 205, 0 }, /* yellow */ + [TSM_COLOR_BLUE] = { 0, 0, 238 }, /* blue */ + [TSM_COLOR_MAGENTA] = { 205, 0, 205 }, /* magenta */ + [TSM_COLOR_CYAN] = { 0, 205, 205 }, /* cyan */ + [TSM_COLOR_LIGHT_GREY] = { 229, 229, 229 }, /* light grey */ + [TSM_COLOR_DARK_GREY] = { 127, 127, 127 }, /* dark grey */ + [TSM_COLOR_LIGHT_RED] = { 255, 0, 0 }, /* light red */ + [TSM_COLOR_LIGHT_GREEN] = { 0, 255, 0 }, /* light green */ + [TSM_COLOR_LIGHT_YELLOW] = { 255, 255, 0 }, /* light yellow */ + [TSM_COLOR_LIGHT_BLUE] = { 92, 92, 255 }, /* light blue */ + [TSM_COLOR_LIGHT_MAGENTA] = { 255, 0, 255 }, /* light magenta */ + [TSM_COLOR_LIGHT_CYAN] = { 0, 255, 255 }, /* light cyan */ + [TSM_COLOR_WHITE] = { 255, 255, 255 }, /* white */ + + [TSM_COLOR_FOREGROUND] = { 229, 229, 229 }, /* light grey */ + [TSM_COLOR_BACKGROUND] = { 0, 0, 0 }, /* black */ }; -static uint8_t color_palette[COLOR_NUM][3] = { - [COLOR_BLACK] = { 0, 0, 0 }, /* black */ - [COLOR_RED] = { 205, 0, 0 }, /* red */ - [COLOR_GREEN] = { 0, 205, 0 }, /* green */ - [COLOR_YELLOW] = { 205, 205, 0 }, /* yellow */ - [COLOR_BLUE] = { 0, 0, 238 }, /* blue */ - [COLOR_MAGENTA] = { 205, 0, 205 }, /* magenta */ - [COLOR_CYAN] = { 0, 205, 205 }, /* cyan */ - [COLOR_LIGHT_GREY] = { 229, 229, 229 }, /* light grey */ - [COLOR_DARK_GREY] = { 127, 127, 127 }, /* dark grey */ - [COLOR_LIGHT_RED] = { 255, 0, 0 }, /* light red */ - [COLOR_LIGHT_GREEN] = { 0, 255, 0 }, /* light green */ - [COLOR_LIGHT_YELLOW] = { 255, 255, 0 }, /* light yellow */ - [COLOR_LIGHT_BLUE] = { 92, 92, 255 }, /* light blue */ - [COLOR_LIGHT_MAGENTA] = { 255, 0, 255 }, /* light magenta */ - [COLOR_LIGHT_CYAN] = { 0, 255, 255 }, /* light cyan */ - [COLOR_WHITE] = { 255, 255, 255 }, /* white */ - - [COLOR_FOREGROUND] = { 229, 229, 229 }, /* light grey */ - [COLOR_BACKGROUND] = { 0, 0, 0 }, /* black */ +static uint8_t color_palette_solarized[TSM_COLOR_NUM][3] = { + [TSM_COLOR_BLACK] = { 7, 54, 66 }, /* black */ + [TSM_COLOR_RED] = { 220, 50, 47 }, /* red */ + [TSM_COLOR_GREEN] = { 133, 153, 0 }, /* green */ + [TSM_COLOR_YELLOW] = { 181, 137, 0 }, /* yellow */ + [TSM_COLOR_BLUE] = { 38, 139, 210 }, /* blue */ + [TSM_COLOR_MAGENTA] = { 211, 54, 130 }, /* magenta */ + [TSM_COLOR_CYAN] = { 42, 161, 152 }, /* cyan */ + [TSM_COLOR_LIGHT_GREY] = { 238, 232, 213 }, /* light grey */ + [TSM_COLOR_DARK_GREY] = { 0, 43, 54 }, /* dark grey */ + [TSM_COLOR_LIGHT_RED] = { 203, 75, 22 }, /* light red */ + [TSM_COLOR_LIGHT_GREEN] = { 88, 110, 117 }, /* light green */ + [TSM_COLOR_LIGHT_YELLOW] = { 101, 123, 131 }, /* light yellow */ + [TSM_COLOR_LIGHT_BLUE] = { 131, 148, 150 }, /* light blue */ + [TSM_COLOR_LIGHT_MAGENTA] = { 108, 113, 196 }, /* light magenta */ + [TSM_COLOR_LIGHT_CYAN] = { 147, 161, 161 }, /* light cyan */ + [TSM_COLOR_WHITE] = { 253, 246, 227 }, /* white */ + + [TSM_COLOR_FOREGROUND] = { 238, 232, 213 }, /* light grey */ + [TSM_COLOR_BACKGROUND] = { 7, 54, 66 }, /* black */ }; -static uint8_t color_palette_solarized[COLOR_NUM][3] = { - [COLOR_BLACK] = { 7, 54, 66 }, /* black */ - [COLOR_RED] = { 220, 50, 47 }, /* red */ - [COLOR_GREEN] = { 133, 153, 0 }, /* green */ - [COLOR_YELLOW] = { 181, 137, 0 }, /* yellow */ - [COLOR_BLUE] = { 38, 139, 210 }, /* blue */ - [COLOR_MAGENTA] = { 211, 54, 130 }, /* magenta */ - [COLOR_CYAN] = { 42, 161, 152 }, /* cyan */ - [COLOR_LIGHT_GREY] = { 238, 232, 213 }, /* light grey */ - [COLOR_DARK_GREY] = { 0, 43, 54 }, /* dark grey */ - [COLOR_LIGHT_RED] = { 203, 75, 22 }, /* light red */ - [COLOR_LIGHT_GREEN] = { 88, 110, 117 }, /* light green */ - [COLOR_LIGHT_YELLOW] = { 101, 123, 131 }, /* light yellow */ - [COLOR_LIGHT_BLUE] = { 131, 148, 150 }, /* light blue */ - [COLOR_LIGHT_MAGENTA] = { 108, 113, 196 }, /* light magenta */ - [COLOR_LIGHT_CYAN] = { 147, 161, 161 }, /* light cyan */ - [COLOR_WHITE] = { 253, 246, 227 }, /* white */ - - [COLOR_FOREGROUND] = { 238, 232, 213 }, /* light grey */ - [COLOR_BACKGROUND] = { 7, 54, 66 }, /* black */ +static uint8_t color_palette_solarized_black[TSM_COLOR_NUM][3] = { + [TSM_COLOR_BLACK] = { 0, 0, 0 }, /* black */ + [TSM_COLOR_RED] = { 220, 50, 47 }, /* red */ + [TSM_COLOR_GREEN] = { 133, 153, 0 }, /* green */ + [TSM_COLOR_YELLOW] = { 181, 137, 0 }, /* yellow */ + [TSM_COLOR_BLUE] = { 38, 139, 210 }, /* blue */ + [TSM_COLOR_MAGENTA] = { 211, 54, 130 }, /* magenta */ + [TSM_COLOR_CYAN] = { 42, 161, 152 }, /* cyan */ + [TSM_COLOR_LIGHT_GREY] = { 238, 232, 213 }, /* light grey */ + [TSM_COLOR_DARK_GREY] = { 0, 43, 54 }, /* dark grey */ + [TSM_COLOR_LIGHT_RED] = { 203, 75, 22 }, /* light red */ + [TSM_COLOR_LIGHT_GREEN] = { 88, 110, 117 }, /* light green */ + [TSM_COLOR_LIGHT_YELLOW] = { 101, 123, 131 }, /* light yellow */ + [TSM_COLOR_LIGHT_BLUE] = { 131, 148, 150 }, /* light blue */ + [TSM_COLOR_LIGHT_MAGENTA] = { 108, 113, 196 }, /* light magenta */ + [TSM_COLOR_LIGHT_CYAN] = { 147, 161, 161 }, /* light cyan */ + [TSM_COLOR_WHITE] = { 253, 246, 227 }, /* white */ + + [TSM_COLOR_FOREGROUND] = { 238, 232, 213 }, /* light grey */ + [TSM_COLOR_BACKGROUND] = { 0, 0, 0 }, /* black */ }; -static uint8_t color_palette_solarized_black[COLOR_NUM][3] = { - [COLOR_BLACK] = { 0, 0, 0 }, /* black */ - [COLOR_RED] = { 220, 50, 47 }, /* red */ - [COLOR_GREEN] = { 133, 153, 0 }, /* green */ - [COLOR_YELLOW] = { 181, 137, 0 }, /* yellow */ - [COLOR_BLUE] = { 38, 139, 210 }, /* blue */ - [COLOR_MAGENTA] = { 211, 54, 130 }, /* magenta */ - [COLOR_CYAN] = { 42, 161, 152 }, /* cyan */ - [COLOR_LIGHT_GREY] = { 238, 232, 213 }, /* light grey */ - [COLOR_DARK_GREY] = { 0, 43, 54 }, /* dark grey */ - [COLOR_LIGHT_RED] = { 203, 75, 22 }, /* light red */ - [COLOR_LIGHT_GREEN] = { 88, 110, 117 }, /* light green */ - [COLOR_LIGHT_YELLOW] = { 101, 123, 131 }, /* light yellow */ - [COLOR_LIGHT_BLUE] = { 131, 148, 150 }, /* light blue */ - [COLOR_LIGHT_MAGENTA] = { 108, 113, 196 }, /* light magenta */ - [COLOR_LIGHT_CYAN] = { 147, 161, 161 }, /* light cyan */ - [COLOR_WHITE] = { 253, 246, 227 }, /* white */ - - [COLOR_FOREGROUND] = { 238, 232, 213 }, /* light grey */ - [COLOR_BACKGROUND] = { 0, 0, 0 }, /* black */ +static uint8_t color_palette_solarized_white[TSM_COLOR_NUM][3] = { + [TSM_COLOR_BLACK] = { 7, 54, 66 }, /* black */ + [TSM_COLOR_RED] = { 220, 50, 47 }, /* red */ + [TSM_COLOR_GREEN] = { 133, 153, 0 }, /* green */ + [TSM_COLOR_YELLOW] = { 181, 137, 0 }, /* yellow */ + [TSM_COLOR_BLUE] = { 38, 139, 210 }, /* blue */ + [TSM_COLOR_MAGENTA] = { 211, 54, 130 }, /* magenta */ + [TSM_COLOR_CYAN] = { 42, 161, 152 }, /* cyan */ + [TSM_COLOR_LIGHT_GREY] = { 238, 232, 213 }, /* light grey */ + [TSM_COLOR_DARK_GREY] = { 0, 43, 54 }, /* dark grey */ + [TSM_COLOR_LIGHT_RED] = { 203, 75, 22 }, /* light red */ + [TSM_COLOR_LIGHT_GREEN] = { 88, 110, 117 }, /* light green */ + [TSM_COLOR_LIGHT_YELLOW] = { 101, 123, 131 }, /* light yellow */ + [TSM_COLOR_LIGHT_BLUE] = { 131, 148, 150 }, /* light blue */ + [TSM_COLOR_LIGHT_MAGENTA] = { 108, 113, 196 }, /* light magenta */ + [TSM_COLOR_LIGHT_CYAN] = { 147, 161, 161 }, /* light cyan */ + [TSM_COLOR_WHITE] = { 253, 246, 227 }, /* white */ + + [TSM_COLOR_FOREGROUND] = { 7, 54, 66 }, /* black */ + [TSM_COLOR_BACKGROUND] = { 238, 232, 213 }, /* light grey */ }; -static uint8_t color_palette_solarized_white[COLOR_NUM][3] = { - [COLOR_BLACK] = { 7, 54, 66 }, /* black */ - [COLOR_RED] = { 220, 50, 47 }, /* red */ - [COLOR_GREEN] = { 133, 153, 0 }, /* green */ - [COLOR_YELLOW] = { 181, 137, 0 }, /* yellow */ - [COLOR_BLUE] = { 38, 139, 210 }, /* blue */ - [COLOR_MAGENTA] = { 211, 54, 130 }, /* magenta */ - [COLOR_CYAN] = { 42, 161, 152 }, /* cyan */ - [COLOR_LIGHT_GREY] = { 238, 232, 213 }, /* light grey */ - [COLOR_DARK_GREY] = { 0, 43, 54 }, /* dark grey */ - [COLOR_LIGHT_RED] = { 203, 75, 22 }, /* light red */ - [COLOR_LIGHT_GREEN] = { 88, 110, 117 }, /* light green */ - [COLOR_LIGHT_YELLOW] = { 101, 123, 131 }, /* light yellow */ - [COLOR_LIGHT_BLUE] = { 131, 148, 150 }, /* light blue */ - [COLOR_LIGHT_MAGENTA] = { 108, 113, 196 }, /* light magenta */ - [COLOR_LIGHT_CYAN] = { 147, 161, 161 }, /* light cyan */ - [COLOR_WHITE] = { 253, 246, 227 }, /* white */ - - [COLOR_FOREGROUND] = { 7, 54, 66 }, /* black */ - [COLOR_BACKGROUND] = { 238, 232, 213 }, /* light grey */ +static uint8_t color_palette_soft_black[TSM_COLOR_NUM][3] = { + [TSM_COLOR_BLACK] = { 0x3f, 0x3f, 0x3f }, /* black */ + [TSM_COLOR_RED] = { 0x70, 0x50, 0x50 }, /* red */ + [TSM_COLOR_GREEN] = { 0x60, 0xb4, 0x8a }, /* green */ + [TSM_COLOR_YELLOW] = { 0xdf, 0xaf, 0x8f }, /* yellow */ + [TSM_COLOR_BLUE] = { 0x9a, 0xb8, 0xd7 }, /* blue */ + [TSM_COLOR_MAGENTA] = { 0xdc, 0x8c, 0xc3 }, /* magenta */ + [TSM_COLOR_CYAN] = { 0x8c, 0xd0, 0xd3 }, /* cyan */ + [TSM_COLOR_LIGHT_GREY] = { 0xff, 0xff, 0xff }, /* light grey */ + [TSM_COLOR_DARK_GREY] = { 0x70, 0x90, 0x80 }, /* dark grey */ + [TSM_COLOR_LIGHT_RED] = { 0xdc, 0xa3, 0xa3 }, /* light red */ + [TSM_COLOR_LIGHT_GREEN] = { 0x72, 0xd5, 0xa3 }, /* light green */ + [TSM_COLOR_LIGHT_YELLOW] = { 0xf0, 0xdf, 0xaf }, /* light yellow */ + [TSM_COLOR_LIGHT_BLUE] = { 0x94, 0xbf, 0xf3 }, /* light blue */ + [TSM_COLOR_LIGHT_MAGENTA] = { 0xec, 0x93, 0xd3 }, /* light magenta */ + [TSM_COLOR_LIGHT_CYAN] = { 0x93, 0xe0, 0xe3 }, /* light cyan */ + [TSM_COLOR_WHITE] = { 0xdc, 0xdc, 0xcc }, /* white */ + + [TSM_COLOR_FOREGROUND] = { 0xdc, 0xdc, 0xcc }, /* white */ + [TSM_COLOR_BACKGROUND] = { 0x2c, 0x2c, 0x2c }, /* light grey */ }; -static uint8_t color_palette_soft_black[COLOR_NUM][3] = { - [COLOR_BLACK] = { 0x3f, 0x3f, 0x3f }, /* black */ - [COLOR_RED] = { 0x70, 0x50, 0x50 }, /* red */ - [COLOR_GREEN] = { 0x60, 0xb4, 0x8a }, /* green */ - [COLOR_YELLOW] = { 0xdf, 0xaf, 0x8f }, /* yellow */ - [COLOR_BLUE] = { 0x9a, 0xb8, 0xd7 }, /* blue */ - [COLOR_MAGENTA] = { 0xdc, 0x8c, 0xc3 }, /* magenta */ - [COLOR_CYAN] = { 0x8c, 0xd0, 0xd3 }, /* cyan */ - [COLOR_LIGHT_GREY] = { 0xff, 0xff, 0xff }, /* light grey */ - [COLOR_DARK_GREY] = { 0x70, 0x90, 0x80 }, /* dark grey */ - [COLOR_LIGHT_RED] = { 0xdc, 0xa3, 0xa3 }, /* light red */ - [COLOR_LIGHT_GREEN] = { 0x72, 0xd5, 0xa3 }, /* light green */ - [COLOR_LIGHT_YELLOW] = { 0xf0, 0xdf, 0xaf }, /* light yellow */ - [COLOR_LIGHT_BLUE] = { 0x94, 0xbf, 0xf3 }, /* light blue */ - [COLOR_LIGHT_MAGENTA] = { 0xec, 0x93, 0xd3 }, /* light magenta */ - [COLOR_LIGHT_CYAN] = { 0x93, 0xe0, 0xe3 }, /* light cyan */ - [COLOR_WHITE] = { 0xdc, 0xdc, 0xcc }, /* white */ - - [COLOR_FOREGROUND] = { 0xdc, 0xdc, 0xcc }, /* white */ - [COLOR_BACKGROUND] = { 0x2c, 0x2c, 0x2c }, /* light grey */ +static uint8_t color_palette_base16_dark[TSM_COLOR_NUM][3] = { + [TSM_COLOR_BLACK] = { 0x00, 0x00, 0x00 }, /* black */ + [TSM_COLOR_RED] = { 0xab, 0x46, 0x42 }, /* red, base08 */ + [TSM_COLOR_GREEN] = { 0xa1, 0xb5, 0x6c }, /* green, base0B */ + [TSM_COLOR_YELLOW] = { 0xf7, 0xca, 0x88 }, /* yellow, base0A */ + [TSM_COLOR_BLUE] = { 0x7c, 0xaf, 0xc2 }, /* blue, base0D */ + [TSM_COLOR_MAGENTA] = { 0xba, 0x8b, 0xaf }, /* magenta, base0E */ + [TSM_COLOR_CYAN] = { 0x86, 0xc1, 0xb9 }, /* cyan, base0C */ + [TSM_COLOR_LIGHT_GREY] = { 0xaa, 0xaa, 0xaa }, /* light grey */ + [TSM_COLOR_DARK_GREY] = { 0x55, 0x55, 0x55 }, /* dark grey */ + [TSM_COLOR_LIGHT_RED] = { 0xab, 0x46, 0x42 }, /* red, base08 */ + [TSM_COLOR_LIGHT_GREEN] = { 0xa1, 0xb5, 0x6c }, /* green, base0B */ + [TSM_COLOR_LIGHT_YELLOW] = { 0xf7, 0xca, 0x88 }, /* yellow, base0A */ + [TSM_COLOR_LIGHT_BLUE] = { 0x7c, 0xaf, 0xc2 }, /* blue, base0D */ + [TSM_COLOR_LIGHT_MAGENTA] = { 0xba, 0x8b, 0xaf }, /* magenta, base0E */ + [TSM_COLOR_LIGHT_CYAN] = { 0x86, 0xc1, 0xb9 }, /* cyan, base0C */ + [TSM_COLOR_WHITE] = { 0xff, 0xff, 0xff }, /* white */ + + [TSM_COLOR_FOREGROUND] = { 0xd8, 0xd8, 0xd8 }, /* light grey */ + [TSM_COLOR_BACKGROUND] = { 0x18, 0x18, 0x18 }, /* dark grey */ }; -static uint8_t color_palette_base16_dark[COLOR_NUM][3] = { - [COLOR_BLACK] = { 0x00, 0x00, 0x00 }, /* black */ - [COLOR_RED] = { 0xab, 0x46, 0x42 }, /* red, base08 */ - [COLOR_GREEN] = { 0xa1, 0xb5, 0x6c }, /* green, base0B */ - [COLOR_YELLOW] = { 0xf7, 0xca, 0x88 }, /* yellow, base0A */ - [COLOR_BLUE] = { 0x7c, 0xaf, 0xc2 }, /* blue, base0D */ - [COLOR_MAGENTA] = { 0xba, 0x8b, 0xaf }, /* magenta, base0E */ - [COLOR_CYAN] = { 0x86, 0xc1, 0xb9 }, /* cyan, base0C */ - [COLOR_LIGHT_GREY] = { 0xaa, 0xaa, 0xaa }, /* light grey */ - [COLOR_DARK_GREY] = { 0x55, 0x55, 0x55 }, /* dark grey */ - [COLOR_LIGHT_RED] = { 0xab, 0x46, 0x42 }, /* red, base08 */ - [COLOR_LIGHT_GREEN] = { 0xa1, 0xb5, 0x6c }, /* green, base0B */ - [COLOR_LIGHT_YELLOW] = { 0xf7, 0xca, 0x88 }, /* yellow, base0A */ - [COLOR_LIGHT_BLUE] = { 0x7c, 0xaf, 0xc2 }, /* blue, base0D */ - [COLOR_LIGHT_MAGENTA] = { 0xba, 0x8b, 0xaf }, /* magenta, base0E */ - [COLOR_LIGHT_CYAN] = { 0x86, 0xc1, 0xb9 }, /* cyan, base0C */ - [COLOR_WHITE] = { 0xff, 0xff, 0xff }, /* white */ - - [COLOR_FOREGROUND] = { 0xd8, 0xd8, 0xd8 }, /* light grey */ - [COLOR_BACKGROUND] = { 0x18, 0x18, 0x18 }, /* dark grey */ -}; - -static uint8_t color_palette_base16_light[COLOR_NUM][3] = { - [COLOR_BLACK] = { 0x00, 0x00, 0x00 }, /* black */ - [COLOR_RED] = { 0xab, 0x46, 0x42 }, /* red, base08 */ - [COLOR_GREEN] = { 0xa1, 0xb5, 0x6c }, /* green, base0B */ - [COLOR_YELLOW] = { 0xf7, 0xca, 0x88 }, /* yellow, base0A */ - [COLOR_BLUE] = { 0x7c, 0xaf, 0xc2 }, /* blue, base0D */ - [COLOR_MAGENTA] = { 0xba, 0x8b, 0xaf }, /* magenta, base0E */ - [COLOR_CYAN] = { 0x86, 0xc1, 0xb9 }, /* cyan, base0C */ - [COLOR_LIGHT_GREY] = { 0xaa, 0xaa, 0xaa }, /* light grey */ - [COLOR_DARK_GREY] = { 0x55, 0x55, 0x55 }, /* dark grey */ - [COLOR_LIGHT_RED] = { 0xab, 0x46, 0x42 }, /* red, base08 */ - [COLOR_LIGHT_GREEN] = { 0xa1, 0xb5, 0x6c }, /* green, base0B */ - [COLOR_LIGHT_YELLOW] = { 0xf7, 0xca, 0x88 }, /* yellow, base0A */ - [COLOR_LIGHT_BLUE] = { 0x7c, 0xaf, 0xc2 }, /* blue, base0D */ - [COLOR_LIGHT_MAGENTA] = { 0xba, 0x8b, 0xaf }, /* magenta, base0E */ - [COLOR_LIGHT_CYAN] = { 0x86, 0xc1, 0xb9 }, /* cyan, base0C */ - [COLOR_WHITE] = { 0xff, 0xff, 0xff }, /* white */ - - [COLOR_FOREGROUND] = { 0x18, 0x18, 0x18 }, /* dark grey */ - [COLOR_BACKGROUND] = { 0xd8, 0xd8, 0xd8 }, /* light grey */ +static uint8_t color_palette_base16_light[TSM_COLOR_NUM][3] = { + [TSM_COLOR_BLACK] = { 0x00, 0x00, 0x00 }, /* black */ + [TSM_COLOR_RED] = { 0xab, 0x46, 0x42 }, /* red, base08 */ + [TSM_COLOR_GREEN] = { 0xa1, 0xb5, 0x6c }, /* green, base0B */ + [TSM_COLOR_YELLOW] = { 0xf7, 0xca, 0x88 }, /* yellow, base0A */ + [TSM_COLOR_BLUE] = { 0x7c, 0xaf, 0xc2 }, /* blue, base0D */ + [TSM_COLOR_MAGENTA] = { 0xba, 0x8b, 0xaf }, /* magenta, base0E */ + [TSM_COLOR_CYAN] = { 0x86, 0xc1, 0xb9 }, /* cyan, base0C */ + [TSM_COLOR_LIGHT_GREY] = { 0xaa, 0xaa, 0xaa }, /* light grey */ + [TSM_COLOR_DARK_GREY] = { 0x55, 0x55, 0x55 }, /* dark grey */ + [TSM_COLOR_LIGHT_RED] = { 0xab, 0x46, 0x42 }, /* red, base08 */ + [TSM_COLOR_LIGHT_GREEN] = { 0xa1, 0xb5, 0x6c }, /* green, base0B */ + [TSM_COLOR_LIGHT_YELLOW] = { 0xf7, 0xca, 0x88 }, /* yellow, base0A */ + [TSM_COLOR_LIGHT_BLUE] = { 0x7c, 0xaf, 0xc2 }, /* blue, base0D */ + [TSM_COLOR_LIGHT_MAGENTA] = { 0xba, 0x8b, 0xaf }, /* magenta, base0E */ + [TSM_COLOR_LIGHT_CYAN] = { 0x86, 0xc1, 0xb9 }, /* cyan, base0C */ + [TSM_COLOR_WHITE] = { 0xff, 0xff, 0xff }, /* white */ + + [TSM_COLOR_FOREGROUND] = { 0x18, 0x18, 0x18 }, /* dark grey */ + [TSM_COLOR_BACKGROUND] = { 0xd8, 0xd8, 0xd8 }, /* light grey */ }; static uint8_t (*get_palette(struct tsm_vte *vte))[3] @@ -368,6 +348,8 @@ static uint8_t (*get_palette(struct tsm_vte *vte))[3] if (!vte->palette_name) return color_palette; + if (!strcmp(vte->palette_name, "custom") && vte->custom_palette_storage) + return vte->custom_palette_storage; if (!strcmp(vte->palette_name, "solarized")) return color_palette_solarized; if (!strcmp(vte->palette_name, "solarized-black")) @@ -401,8 +383,8 @@ static void to_rgb(struct tsm_vte *vte, struct tsm_screen_attr *attr) /* bold causes light colors */ if (attr->bold && code < 8) code += 8; - if (code >= COLOR_NUM) - code = COLOR_FOREGROUND; + if (code >= TSM_COLOR_NUM) + code = TSM_COLOR_FOREGROUND; attr->fr = vte->palette[code][0]; attr->fg = vte->palette[code][1]; @@ -411,8 +393,8 @@ static void to_rgb(struct tsm_vte *vte, struct tsm_screen_attr *attr) code = attr->bccode; if (code >= 0) { - if (code >= COLOR_NUM) - code = COLOR_BACKGROUND; + if (code >= TSM_COLOR_NUM) + code = TSM_COLOR_BACKGROUND; attr->br = vte->palette[code][0]; attr->bg = vte->palette[code][1]; @@ -462,9 +444,10 @@ int tsm_vte_new(struct tsm_vte **out, struct tsm_screen *con, vte->data = data; vte->osc_cb = NULL; vte->osc_data = NULL; + vte->custom_palette_storage = NULL; vte->palette = get_palette(vte); - vte->def_attr.fccode = COLOR_FOREGROUND; - vte->def_attr.bccode = COLOR_BACKGROUND; + vte->def_attr.fccode = TSM_COLOR_FOREGROUND; + vte->def_attr.bccode = TSM_COLOR_BACKGROUND; to_rgb(vte, &vte->def_attr); ret = tsm_utf8_mach_new(&vte->mach); @@ -506,26 +489,45 @@ void tsm_vte_unref(struct tsm_vte *vte) free(vte->palette_name); tsm_screen_unref(vte->con); tsm_utf8_mach_free(vte->mach); + free(vte->custom_palette_storage); free(vte); } SHL_EXPORT void tsm_vte_set_osc_cb(struct tsm_vte *vte, tsm_vte_osc_cb osc_cb, void *osc_data) { + if (!vte) + return; + vte->osc_cb = osc_cb; vte->osc_data = osc_data; } +static int vte_update_palette(struct tsm_vte *vte) +{ + vte->palette = get_palette(vte); + vte->def_attr.fccode = TSM_COLOR_FOREGROUND; + vte->def_attr.bccode = TSM_COLOR_BACKGROUND; + + to_rgb(vte, &vte->def_attr); + memcpy(&vte->cattr, &vte->def_attr, sizeof(vte->cattr)); + + tsm_screen_set_def_attr(vte->con, &vte->def_attr); + tsm_screen_erase_screen(vte->con, false); + + return 0; +} + SHL_EXPORT -int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette) +int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette_name) { char *tmp = NULL; if (!vte) return -EINVAL; - if (palette) { - tmp = strdup(palette); + if (palette_name) { + tmp = strdup(palette_name); if (!tmp) return -ENOMEM; } @@ -533,17 +535,29 @@ int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette) free(vte->palette_name); vte->palette_name = tmp; - vte->palette = get_palette(vte); - vte->def_attr.fccode = COLOR_FOREGROUND; - vte->def_attr.bccode = COLOR_BACKGROUND; + return vte_update_palette(vte); +} - to_rgb(vte, &vte->def_attr); - memcpy(&vte->cattr, &vte->def_attr, sizeof(vte->cattr)); +SHL_EXPORT +int tsm_vte_set_custom_palette(struct tsm_vte *vte, uint8_t (*palette)[3]) +{ + const size_t palette_byte_size = sizeof(color_palette); + uint8_t (*tmp)[3] = NULL; - tsm_screen_set_def_attr(vte->con, &vte->def_attr); - tsm_screen_erase_screen(vte->con, false); + if (!vte) + return -EINVAL; - return 0; + if (palette) { + tmp = malloc(palette_byte_size); + if (!tmp) + return -ENOMEM; + memcpy(tmp, palette, palette_byte_size); + } + + free(vte->custom_palette_storage); + vte->custom_palette_storage = tmp; + + return vte_update_palette(vte); } SHL_EXPORT @@ -730,6 +744,9 @@ void tsm_vte_reset(struct tsm_vte *vte) SHL_EXPORT void tsm_vte_hard_reset(struct tsm_vte *vte) { + if (!vte) + return; + tsm_vte_reset(vte); tsm_screen_erase_screen(vte->con, false); tsm_screen_clear_sb(vte->con); @@ -1175,106 +1192,106 @@ static void csi_attribute(struct tsm_vte *vte) vte->cattr.inverse = 0; break; case 30: - vte->cattr.fccode = COLOR_BLACK; + vte->cattr.fccode = TSM_COLOR_BLACK; break; case 31: - vte->cattr.fccode = COLOR_RED; + vte->cattr.fccode = TSM_COLOR_RED; break; case 32: - vte->cattr.fccode = COLOR_GREEN; + vte->cattr.fccode = TSM_COLOR_GREEN; break; case 33: - vte->cattr.fccode = COLOR_YELLOW; + vte->cattr.fccode = TSM_COLOR_YELLOW; break; case 34: - vte->cattr.fccode = COLOR_BLUE; + vte->cattr.fccode = TSM_COLOR_BLUE; break; case 35: - vte->cattr.fccode = COLOR_MAGENTA; + vte->cattr.fccode = TSM_COLOR_MAGENTA; break; case 36: - vte->cattr.fccode = COLOR_CYAN; + vte->cattr.fccode = TSM_COLOR_CYAN; break; case 37: - vte->cattr.fccode = COLOR_LIGHT_GREY; + vte->cattr.fccode = TSM_COLOR_LIGHT_GREY; break; case 39: copy_fcolor(&vte->cattr, &vte->def_attr); break; case 40: - vte->cattr.bccode = COLOR_BLACK; + vte->cattr.bccode = TSM_COLOR_BLACK; break; case 41: - vte->cattr.bccode = COLOR_RED; + vte->cattr.bccode = TSM_COLOR_RED; break; case 42: - vte->cattr.bccode = COLOR_GREEN; + vte->cattr.bccode = TSM_COLOR_GREEN; break; case 43: - vte->cattr.bccode = COLOR_YELLOW; + vte->cattr.bccode = TSM_COLOR_YELLOW; break; case 44: - vte->cattr.bccode = COLOR_BLUE; + vte->cattr.bccode = TSM_COLOR_BLUE; break; case 45: - vte->cattr.bccode = COLOR_MAGENTA; + vte->cattr.bccode = TSM_COLOR_MAGENTA; break; case 46: - vte->cattr.bccode = COLOR_CYAN; + vte->cattr.bccode = TSM_COLOR_CYAN; break; case 47: - vte->cattr.bccode = COLOR_LIGHT_GREY; + vte->cattr.bccode = TSM_COLOR_LIGHT_GREY; break; case 49: copy_bcolor(&vte->cattr, &vte->def_attr); break; case 90: - vte->cattr.fccode = COLOR_DARK_GREY; + vte->cattr.fccode = TSM_COLOR_DARK_GREY; break; case 91: - vte->cattr.fccode = COLOR_LIGHT_RED; + vte->cattr.fccode = TSM_COLOR_LIGHT_RED; break; case 92: - vte->cattr.fccode = COLOR_LIGHT_GREEN; + vte->cattr.fccode = TSM_COLOR_LIGHT_GREEN; break; case 93: - vte->cattr.fccode = COLOR_LIGHT_YELLOW; + vte->cattr.fccode = TSM_COLOR_LIGHT_YELLOW; break; case 94: - vte->cattr.fccode = COLOR_LIGHT_BLUE; + vte->cattr.fccode = TSM_COLOR_LIGHT_BLUE; break; case 95: - vte->cattr.fccode = COLOR_LIGHT_MAGENTA; + vte->cattr.fccode = TSM_COLOR_LIGHT_MAGENTA; break; case 96: - vte->cattr.fccode = COLOR_LIGHT_CYAN; + vte->cattr.fccode = TSM_COLOR_LIGHT_CYAN; break; case 97: - vte->cattr.fccode = COLOR_WHITE; + vte->cattr.fccode = TSM_COLOR_WHITE; break; case 100: - vte->cattr.bccode = COLOR_DARK_GREY; + vte->cattr.bccode = TSM_COLOR_DARK_GREY; break; case 101: - vte->cattr.bccode = COLOR_LIGHT_RED; + vte->cattr.bccode = TSM_COLOR_LIGHT_RED; break; case 102: - vte->cattr.bccode = COLOR_LIGHT_GREEN; + vte->cattr.bccode = TSM_COLOR_LIGHT_GREEN; break; case 103: - vte->cattr.bccode = COLOR_LIGHT_YELLOW; + vte->cattr.bccode = TSM_COLOR_LIGHT_YELLOW; break; case 104: - vte->cattr.bccode = COLOR_LIGHT_BLUE; + vte->cattr.bccode = TSM_COLOR_LIGHT_BLUE; break; case 105: - vte->cattr.bccode = COLOR_LIGHT_MAGENTA; + vte->cattr.bccode = TSM_COLOR_LIGHT_MAGENTA; break; case 106: - vte->cattr.bccode = COLOR_LIGHT_CYAN; + vte->cattr.bccode = TSM_COLOR_LIGHT_CYAN; break; case 107: - vte->cattr.bccode = COLOR_WHITE; + vte->cattr.bccode = TSM_COLOR_WHITE; break; case 38: /* fallthrough */ @@ -2381,6 +2398,10 @@ bool tsm_vte_handle_keyboard(struct tsm_vte *vte, uint32_t keysym, size_t len; uint32_t sym; + if (!vte) { + return false; + } + /* MOD1 (mostly labeled 'Alt') prepends an escape character to every * input that is sent by a key. * TODO: Transform this huge handler into a lookup table to save a lot diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b6f998b..7470282 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,6 +35,12 @@ libtsm_add_test(test_symbol check::check ) +libtsm_add_test(test_vte + LINK_LIBRARIES + tsm_test + check::check +) + # This is only a quick sanity check that verifies the # valgrind tests work properly. libtsm_add_test(test_valgrind diff --git a/test/test_common.h b/test/test_common.h index e9498a8..71360ef 100644 --- a/test/test_common.h +++ b/test/test_common.h @@ -47,6 +47,8 @@ /* lower address-space is protected from user-allocation, so this is invalid */ #define TEST_INVALID_PTR ((void*)0x10) +#define UNUSED(x) (void)(x) + #define TEST_DEFINE_CASE(_name) \ static TCase *test_create_case_##_name(void) \ { \ diff --git a/test/test_valgrind.c b/test/test_valgrind.c index 18156b9..46ef8fc 100644 --- a/test/test_valgrind.c +++ b/test/test_valgrind.c @@ -32,7 +32,7 @@ START_TEST(test_valgrind) void *p; p = malloc(0x100); - ck_assert(!!p); + ck_assert_ptr_ne(p, NULL); } END_TEST diff --git a/test/test_vte.c b/test/test_vte.c new file mode 100644 index 0000000..ee30bb4 --- /dev/null +++ b/test/test_vte.c @@ -0,0 +1,173 @@ +/* + * TSM - VTE State Machine Tests + * + * Copyright (c) 2018 Aetf + * + * 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. + */ + +#include "libtsm-int.h" +#include "libtsm.h" +#include "test_common.h" + +static void log_cb(void *data, const char *file, int line, const char *func, const char *subs, + unsigned int sev, const char *format, va_list args) +{ + UNUSED(data); + UNUSED(file); + UNUSED(line); + UNUSED(func); + UNUSED(subs); + UNUSED(sev); + UNUSED(format); + UNUSED(args); +} + +static void write_cb(struct tsm_vte *vte, const char *u8, size_t len, void *data) +{ + UNUSED(len); + UNUSED(data); + + ck_assert_ptr_nonnull(vte); + ck_assert_ptr_nonnull(u8); +} + +START_TEST(test_vte_init) +{ + struct tsm_screen *screen; + struct tsm_vte *vte; + int r; + + r = tsm_screen_new(&screen, log_cb, NULL); + ck_assert_int_eq(r, 0); + + r = tsm_vte_new(&vte, screen, write_cb, NULL, log_cb, NULL); + ck_assert_int_eq(r, 0); + + tsm_vte_unref(vte); + vte = NULL; + + tsm_screen_unref(screen); + screen = NULL; +} +END_TEST + +START_TEST(test_vte_null) +{ + int r; + bool rb; + + r = tsm_vte_new(NULL, NULL, NULL, NULL, log_cb, NULL); + ck_assert_int_eq(r, -EINVAL); + + tsm_vte_ref(NULL); + tsm_vte_unref(NULL); + + tsm_vte_set_osc_cb(NULL, NULL, NULL); + + r = tsm_vte_set_palette(NULL, ""); + ck_assert_int_eq(r, -EINVAL); + + r = tsm_vte_set_custom_palette(NULL, NULL); + ck_assert_int_eq(r, -EINVAL); + + tsm_vte_get_def_attr(NULL, NULL); + + tsm_vte_reset(NULL); + tsm_vte_hard_reset(NULL); + tsm_vte_input(NULL, "", 0); + + rb = tsm_vte_handle_keyboard(NULL, 0, 0, 0, 0); + ck_assert(!rb); +} +END_TEST + +static uint8_t test_palette[TSM_COLOR_NUM][3] = { + [TSM_COLOR_BLACK] = { 0, 18, 36 }, + [TSM_COLOR_RED] = { 1, 19, 37 }, + [TSM_COLOR_GREEN] = { 2, 20, 38 }, + [TSM_COLOR_YELLOW] = { 3, 21, 39 }, + [TSM_COLOR_BLUE] = { 4, 22, 40 }, + [TSM_COLOR_MAGENTA] = { 5, 23, 41 }, + [TSM_COLOR_CYAN] = { 6, 24, 42 }, + [TSM_COLOR_LIGHT_GREY] = { 7, 25, 43 }, + [TSM_COLOR_DARK_GREY] = { 8, 26, 44 }, + [TSM_COLOR_LIGHT_RED] = { 9, 27, 45 }, + [TSM_COLOR_LIGHT_GREEN] = { 10, 28, 46 }, + [TSM_COLOR_LIGHT_YELLOW] = { 11, 29, 47 }, + [TSM_COLOR_LIGHT_BLUE] = { 12, 30, 48 }, + [TSM_COLOR_LIGHT_MAGENTA] = { 13, 31, 49 }, + [TSM_COLOR_LIGHT_CYAN] = { 14, 32, 50 }, + [TSM_COLOR_WHITE] = { 15, 33, 51 }, + + [TSM_COLOR_FOREGROUND] = { 16, 34, 52 }, + [TSM_COLOR_BACKGROUND] = { 17, 35, 53 }, +}; + +START_TEST(test_vte_custom_palette) +{ + struct tsm_screen *screen; + struct tsm_vte *vte; + int r; + + r = tsm_screen_new(&screen, log_cb, NULL); + ck_assert_int_eq(r, 0); + + r = tsm_vte_new(&vte, screen, write_cb, NULL, log_cb, NULL); + ck_assert_int_eq(r, 0); + + r = tsm_vte_set_custom_palette(vte, test_palette); + ck_assert_int_eq(r, 0); + + r = tsm_vte_set_palette(vte, "custom"); + ck_assert_int_eq(r, 0); + + struct tsm_screen_attr attr; + tsm_vte_get_def_attr(vte, &attr); + ck_assert_uint_eq(attr.fr, test_palette[TSM_COLOR_FOREGROUND][0]); + ck_assert_uint_eq(attr.fg, test_palette[TSM_COLOR_FOREGROUND][1]); + ck_assert_uint_eq(attr.fb, test_palette[TSM_COLOR_FOREGROUND][2]); + + ck_assert_uint_eq(attr.br, test_palette[TSM_COLOR_BACKGROUND][0]); + ck_assert_uint_eq(attr.bg, test_palette[TSM_COLOR_BACKGROUND][1]); + ck_assert_uint_eq(attr.bb, test_palette[TSM_COLOR_BACKGROUND][2]); + + tsm_vte_unref(vte); + vte = NULL; + + tsm_screen_unref(screen); + screen = NULL; +} +END_TEST + +TEST_DEFINE_CASE(misc) + TEST(test_vte_init) + TEST(test_vte_null) + TEST(test_vte_custom_palette) +TEST_END_CASE + +// clang-format off +TEST_DEFINE( + TEST_SUITE(vte, + TEST_CASE(misc), + TEST_END + ) +) +// clang-format on From 3f5c38ae80fb13525be4f8d715a5cf596246b248 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 9 Oct 2018 11:17:37 -0400 Subject: [PATCH 14/20] build: add clang-format config Signed-off-by: Aetf --- .clang-format | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..eafe9b0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,121 @@ +--- +Language: Cpp +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 110 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - Q_FOREVER + - BOOST_FOREACH +IncludeBlocks: Regroup +IncludeCategories: + - Regex: 'tensorflow_headers\.h' + Priority: -1 + - Regex: '^"' + Priority: 3 + - Regex: '^(<|")(tensorflow|third_party)/' + Priority: 5 + - Regex: '^ Date: Tue, 9 Oct 2018 11:18:00 -0400 Subject: [PATCH 15/20] tsm: make sure stdint.h is included Signed-off-by: Aetf --- src/tsm/libtsm-int.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tsm/libtsm-int.h b/src/tsm/libtsm-int.h index ff3f3bc..dbc7924 100644 --- a/src/tsm/libtsm-int.h +++ b/src/tsm/libtsm-int.h @@ -1,6 +1,7 @@ /* * TSM - Main internal header * + * Copyright (c) 2018 Aetf * Copyright (c) 2011-2013 David Herrmann * * Permission is hereby granted, free of charge, to any person obtaining @@ -29,6 +30,7 @@ #include #include #include +#include #include "libtsm.h" #include "shl-llog.h" From a061a9ee7434f103ff98926942a78bddc1ec4545 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 9 Oct 2018 11:20:04 -0400 Subject: [PATCH 16/20] build: don't use symbols from libcheck newer than 0.9.10 Signed-off-by: Aetf --- test/test_vte.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_vte.c b/test/test_vte.c index ee30bb4..bb3369a 100644 --- a/test/test_vte.c +++ b/test/test_vte.c @@ -45,8 +45,8 @@ static void write_cb(struct tsm_vte *vte, const char *u8, size_t len, void *data UNUSED(len); UNUSED(data); - ck_assert_ptr_nonnull(vte); - ck_assert_ptr_nonnull(u8); + ck_assert_ptr_ne(vte, NULL); + ck_assert_ptr_ne(u8, NULL); } START_TEST(test_vte_init) From c26958c741ae4c82d473b2dac2317ddbd40261e7 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 9 Oct 2018 11:24:55 -0400 Subject: [PATCH 17/20] tsm: tsm_screen_draw now uses 64bit char id which is a breaking change, marking it as version 4 symbol Signed-off-by: Aetf --- src/tsm/libtsm.sym | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tsm/libtsm.sym b/src/tsm/libtsm.sym index 644ccf5..5e4cb91 100644 --- a/src/tsm/libtsm.sym +++ b/src/tsm/libtsm.sym @@ -99,8 +99,6 @@ global: tsm_screen_selection_target; tsm_screen_selection_copy; - tsm_screen_draw; - tsm_vte_new; tsm_vte_ref; tsm_vte_unref; @@ -118,5 +116,7 @@ global: LIBTSM_4 { global: + tsm_screen_draw; + tsm_vte_set_custom_palette; } LIBTSM_3; From 0463a84d54d5d1d755658f242d132a32bdcf0e2b Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 9 Oct 2018 12:51:23 -0400 Subject: [PATCH 18/20] build: add tests for tsm_screen Signed-off-by: Aetf --- test/CMakeLists.txt | 6 ++ test/test_screen.c | 147 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 test/test_screen.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7470282..a848995 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,6 +35,12 @@ libtsm_add_test(test_symbol check::check ) +libtsm_add_test(test_screen + LINK_LIBRARIES + tsm_test + check::check +) + libtsm_add_test(test_vte LINK_LIBRARIES tsm_test diff --git a/test/test_screen.c b/test/test_screen.c new file mode 100644 index 0000000..d5839b2 --- /dev/null +++ b/test/test_screen.c @@ -0,0 +1,147 @@ +/* + * TSM - Screen Management Tests + * + * Copyright (c) 2018 Aetf + * + * 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. + */ + +#include "test_common.h" +#include "libtsm.h" +#include "libtsm-int.h" + +START_TEST(test_screen_init) +{ + struct tsm_screen *screen; + int r; + + r = tsm_screen_new(&screen, NULL, NULL); + ck_assert_int_eq(r, 0); + + tsm_screen_unref(screen); + screen = NULL; +} +END_TEST + +START_TEST(test_screen_null) +{ + int r; + unsigned int n; + + r = tsm_screen_new(NULL, NULL, NULL); + ck_assert_int_eq(r, -EINVAL); + + tsm_screen_ref(NULL); + tsm_screen_unref(NULL); + + tsm_screen_set_opts(NULL, 0u); + tsm_screen_reset_opts(NULL, 0u); + + n = tsm_screen_get_opts(NULL); + ck_assert_int_eq(n, 0); + + n = tsm_screen_get_width(NULL); + ck_assert_int_eq(n, 0); + + n = tsm_screen_get_height(NULL); + ck_assert_int_eq(n, 0); + + r = tsm_screen_resize(NULL, 0, 0); + ck_assert_int_eq(r, -EINVAL); + + r = tsm_screen_set_margins(NULL, 0u, 0u); + ck_assert_int_eq(r, -EINVAL); + + tsm_screen_set_max_sb(NULL, 0u); + + tsm_screen_clear_sb(NULL); + + tsm_screen_sb_up(NULL, 0u); + tsm_screen_sb_down(NULL, 0u); + tsm_screen_sb_page_up(NULL, 0u); + tsm_screen_sb_page_down(NULL, 0u); + tsm_screen_sb_reset(NULL); + + tsm_screen_set_def_attr(NULL, NULL); + + tsm_screen_reset(NULL); + + tsm_screen_set_flags(NULL, 0u); + tsm_screen_reset_flags(NULL, 0u); + + n = tsm_screen_get_flags(NULL); + ck_assert_int_eq(n, 0); + + n = tsm_screen_get_cursor_x(NULL); + ck_assert_int_eq(n, 0); + + n = tsm_screen_get_cursor_y(NULL); + ck_assert_int_eq(n, 0); + + tsm_screen_set_tabstop(NULL); + tsm_screen_reset_tabstop(NULL); + tsm_screen_reset_all_tabstops(NULL); + + tsm_screen_write(NULL, 0u, NULL); + + tsm_screen_newline(NULL); + + tsm_screen_scroll_up(NULL, 0u); + tsm_screen_scroll_down(NULL, 0u); + + tsm_screen_move_to(NULL, 0u, 0u); + tsm_screen_move_up(NULL, 0u, false); + tsm_screen_move_down(NULL, 0u, false); + tsm_screen_move_right(NULL, 0u); + tsm_screen_move_left(NULL, 0u); + tsm_screen_move_line_end(NULL); + tsm_screen_move_line_home(NULL); + + tsm_screen_tab_right(NULL, 0u); + tsm_screen_tab_left(NULL, 0u); + + tsm_screen_insert_lines(NULL, 0u); + tsm_screen_delete_lines(NULL, 0u); + tsm_screen_insert_chars(NULL, 0u); + tsm_screen_delete_chars(NULL, 0u); + + tsm_screen_erase_cursor(NULL); + tsm_screen_erase_chars(NULL, 0u); + tsm_screen_erase_cursor_to_end(NULL, false); + tsm_screen_erase_home_to_cursor(NULL, false); + tsm_screen_erase_current_line(NULL, false); + tsm_screen_erase_screen_to_cursor(NULL, false); + tsm_screen_erase_cursor_to_screen(NULL, false); + tsm_screen_erase_screen(NULL, false); +} +END_TEST + + +TEST_DEFINE_CASE(misc) + TEST(test_screen_init) + TEST(test_screen_null) +TEST_END_CASE + +TEST_DEFINE( + TEST_SUITE(screen, + TEST_CASE(misc), + TEST_END + ) +) From a5a9ea0c23b28aa2c9cf889105b75981fdebbc25 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 9 Oct 2018 13:31:56 -0400 Subject: [PATCH 19/20] docs: make comments more doxygen compatible --- src/tsm/libtsm.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/tsm/libtsm.h b/src/tsm/libtsm.h index 4c5b64d..3355b1b 100644 --- a/src/tsm/libtsm.h +++ b/src/tsm/libtsm.h @@ -66,14 +66,14 @@ extern "C" { /** * Logging Callback * - * @data: user-provided data - * @file: Source code file where the log message originated or NULL - * @line: Line number in source code or 0 - * @func: C function name or NULL - * @subs: Subsystem where the message came from or NULL - * @sev: Kernel-style severity between 0=FATAL and 7=DEBUG - * @format: printf-formatted message - * @args: arguments for printf-style @format + * @param data: User-provided data + * @param file: Source code file where the log message originated or NULL + * @param line: Line number in source code or 0 + * @param func: C function name or NULL + * @param subs: Subsystem where the message came from or NULL + * @param sev: Kernel-style severity between 0=FATAL and 7=DEBUG + * @param format: Printf-formatted message + * @param args: Arguments for printf-style @p format * * This is the type of a logging callback function. You can always pass NULL * instead of such a function to disable logging. @@ -351,13 +351,16 @@ void tsm_vte_set_osc_cb(struct tsm_vte *vte, tsm_vte_osc_cb osc_cb, void *osc_da * - base16-light * * In addition, when palette name is "custom", the custom palette set in - * @link tsm_vte_set_custom_palette is used. + * tsm_vte_set_custom_palette() is used. * * @sa tsm_vte_set_custom_palette to set custom palette. * - * @param vte The vte object to set on + * @param vte The vte object to set on. * @param palette_name Name of the color palette. Pass NULL to reset to default. - * @return 0 on success. -EINVAL if vte is NULL. -ENOMEM if malloc fails. + * + * @retval 0 on success. + * @retval -EINVAL if vte is NULL. + * @retval -ENOMEM if malloc fails. */ int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette_name); @@ -393,8 +396,11 @@ int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette_name); * The palette array is copied into the vte object. * * @param vte The vte object to set on - * @param palette The palette array, which should has shape uint8_t palette[TSM_COLOR_NUM][3]. - * @return 0 on success. -EINVAL if vte is NULL. -ENOMEM if malloc fails. + * @param palette The palette array, which should have shape `uint8_t palette[TSM_COLOR_NUM][3]`. Pass NULL to clear. + * + * @retval 0 on success. + * @retval -EINVAL if vte is NULL. + * @retval -ENOMEM if malloc fails. */ int tsm_vte_set_custom_palette(struct tsm_vte *vte, uint8_t (*palette)[3]); From 5b27124be82e1a134d1b9458629677e9e53906d0 Mon Sep 17 00:00:00 2001 From: Aetf Date: Tue, 9 Oct 2018 13:40:17 -0400 Subject: [PATCH 20/20] build: bump version to 4.0.1 --- CMakeLists.txt | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7983646..5316411 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5) project(libtsm LANGUAGES C - VERSION 4.0.0 + VERSION 4.0.1 ) # Some meta data diff --git a/README.md b/README.md index c12098c..f2ba0a4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # TSM - Terminal Emulator State Machine -[![Build Status](https://travis-ci.com/Aetf/libtsm.svg?branch=develop)](https://travis-ci.com/Aetf/libtsm) +[![Build Status](https://travis-ci.com/Aetf/libtsm.svg?branch=master)](https://travis-ci.com/Aetf/libtsm) TSM is a state machine for DEC VT100-VT520 compatible terminal emulators. It tries to support all common standards while keeping compatibility to existing