2020-01-21 20:53:43 +00:00
cmake_minimum_required(VERSION 3.3)
2017-03-23 16:10:45 +00:00
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
2019-12-17 22:52:05 +00:00
include(ComputeVersion)
if (NOT VERSION_FOUND)
2021-05-01 13:19:05 +00:00
project(Dino LANGUAGES C CXX)
2019-12-17 22:52:05 +00:00
elseif (VERSION_IS_RELEASE)
2021-05-01 13:19:05 +00:00
project(Dino VERSION ${VERSION_FULL} LANGUAGES C CXX)
2019-12-17 22:52:05 +00:00
else ()
2021-05-01 13:19:05 +00:00
project(Dino LANGUAGES C CXX)
2019-12-17 22:52:05 +00:00
set(PROJECT_VERSION ${VERSION_FULL})
endif ()
2017-03-23 16:10:45 +00:00
# Prepare Plugins
2021-03-19 22:09:56 +00:00
set(DEFAULT_PLUGINS omemo;openpgp;http-files;ice;rtp)
2019-12-17 22:52:05 +00:00
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)
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)
if (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)
2017-03-23 16:10:45 +00:00
2019-12-17 22:52:05 +00:00
set(PLUGINS "")
get_cmake_property(all_variables VARIABLES)
foreach (variable_name ${all_variables})
if (variable_name MATCHES "^DINO_PLUGIN_ENABLED_(.+)$" AND ${variable_name})
list(APPEND PLUGINS ${CMAKE_MATCH_1})
endif()
endforeach ()
list(SORT PLUGINS)
2019-12-18 00:16:35 +00:00
string(REPLACE ";" ", " PLUGINS_TEXT "${PLUGINS}")
2019-12-17 22:52:05 +00:00
message(STATUS "Configuring Dino ${PROJECT_VERSION} with plugins: ${PLUGINS_TEXT}")
2017-03-23 16:10:45 +00:00
# Prepare instal paths
2017-03-30 13:29:21 +00:00
macro(set_path what val desc)
2019-12-17 22:52:05 +00:00
if (NOT ${what})
2017-03-30 13:29:21 +00:00
unset(${what} CACHE)
set(${what} ${val})
2019-12-17 22:52:05 +00:00
endif ()
if (NOT "${${what}}" STREQUAL "${_${what}_SET}")
message(STATUS "${desc}: ${${what}}")
set(_${what}_SET ${${what}} CACHE INTERNAL ${desc})
2017-03-30 13:29:21 +00:00
endif()
endmacro(set_path)
2017-03-23 16:10:45 +00:00
string(REGEX REPLACE "^liblib" "lib" LIBDIR_NAME "lib${LIB_SUFFIX}")
2019-12-17 22:52:05 +00:00
set_path(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Installation directory for architecture-independent files")
2017-03-30 13:29:21 +00:00
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(BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin" "Installation directory for user executables")
set_path(DATA_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/dino" "Installation directory for dino-specific data")
2017-12-03 11:15:21 +00:00
set_path(APPDATA_FILE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/metainfo" "Installation directory for .appdata.xml files")
2017-03-30 13:29:21 +00:00
set_path(DESKTOP_FILE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/applications" "Installation directory for .desktop files")
2017-09-19 22:26:04 +00:00
set_path(SERVICE_FILE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/dbus-1/services" "Installation directory for .service files")
2017-03-30 13:29:21 +00:00
set_path(ICON_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/icons" "Installation directory for icons")
set_path(INCLUDE_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/include" "Installation directory for C header files")
set_path(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/${LIBDIR_NAME}" "Installation directory for object code libraries")
2017-04-07 09:09:47 +00:00
set_path(LOCALE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/locale" "Installation directory for locale files")
2017-04-03 12:10:17 +00:00
set_path(PLUGIN_INSTALL_DIR "${LIB_INSTALL_DIR}/dino/plugins" "Installation directory for dino plugin object code files")
2017-03-30 13:29:21 +00:00
set_path(VAPI_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/vala/vapi" "Installation directory for Vala API files")
2017-03-23 16:10:45 +00:00
set(TARGET_INSTALL LIBRARY DESTINATION ${LIB_INSTALL_DIR} RUNTIME DESTINATION ${BIN_INSTALL_DIR} PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
set(PLUGIN_INSTALL LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} RUNTIME DESTINATION ${PLUGIN_INSTALL_DIR})
2017-03-02 14:37:32 +00:00
include(CheckCCompilerFlag)
2017-08-31 21:53:40 +00:00
include(CheckCSourceCompiles)
2017-03-23 16:10:45 +00:00
2020-01-21 20:53:43 +00:00
macro(AddCFlagIfSupported list flag)
2017-03-30 19:26:17 +00:00
string(REGEX REPLACE "[^a-z^A-Z^_^0-9]+" "_" flag_name ${flag})
2017-08-31 21:53:40 +00:00
check_c_compiler_flag(${flag} COMPILER_SUPPORTS${flag_name})
2019-12-17 22:52:05 +00:00
if (${COMPILER_SUPPORTS${flag_name}})
2020-01-21 20:53:43 +00:00
set(${list} "${${list}} ${flag}")
2019-12-17 22:52:05 +00:00
endif ()
2017-03-23 16:10:45 +00:00
endmacro()
2017-03-02 14:37:32 +00:00
2021-03-19 22:09:56 +00:00
2019-12-17 22:52:05 +00:00
if ("Ninja" STREQUAL ${CMAKE_GENERATOR})
2020-01-21 20:53:43 +00:00
AddCFlagIfSupported(CMAKE_C_FLAGS -fdiagnostics-color)
endif ()
# Flags for all C files
AddCFlagIfSupported(CMAKE_C_FLAGS -Wall)
AddCFlagIfSupported(CMAKE_C_FLAGS -Wextra)
AddCFlagIfSupported(CMAKE_C_FLAGS -Werror=format-security)
AddCFlagIfSupported(CMAKE_C_FLAGS -Wno-duplicate-decl-specifier)
2021-03-19 22:09:56 +00:00
AddCFlagIfSupported(CMAKE_C_FLAGS -fno-omit-frame-pointer)
2020-01-21 20:53:43 +00:00
if (NOT VALA_WARN)
set(VALA_WARN "conversion")
endif ()
set(VALA_WARN "${VALA_WARN}" CACHE STRING "Which warnings to show when invoking C compiler on Vala compiler output")
set_property(CACHE VALA_WARN PROPERTY STRINGS "all;unused;qualifier;conversion;deprecated;format;none")
# Vala generates some unused stuff
if (NOT ("all" IN_LIST VALA_WARN OR "unused" IN_LIST VALA_WARN))
AddCFlagIfSupported(VALA_CFLAGS -Wno-unused-but-set-variable)
AddCFlagIfSupported(VALA_CFLAGS -Wno-unused-function)
AddCFlagIfSupported(VALA_CFLAGS -Wno-unused-label)
AddCFlagIfSupported(VALA_CFLAGS -Wno-unused-parameter)
AddCFlagIfSupported(VALA_CFLAGS -Wno-unused-value)
AddCFlagIfSupported(VALA_CFLAGS -Wno-unused-variable)
endif ()
if (NOT ("all" IN_LIST VALA_WARN OR "qualifier" IN_LIST VALA_WARN))
AddCFlagIfSupported(VALA_CFLAGS -Wno-discarded-qualifiers)
AddCFlagIfSupported(VALA_CFLAGS -Wno-discarded-array-qualifiers)
2022-01-05 12:57:36 +00:00
AddCFlagIfSupported(VALA_CFLAGS -Wno-incompatible-pointer-types-discards-qualifiers)
2019-12-17 22:52:05 +00:00
endif ()
2017-03-02 14:37:32 +00:00
2020-01-21 20:53:43 +00:00
if (NOT ("all" IN_LIST VALA_WARN OR "deprecated" IN_LIST VALA_WARN))
AddCFlagIfSupported(VALA_CFLAGS -Wno-deprecated-declarations)
endif ()
if (NOT ("all" IN_LIST VALA_WARN OR "format" IN_LIST VALA_WARN))
AddCFlagIfSupported(VALA_CFLAGS -Wno-missing-braces)
endif ()
2017-03-30 19:26:17 +00:00
2020-01-21 20:53:43 +00:00
if (NOT ("all" IN_LIST VALA_WARN OR "conversion" IN_LIST VALA_WARN))
AddCFlagIfSupported(VALA_CFLAGS -Wno-int-conversion)
AddCFlagIfSupported(VALA_CFLAGS -Wno-pointer-sign)
AddCFlagIfSupported(VALA_CFLAGS -Wno-incompatible-pointer-types)
endif ()
2017-03-30 13:29:21 +00:00
2017-08-31 21:53:40 +00:00
try_compile(__WITHOUT_FILE_OFFSET_BITS_64 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/LargeFileOffsets.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
2019-12-17 22:52:05 +00:00
if (NOT __WITHOUT_FILE_OFFSET_BITS_64)
2017-08-31 21:53:40 +00:00
try_compile(__WITH_FILE_OFFSET_BITS_64 ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/LargeFileOffsets.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=64)
2019-12-17 22:52:05 +00:00
if (__WITH_FILE_OFFSET_BITS_64)
2020-01-21 20:53:43 +00:00
AddCFlagIfSupported(CMAKE_C_FLAGS -D_FILE_OFFSET_BITS=64)
2017-08-31 21:53:40 +00:00
message(STATUS "Enabled large file support using _FILE_OFFSET_BITS=64")
2019-12-17 22:52:05 +00:00
else (__WITH_FILE_OFFSET_BITS_64)
2017-08-31 21:53:40 +00:00
message(STATUS "Large file support not available")
2019-12-17 22:52:05 +00:00
endif (__WITH_FILE_OFFSET_BITS_64)
2017-08-31 21:53:40 +00:00
unset(__WITH_FILE_OFFSET_BITS_64)
2019-12-17 22:52:05 +00:00
endif (NOT __WITHOUT_FILE_OFFSET_BITS_64)
2017-08-31 21:53:40 +00:00
unset(__WITHOUT_FILE_OFFSET_BITS_64)
2019-12-17 22:52:05 +00:00
if ($ENV{USE_CCACHE})
2017-03-30 13:29:21 +00:00
# Configure CCache if available
2019-12-17 22:52:05 +00:00
find_program(CCACHE_BIN ccache)
mark_as_advanced(CCACHE_BIN)
if (CCACHE_BIN)
2017-03-30 13:29:21 +00:00
message(STATUS "Using ccache")
2019-12-17 22:52:05 +00:00
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_BIN})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_BIN})
else (CCACHE_BIN)
2017-08-31 21:53:40 +00:00
message(STATUS "USE_CCACHE was set but ccache was not found")
2019-12-17 22:52:05 +00:00
endif (CCACHE_BIN)
endif ($ENV{USE_CCACHE})
2017-03-23 16:10:45 +00:00
2019-12-17 22:52:05 +00:00
if (NOT NO_DEBUG)
2017-03-23 16:10:45 +00:00
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_VALA_FLAGS "${CMAKE_VALA_FLAGS} -g")
2019-12-17 22:52:05 +00:00
endif (NOT NO_DEBUG)
2017-03-23 16:10:45 +00:00
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
2017-04-23 08:01:40 +00:00
set(GTK3_GLOBAL_VERSION 3.22)
set(GLib_GLOBAL_VERSION 2.38)
2019-12-22 03:10:53 +00:00
set(ICU_GLOBAL_VERSION 57)
2017-04-23 08:01:40 +00:00
2019-12-17 22:52:05 +00:00
if (NOT VALA_EXECUTABLE)
2017-03-30 13:29:21 +00:00
unset(VALA_EXECUTABLE CACHE)
2019-12-17 22:52:05 +00:00
endif ()
2017-03-30 13:29:21 +00:00
2017-12-31 19:19:51 +00:00
find_package(Vala 0.34 REQUIRED)
2019-12-17 22:52:05 +00:00
if (VALA_VERSION VERSION_GREATER "0.34.90" AND VALA_VERSION VERSION_LESS "0.36.1" OR # Due to a bug on 0.36.0 (and pre-releases), we need to disable FAST_VAPI
2020-04-22 21:59:12 +00:00
VALA_VERSION VERSION_EQUAL "0.44.10" OR VALA_VERSION VERSION_EQUAL "0.46.4" OR VALA_VERSION VERSION_EQUAL "0.47.1" OR # See Dino issue #646
VALA_VERSION VERSION_EQUAL "0.40.21" OR VALA_VERSION VERSION_EQUAL "0.46.8" OR VALA_VERSION VERSION_EQUAL "0.48.4") # See Dino issue #816
2017-03-23 19:06:00 +00:00
set(DISABLE_FAST_VAPI yes)
2019-12-17 22:52:05 +00:00
endif ()
2017-03-23 19:06:00 +00:00
2017-03-23 16:10:45 +00:00
include(${VALA_USE_FILE})
include(MultiFind)
include(GlibCompileResourcesSupport)
2022-03-09 00:33:42 +00:00
find_package(GLib ${GLib_GLOBAL_VERSION} REQUIRED)
2022-03-16 14:33:13 +00:00
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" GLib_MAJOR_VERSION "${GLib_VERSION}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" GLib_MINOR_VERSION "${GLib_VERSION}")
math(EXPR GLib_LAST_RELEASE_MINOR_VERSION "${GLib_MINOR_VERSION} / 2 * 2")
set(CMAKE_VALA_FLAGS "${CMAKE_VALA_FLAGS} --target-glib=${GLib_MAJOR_VERSION}.${GLib_LAST_RELEASE_MINOR_VERSION}")
2017-03-02 14:37:32 +00:00
add_subdirectory(qlite)
2017-03-10 16:01:45 +00:00
add_subdirectory(xmpp-vala)
2017-03-10 18:34:56 +00:00
add_subdirectory(libdino)
2017-03-11 00:29:38 +00:00
add_subdirectory(main)
2021-05-14 17:26:05 +00:00
add_subdirectory(crypto-vala)
2017-03-11 00:29:38 +00:00
add_subdirectory(plugins)
2017-03-23 16:10:45 +00:00
# uninstall target
configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake COMMENT "Uninstall the project...")