Add version and adjust some cmake

This commit is contained in:
Marvin W 2019-12-17 23:52:05 +01:00
parent a4a795af33
commit bd45fdf1e1
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
11 changed files with 250 additions and 65 deletions

View file

@ -1,21 +1,58 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(Dino LANGUAGES C)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(ComputeVersion)
if (NOT VERSION_FOUND)
project(Dino LANGUAGES C)
elseif (VERSION_IS_RELEASE)
project(Dino VERSION ${VERSION_FULL} LANGUAGES C)
else ()
project(Dino LANGUAGES C)
set(PROJECT_VERSION ${VERSION_FULL})
endif ()
# Prepare Plugins # Prepare Plugins
set(PLUGINS omemo;openpgp;http-files) set(DEFAULT_PLUGINS omemo;openpgp;http-files)
foreach (plugin ${DEFAULT_PLUGINS})
if ("$CACHE{DINO_PLUGIN_ENABLED_${plugin}}" STREQUAL "")
if (NOT DEFINED DINO_PLUGIN_ENABLED_${plugin}})
set(DINO_PLUGIN_ENABLED_${plugin} "yes" CACHE BOOL "Enable plugin ${plugin}")
else ()
set(DINO_PLUGIN_ENABLED_${plugin} "${DINO_PLUGIN_ENABLED_${plugin}}" CACHE BOOL "Enable plugin ${plugin}" FORCE)
endif ()
if (DINO_PLUGIN_ENABLED_${plugin})
message(STATUS "Enabled plugin: ${plugin}")
else ()
message(STATUS "Disabled plugin: ${plugin}")
endif ()
endif ()
endforeach (plugin)
if (DISABLED_PLUGINS) if (DISABLED_PLUGINS)
list(REMOVE_ITEM PLUGINS ${DISABLED_PLUGINS}) foreach(plugin ${DISABLED_PLUGINS})
set(DINO_PLUGIN_ENABLED_${plugin} "no" CACHE BOOL "Enable plugin ${plugin}" FORCE)
message(STATUS "Disabled plugin: ${plugin}")
endforeach(plugin)
endif (DISABLED_PLUGINS) endif (DISABLED_PLUGINS)
if (ENABLED_PLUGINS) if (ENABLED_PLUGINS)
list(APPEND PLUGINS ${ENABLED_PLUGINS}) foreach(plugin ${ENABLED_PLUGINS})
set(DINO_PLUGIN_ENABLED_${plugin} "yes" CACHE BOOL "Enable plugin ${plugin}" FORCE)
message(STATUS "Enabled plugin: ${plugin}")
endforeach(plugin)
endif (ENABLED_PLUGINS) endif (ENABLED_PLUGINS)
list(REMOVE_DUPLICATES PLUGINS) list(REMOVE_DUPLICATES PLUGINS)
foreach(plugin ${PLUGINS}) set(PLUGINS "")
message(STATUS "Building plugin: ${plugin}") get_cmake_property(all_variables VARIABLES)
set(PLUGIN_ENABLED_${plugin} "yes") foreach (variable_name ${all_variables})
endforeach(plugin) if (variable_name MATCHES "^DINO_PLUGIN_ENABLED_(.+)$" AND ${variable_name})
list(APPEND PLUGINS ${CMAKE_MATCH_1})
endif()
endforeach ()
list(SORT PLUGINS)
list(JOIN PLUGINS ", " PLUGINS_TEXT)
message(STATUS "Configuring Dino ${PROJECT_VERSION} with plugins: ${PLUGINS_TEXT}")
# Prepare instal paths # Prepare instal paths
macro(set_path what val desc) macro(set_path what val desc)
@ -23,11 +60,14 @@ macro(set_path what val desc)
unset(${what} CACHE) unset(${what} CACHE)
set(${what} ${val}) set(${what} ${val})
endif () endif ()
if (NOT "${${what}}" STREQUAL "${_${what}_SET}")
message(STATUS "${desc}: ${${what}}") message(STATUS "${desc}: ${${what}}")
set(_${what}_SET ${${what}} CACHE INTERNAL ${desc})
endif()
endmacro(set_path) endmacro(set_path)
string(REGEX REPLACE "^liblib" "lib" LIBDIR_NAME "lib${LIB_SUFFIX}") string(REGEX REPLACE "^liblib" "lib" LIBDIR_NAME "lib${LIB_SUFFIX}")
message(STATUS "Installation directory for architecture-independent files: ${CMAKE_INSTALL_PREFIX}") set_path(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Installation directory for architecture-independent files")
set_path(EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Installation directory for architecture-dependent files") set_path(EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Installation directory for architecture-dependent files")
set_path(SHARE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/share" "Installation directory for read-only architecture-independent data") set_path(SHARE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/share" "Installation directory for read-only architecture-independent data")
@ -98,14 +138,15 @@ unset(__WITHOUT_FILE_OFFSET_BITS_64)
if ($ENV{USE_CCACHE}) if ($ENV{USE_CCACHE})
# Configure CCache if available # Configure CCache if available
find_program(CCACHE_FOUND ccache) find_program(CCACHE_BIN ccache)
if(CCACHE_FOUND) mark_as_advanced(CCACHE_BIN)
if (CCACHE_BIN)
message(STATUS "Using ccache") message(STATUS "Using ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_BIN})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_BIN})
else(CCACHE_FOUND) else (CCACHE_BIN)
message(STATUS "USE_CCACHE was set but ccache was not found") message(STATUS "USE_CCACHE was set but ccache was not found")
endif(CCACHE_FOUND) endif (CCACHE_BIN)
endif ($ENV{USE_CCACHE}) endif ($ENV{USE_CCACHE})
if (NOT NO_DEBUG) if (NOT NO_DEBUG)

104
cmake/ComputeVersion.cmake Normal file
View file

@ -0,0 +1,104 @@
include(CMakeParseArguments)
function(_compute_version_from_file)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/VERSION)
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/VERSION)
set(VERSION_FOUND 0 PARENT_SCOPE)
return()
endif ()
file(STRINGS ${CMAKE_SOURCE_DIR}/VERSION VERSION_FILE)
string(REPLACE " " ";" VERSION_FILE "${VERSION_FILE}")
cmake_parse_arguments(VERSION_FILE "" "RELEASE;PRERELEASE" "" ${VERSION_FILE})
if (DEFINED VERSION_FILE_RELEASE)
string(STRIP "${VERSION_FILE_RELEASE}" VERSION_FILE_RELEASE)
set(VERSION_IS_RELEASE 1 PARENT_SCOPE)
set(VERSION_FULL "${VERSION_FILE_RELEASE}" PARENT_SCOPE)
set(VERSION_FOUND 1 PARENT_SCOPE)
elseif (DEFINED VERSION_FILE_PRERELEASE)
string(STRIP "${VERSION_FILE_PRERELEASE}" VERSION_FILE_PRERELEASE)
set(VERSION_IS_RELEASE 0 PARENT_SCOPE)
set(VERSION_FULL "${VERSION_FILE_PRERELEASE}" PARENT_SCOPE)
set(VERSION_FOUND 1 PARENT_SCOPE)
else ()
set(VERSION_FOUND 0 PARENT_SCOPE)
endif ()
endfunction(_compute_version_from_file)
function(_compute_version_from_git)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/.git)
if (NOT GIT_EXECUTABLE)
find_package(Git QUIET)
if (NOT GIT_FOUND)
return()
endif ()
endif (NOT GIT_EXECUTABLE)
# Git tag
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --abbrev=0
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_tag
ERROR_VARIABLE git_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if (NOT git_result EQUAL 0)
return()
endif (NOT git_result EQUAL 0)
if (git_tag MATCHES "^v?([0-9]+[.]?[0-9]*[.]?[0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$")
set(VERSION_LAST_RELEASE "${CMAKE_MATCH_1}")
else ()
return()
endif ()
# Git describe
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_describe
ERROR_VARIABLE git_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if (NOT git_result EQUAL 0)
return()
endif (NOT git_result EQUAL 0)
if ("${git_tag}" STREQUAL "${git_describe}")
set(VERSION_IS_RELEASE 1)
else ()
set(VERSION_IS_RELEASE 0)
if (git_describe MATCHES "g([0-9a-f]+)$")
set(VERSION_COMMIT_HASH "${CMAKE_MATCH_1}")
endif ()
execute_process(
COMMAND "${GIT_EXECUTABLE}" show --format=%cd --date=format:%Y%m%d -s
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_time
ERROR_VARIABLE git_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if (NOT git_result EQUAL 0)
return()
endif (NOT git_result EQUAL 0)
set(VERSION_COMMIT_DATE "${git_time}")
endif ()
if (NOT VERSION_IS_RELEASE)
set(VERSION_SUFFIX ".git${VERSION_COMMIT_DATE}.${VERSION_COMMIT_HASH}")
else (NOT VERSION_IS_RELEASE)
set(VERSION_SUFFIX "")
endif (NOT VERSION_IS_RELEASE)
set(VERSION_IS_RELEASE ${VERSION_IS_RELEASE} PARENT_SCOPE)
set(VERSION_FULL "${VERSION_LAST_RELEASE}${VERSION_SUFFIX}" PARENT_SCOPE)
set(VERSION_FOUND 1 PARENT_SCOPE)
endfunction(_compute_version_from_git)
_compute_version_from_file()
if (NOT VERSION_FOUND)
_compute_version_from_git()
endif (NOT VERSION_FOUND)

View file

@ -27,6 +27,9 @@ endif()
if (GDK3_FOUND) if (GDK3_FOUND)
find_file(GDK3_WITH_X11 "gdk/gdkx.h" HINTS ${GDK3_INCLUDE_DIRS}) find_file(GDK3_WITH_X11 "gdk/gdkx.h" HINTS ${GDK3_INCLUDE_DIRS})
if (GDK3_WITH_X11)
set(GDK3_WITH_X11 yes CACHE INTERNAL "Does GDK3 support X11")
endif (GDK3_WITH_X11)
endif () endif ()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)

View file

@ -193,6 +193,9 @@ function(vala_precompile output)
endif(ARGS_GENERATE_HEADER) endif(ARGS_GENERATE_HEADER)
string(REPLACE " " ";" VALAC_FLAGS ${CMAKE_VALA_FLAGS}) string(REPLACE " " ";" VALAC_FLAGS ${CMAKE_VALA_FLAGS})
if (VALA_VERSION VERSION_GREATER "0.38")
set(VALAC_COLORS "--color=always")
endif ()
if(ARGS_FAST_VAPI) if(ARGS_FAST_VAPI)
foreach(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS}) foreach(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
@ -211,6 +214,7 @@ function(vala_precompile output)
COMMAND COMMAND
${VALA_EXECUTABLE} ${VALA_EXECUTABLE}
ARGS ARGS
${VALAC_COLORS}
--fast-vapi ${fast_vapi_file} --fast-vapi ${fast_vapi_file}
${vala_define_opts} ${vala_define_opts}
${ARGS_OPTIONS} ${ARGS_OPTIONS}
@ -246,6 +250,7 @@ function(vala_precompile output)
COMMAND COMMAND
${VALA_EXECUTABLE} ${VALA_EXECUTABLE}
ARGS ARGS
${VALAC_COLORS}
"-C" "-C"
"-d" ${dir} "-d" ${dir}
${vala_pkg_opts} ${vala_pkg_opts}
@ -271,6 +276,7 @@ function(vala_precompile output)
COMMAND COMMAND
${VALA_EXECUTABLE} ${VALA_EXECUTABLE}
ARGS ARGS
${VALAC_COLORS}
-C -q --disable-warnings -C -q --disable-warnings
${header_arguments} ${header_arguments}
${vapi_arguments} ${vapi_arguments}
@ -306,6 +312,7 @@ function(vala_precompile output)
COMMAND COMMAND
${VALA_EXECUTABLE} ${VALA_EXECUTABLE}
ARGS ARGS
${VALAC_COLORS}
-C -C
${header_arguments} ${header_arguments}
${vapi_arguments} ${vapi_arguments}

20
configure vendored
View file

@ -191,9 +191,16 @@ if ! [ -x "$ninja_bin" ]; then
ninja_bin="$(which ninja 2>/dev/null)" ninja_bin="$(which ninja 2>/dev/null)"
fi fi
if [ -x "$ninja_bin" ]; then if [ -x "$ninja_bin" ]; then
ninja_version=$($ninja_bin --version 2>/dev/null) ninja_version=`$ninja_bin --version 2>/dev/null`
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [ -d build ]; then
last_ninja_version=`cat build/.ninja_version 2>/dev/null`
else
last_ninja_version=0
fi
if [ "$ninja_version" != "$last_ninja_version" ]; then
echo "-- Found Ninja: $ninja_bin (found version \"$ninja_version\")" echo "-- Found Ninja: $ninja_bin (found version \"$ninja_version\")"
fi
cmake_type="Ninja" cmake_type="Ninja"
exec_bin="$ninja_bin" exec_bin="$ninja_bin"
exec_command="$exec_bin" exec_command="$exec_bin"
@ -219,14 +226,12 @@ if ! [ -x "$exec_bin" ]; then
fi fi
if [ -f ./build ] if [ -f ./build ]; then
then
echo "-!- ./build file exists. ./configure can't continue" echo "-!- ./build file exists. ./configure can't continue"
exit 2 exit 2
fi fi
if [ -d build ] if [ -d build ]; then
then
last_type=`cat build/.cmake_type` last_type=`cat build/.cmake_type`
if [ "$cmake_type" != "$last_type" ] if [ "$cmake_type" != "$last_type" ]
then then
@ -241,6 +246,7 @@ mkdir -p build
cd build cd build
echo "$cmake_type" > .cmake_type echo "$cmake_type" > .cmake_type
echo "$ninja_version" > .ninja_version
cmake -G "$cmake_type" \ cmake -G "$cmake_type" \
-DCMAKE_INSTALL_PREFIX="$PREFIX" \ -DCMAKE_INSTALL_PREFIX="$PREFIX" \
-DENABLED_PLUGINS="$ENABLED_PLUGINS" \ -DENABLED_PLUGINS="$ENABLED_PLUGINS" \
@ -256,10 +262,10 @@ cmake -G "$cmake_type" \
-DBIN_INSTALL_DIR="$BINDIR" \ -DBIN_INSTALL_DIR="$BINDIR" \
-DINCLUDE_INSTALL_DIR="$INCLUDEDIR" \ -DINCLUDE_INSTALL_DIR="$INCLUDEDIR" \
-DLIB_INSTALL_DIR="$LIBDIR" \ -DLIB_INSTALL_DIR="$LIBDIR" \
-Wno-dev \
.. || exit 9 .. || exit 9
if [ "$cmake_type" = "Ninja" ] if [ "$cmake_type" = "Ninja" ]; then
then
cat << EOF > Makefile cat << EOF > Makefile
default: default:
@sh -c "$exec_command" @sh -c "$exec_command"

View file

@ -1,6 +1,9 @@
using Dino.Entities; using Dino.Entities;
public interface Dino.Application : GLib.Application { namespace Dino {
extern const string VERSION;
public interface Application : GLib.Application {
public abstract Database db { get; set; } public abstract Database db { get; set; }
public abstract Dino.Entities.Settings settings { get; set; } public abstract Dino.Entities.Settings settings { get; set; }
@ -127,3 +130,4 @@ public interface Dino.Application : GLib.Application {
} }
} }
}

View file

@ -169,7 +169,7 @@ OPTIONS
${MAIN_EXTRA_OPTIONS} ${MAIN_EXTRA_OPTIONS}
) )
add_definitions(${VALA_CFLAGS} -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\") add_definitions(${VALA_CFLAGS} -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\" -DDINO_VERSION=\"${PROJECT_VERSION}\")
add_executable(dino ${MAIN_VALA_C} ${MAIN_GRESOURCES_TARGET} src/emojichooser.c) add_executable(dino ${MAIN_VALA_C} ${MAIN_GRESOURCES_TARGET} src/emojichooser.c)
add_dependencies(dino ${GETTEXT_PACKAGE}-translations) add_dependencies(dino ${GETTEXT_PACKAGE}-translations)
target_include_directories(dino PRIVATE src) target_include_directories(dino PRIVATE src)

View file

@ -16,6 +16,10 @@
<attribute name="action">app.open_shortcuts</attribute> <attribute name="action">app.open_shortcuts</attribute>
<attribute name="label" translatable="yes">Keyboard Shortcuts</attribute> <attribute name="label" translatable="yes">Keyboard Shortcuts</attribute>
</item> </item>
<item>
<attribute name="action">app.about</attribute>
<attribute name="label" translatable="yes">About Dino</attribute>
</item>
</section> </section>
</menu> </menu>
</interface> </interface>

View file

@ -80,6 +80,10 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
settings_action.activate.connect(show_settings_window); settings_action.activate.connect(show_settings_window);
add_action(settings_action); add_action(settings_action);
SimpleAction about_action = new SimpleAction("about", null);
about_action.activate.connect(show_about_window);
add_action(about_action);
SimpleAction quit_action = new SimpleAction("quit", null); SimpleAction quit_action = new SimpleAction("quit", null);
quit_action.activate.connect(quit); quit_action.activate.connect(quit);
add_action(quit_action); add_action(quit_action);
@ -169,6 +173,18 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
dialog.present(); dialog.present();
} }
private void show_about_window() {
show_about_dialog(get_active_window(),
logo_icon_name: "im.dino.Dino",
program_name: "Dino",
version: Dino.VERSION.strip().length == 0 ? null : Dino.VERSION,
comments: "Dino. Communicating happiness.",
website: "https://dino.im/",
website_label: "dino.im",
copyright: "Copyright © 2016-2019 - Dino Team",
license_type: License.GPL_3_0);
}
private void show_join_muc_dialog(Account? account, Jid jid) { private void show_join_muc_dialog(Account? account, Jid jid) {
Dialog dialog = new Dialog.with_buttons(_("Join Channel"), window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR, _("Join"), ResponseType.OK, _("Cancel"), ResponseType.CANCEL); Dialog dialog = new Dialog.with_buttons(_("Join Channel"), window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR, _("Join"), ResponseType.OK, _("Cancel"), ResponseType.CANCEL);
dialog.modal = true; dialog.modal = true;

View file

@ -1,18 +1,18 @@
if(PLUGIN_ENABLED_http-files) if(DINO_PLUGIN_ENABLED_http-files)
add_subdirectory(http-files) add_subdirectory(http-files)
endif(PLUGIN_ENABLED_http-files) endif(DINO_PLUGIN_ENABLED_http-files)
if(PLUGIN_ENABLED_openpgp) if(DINO_PLUGIN_ENABLED_openpgp)
add_subdirectory(gpgme-vala) add_subdirectory(gpgme-vala)
add_subdirectory(openpgp) add_subdirectory(openpgp)
endif(PLUGIN_ENABLED_openpgp) endif(DINO_PLUGIN_ENABLED_openpgp)
if(PLUGIN_ENABLED_omemo) if(DINO_PLUGIN_ENABLED_omemo)
add_subdirectory(crypto-vala) add_subdirectory(crypto-vala)
add_subdirectory(omemo) add_subdirectory(omemo)
add_subdirectory(signal-protocol) add_subdirectory(signal-protocol)
endif(PLUGIN_ENABLED_omemo) endif(DINO_PLUGIN_ENABLED_omemo)
if(PLUGIN_ENABLED_notification-sound) if(DINO_PLUGIN_ENABLED_notification-sound)
add_subdirectory(notification-sound) add_subdirectory(notification-sound)
endif(PLUGIN_ENABLED_notification-sound) endif(DINO_PLUGIN_ENABLED_notification-sound)

View file

@ -18,8 +18,6 @@ endif()
vala_precompile(ENGINE_VALA_C vala_precompile(ENGINE_VALA_C
SOURCES SOURCES
"src/glib_fixes.vapi"
"src/core/namespace_state.vala" "src/core/namespace_state.vala"
"src/core/stanza_attribute.vala" "src/core/stanza_attribute.vala"
"src/core/stanza_node.vala" "src/core/stanza_node.vala"
@ -101,6 +99,8 @@ GENERATE_VAPI
xmpp-vala xmpp-vala
GENERATE_HEADER GENERATE_HEADER
xmpp-vala xmpp-vala
CUSTOM_VAPIS
"${CMAKE_CURRENT_SOURCE_DIR}/src/glib_fixes.vapi"
DEFINITIONS DEFINITIONS
${ENGINE_DEFINITIONS} ${ENGINE_DEFINITIONS}
) )