[evolution-data-server/wip/cmake] GObjectIntrospection build



commit eda51aa570ebd2a2d2f9a602bf19df058fc889a7
Author: Milan Crha <mcrha redhat com>
Date:   Thu Sep 22 14:05:01 2016 +0200

    GObjectIntrospection build

 CMakeLists.txt                           |   15 ++-
 camel/CMakeLists.txt                     |   33 ++++-
 cmake/modules/GObjectIntrospection.cmake |  197 ++++++++++++++++++++++++++++++
 libedataserver/CMakeLists.txt            |   27 ++++-
 4 files changed, 258 insertions(+), 14 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 72d8fdd..e2b3db5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -107,7 +107,7 @@ set(json_glib_minimum_version 1.0.4)
 set(webkit2gtk_minimum_version 2.11.91)
 
 # Load modules from the source tree
-set(CMAKE_MODULE_PATH $CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
 
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 
@@ -128,8 +128,8 @@ add_printable_variable_path(BIN_INSTALL_DIR "Install directory for binary files,
 add_printable_variable_path(INCLUDE_INSTALL_DIR "Install directory for header files, defaults to 
CMAKE_INSTALL_PREFIX/include" "${CMAKE_INSTALL_PREFIX}/include")
 add_printable_variable_path(LIB_INSTALL_DIR "Install directory for library files, defaults to 
CMAKE_INSTALL_PREFIX/lib{LIB_SUFFIX}" "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
 add_printable_variable_path(LIBEXEC_INSTALL_DIR "Install directory for library executable files, defaults to 
CMAKE_INSTALL_PREFIX/libexec" "${CMAKE_INSTALL_PREFIX}/libexec")
-add_printable_variable_path(SHARE_INSTALL_PREFIX "Install directory for shared files, defaults to 
CMAKE_INSTALL_PREFIX/share" "${CMAKE_INSTALL_PREFIX}/share")
-add_printable_variable_path(LOCALE_INSTALL_PREFIX "Install directory for locale files, defaults to 
SHARE_INSTALL_PREFIX/locale" "${SHARE_INSTALL_PREFIX}/locale")
+add_printable_variable_path(SHARE_INSTALL_DIR "Install directory for shared files, defaults to 
CMAKE_INSTALL_PREFIX/share" "${CMAKE_INSTALL_PREFIX}/share")
+add_printable_variable_path(LOCALE_INSTALL_DIR "Install directory for locale files, defaults to 
SHARE_INSTALL_DIR/locale" "${SHARE_INSTALL_DIR}/locale")
 add_printable_variable_path(SYSCONF_INSTALL_DIR "Install directory for system configuration files, defaults 
to CMAKE_INSTALL_PREFIX/etc" "${CMAKE_INSTALL_PREFIX}/etc")
 
 # ******************************
@@ -139,7 +139,7 @@ add_printable_variable_path(SYSCONF_INSTALL_DIR "Install directory for system co
 # If you add something here, consider whether or not you also
 # need to add it to one or more .pc.in files (for Connector, etc)
 
-set(privdatadir "${SHARE_INSTALL_PREFIX}/${PROJECT_NAME}")
+set(privdatadir "${SHARE_INSTALL_DIR}/${PROJECT_NAME}")
 set(privincludedir "${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}")
 set(privlibdir "${LIB_INSTALL_DIR}/${PROJECT_NAME}")
 set(privlibexecdir "${LIBEXEC_INSTALL_DIR}'/${PROJECT_NAME}")
@@ -153,7 +153,7 @@ else(WIN32)
        set(privsolibdir "${privlibdir}")
 endif(WIN32)
 
-set(imagesdir "${SHARE_INSTALL_PREFIX}/pixmaps/${PROJECT_NAME}")
+set(imagesdir "${SHARE_INSTALL_DIR}/pixmaps/${PROJECT_NAME}")
 set(moduledir "${privlibdir}/registry-modules")
 set(credentialmoduledir "${privlibdir}/credential-modules")
 set(ebook_backenddir "${privlibdir}/addressbook-backends")
@@ -175,7 +175,7 @@ if(WIN32 AND (NOT ("$ENV{WIN32_SERVICELIBEXECDIR}" STREQUAL "")))
        set(servicelibexecdir "$ENV{WIN32_SERVICELIBEXECDIR}")
 endif(WIN32 AND (NOT ("$ENV{WIN32_SERVICELIBEXECDIR}" STREQUAL "")))
 
-add_printable_variable_path(WITH_DBUS_SERVICE_DIR "Set directory for D-Bus service files" 
"${SHARE_INSTALL_PREFIX}/dbus-1/services")
+add_printable_variable_path(WITH_DBUS_SERVICE_DIR "Set directory for D-Bus service files" 
"${SHARE_INSTALL_DIR}/dbus-1/services")
 
 # It is correct for this to be in ${CMAKE_INSTALL_PREFIX}/lib, even on systems where that
 # does not match ${LIB_INSTALL_DIR}. This is what systemd uses on such platforms.
@@ -207,6 +207,7 @@ include(CodeCoverageGCOV)
 include(CheckTarget)
 include(DistTarget)
 include(GLibTools)
+include(GObjectIntrospection)
 include(PkgConfigEx)
 include(SetupBuildFlags)
 include(UninstallTarget)
@@ -852,5 +853,5 @@ add_definitions(-DHAVE_CONFIG_H=1)
 print_build_options()
 
 add_subdirectory(camel)
-add_subdirectory(private)
 add_subdirectory(libedataserver)
+add_subdirectory(private)
diff --git a/camel/CMakeLists.txt b/camel/CMakeLists.txt
index 6cd088d..4a21b44 100644
--- a/camel/CMakeLists.txt
+++ b/camel/CMakeLists.txt
@@ -18,7 +18,6 @@ set(SOURCES
        camel-data-wrapper.c
        camel-db.c
        camel-debug.c
-       camel-enumtypes.c
        camel-file-utils.c
        camel-filter-driver.c
        camel-filter-input-stream.c
@@ -60,7 +59,6 @@ set(SOURCES
        camel-mime-parser.c
        camel-mime-part-utils.c
        camel-mime-part.c
-       camel-mime-tables.c
        camel-mime-utils.c
        camel-msgport.c
        camel-multipart-encrypted.c
@@ -118,6 +116,8 @@ set(SOURCES
        camel-vee-store.c
        camel-vee-summary.c
        camel-vtrash-folder.c
+       ${CMAKE_CURRENT_BINARY_DIR}/camel-enumtypes.c
+       ${CMAKE_CURRENT_BINARY_DIR}/camel-mime-tables.c
 )
 
 if(WIN32)
@@ -266,7 +266,7 @@ target_compile_definitions(camel PRIVATE
        -DCAMEL_LIBEXECDIR=\"${LIBEXEC_INSTALL_DIR}\"
        -DCAMEL_PROVIDERDIR=\"${camel_providerdir}\"
        -DE_DATA_SERVER_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"
-       -DLOCALEDIR=\"${LOCALE_INSTALL_PREFIX}\"
+       -DLOCALEDIR=\"${LOCALE_INSTALL_DIR}\"
        -DCAMEL_COMPILATION
 )
 
@@ -307,6 +307,29 @@ install(FILES ${HEADERS}
 
 add_pkgconfig_file(camel.pc.in camel-${API_VERSION}.pc)
 
+set(gir_sources ${SOURCES} ${HEADERS})
+set(gir_identifies_prefixes Camel camel)
+set(gir_includes GObject-2.0 Gio-2.0 libxml2-2.0)
+set(gir_cflags ${CAMEL_CFLAGS} -DCAMEL_COMPILATION)
+set(gir_libdirs)
+set(gir_libs camel)
+
+# Enable once the typelib will be buildable; the gi-r-compiler crashes with
+#    ERROR:girepository/girparser.c:343:state_switch: assertion failed: (ctx->state != newstate)
+#
+#gir_add_introspection_simple(
+#      Camel
+#      camel
+#      ${API_VERSION}
+#      "camel/camel.h"
+#      gir_identifies_prefixes
+#      gir_includes
+#      gir_cflags
+#      gir_libdirs
+#      gir_libs
+#      gir_sources
+#)
+
 if(NOT WIN32)
        add_executable(camel-lock-helper
                camel-lock.c
@@ -324,7 +347,7 @@ if(NOT WIN32)
                -DCAMEL_LIBEXECDIR=\"${LIBEXEC_INSTALL_DIR}\"
                -DCAMEL_PROVIDERDIR=\"${camel_providerdir}\"
                -DE_DATA_SERVER_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"
-               -DLOCALEDIR=\"${LOCALE_INSTALL_PREFIX}\"
+               -DLOCALEDIR=\"${LOCALE_INSTALL_DIR}\"
                -DCAMEL_COMPILATION
        )
 
@@ -364,7 +387,7 @@ target_compile_definitions(camel-index-control PRIVATE
        -DCAMEL_LIBEXECDIR=\"${LIBEXEC_INSTALL_DIR}\"
        -DCAMEL_PROVIDERDIR=\"${camel_providerdir}\"
        -DE_DATA_SERVER_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"
-       -DLOCALEDIR=\"${LOCALE_INSTALL_PREFIX}\"
+       -DLOCALEDIR=\"${LOCALE_INSTALL_DIR}\"
        -DCAMEL_COMPILATION
 )
 
diff --git a/cmake/modules/GObjectIntrospection.cmake b/cmake/modules/GObjectIntrospection.cmake
new file mode 100644
index 0000000..020f7a3
--- /dev/null
+++ b/cmake/modules/GObjectIntrospection.cmake
@@ -0,0 +1,197 @@
+# GObjectIntrospection.cmake
+#
+# Adds an option -DENABLE_INTROSPECTION=OFF and helper commands which work only
+# when the introspection is enabled.
+#
+# Most of the script is copied and tuned from libical, which states:
+#    Copyright (C) 2010, Pino Toscano, <pino at kde.org>
+#
+#    Redistribution and use is allowed according to the terms of the BSD license.
+#    For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+include(PrintableOptions)
+include(PkgConfigEx)
+
+add_printable_option(ENABLE_INTROSPECTION "Enable GObject introspection" OFF)
+
+if(ENABLE_INTROSPECTION)
+       pkg_check_modules_for_option(ENABLE_INTROSPECTION "GObject introspection" GOBJECT_INTROSPECTION 
gobject-introspection-1.0)
+
+       pkg_check_variable(G_IR_SCANNER gobject-introspection-1.0 g_ir_scanner)
+       pkg_check_variable(G_IR_COMPILER gobject-introspection-1.0 g_ir_compiler)
+
+       if(NOT G_IR_SCANNER)
+               message(FATAL_ERROR "g-ir-scanner not provided by gobject-introspection-1.0, you can disable 
GObject introspection by -DENABLE_INTROSPECTION=OFF")
+       endif(NOT G_IR_SCANNER)
+       if(NOT G_IR_COMPILER)
+               message(FATAL_ERROR "g-ir-compiler not provided by gobject-introspection-1.0, you can disable 
GObject introspection by -DENABLE_INTROSPECTION=OFF")
+       endif(NOT G_IR_COMPILER)
+endif(ENABLE_INTROSPECTION)
+
+macro(_gir_list_prefix _outvar _listvar _prefix)
+       set(${_outvar})
+       foreach(_item IN LISTS ${_listvar})
+               list(APPEND ${_outvar} ${_prefix}${_item})
+       endforeach()
+endmacro(_gir_list_prefix)
+
+macro(_gir_list_prefix_libs _outvar _listvar _prefix)
+       set(${_outvar})
+       foreach(_item IN LISTS ${_listvar})
+               get_target_property(_output_name ${_item} OUTPUT_NAME)
+               if(_output_name)
+                       list(APPEND ${_outvar} ${_prefix}${_output_name})
+               else(_output_name)
+                       list(APPEND ${_outvar} ${_prefix}${_item})
+               endif(_output_name)
+       endforeach()
+endmacro(_gir_list_prefix_libs)
+
+macro(gir_construct_names _prefix _version _out_girname _out_varsprefix)
+       set(${_out_girname} "${_prefix}-${_version}.gir")
+       set(_varsprefix ${${_out_girname}})
+
+       string(REPLACE "-" "_" _varsprefix "${_varsprefix}")
+       string(REPLACE "." "_" _varsprefix "${_varsprefix}")
+
+       set(${_out_varsprefix} ${_varsprefix})
+endmacro(gir_construct_names)
+
+# the macro does something only if ENABLE_INTROSPECTION is ON
+macro(gir_add_introspection gir)
+       if(ENABLE_INTROSPECTION)
+               set(_gir_girs)
+               set(_gir_typelibs)
+
+               set(_gir_name "${gir}")
+
+               ## Transform the gir filename to something which can reference through a variable
+               ## without automake/make complaining, eg Gtk-2.0.gir -> Gtk_2_0_gir
+               string(REPLACE "-" "_" _gir_name "${_gir_name}")
+               string(REPLACE "." "_" _gir_name "${_gir_name}")
+
+               # Namespace and Version is either fetched from the gir filename
+               # or the _NAMESPACE/_VERSION variable combo
+               set(_gir_namespace "${${_gir_name}_NAMESPACE}")
+               if (_gir_namespace STREQUAL "")
+                       string(REGEX REPLACE "([^-]+)-.*" "\\1" _gir_namespace "${gir}")
+               endif ()
+               set(_gir_version "${${_gir_name}_VERSION}")
+               if (_gir_version STREQUAL "")
+                       string(REGEX REPLACE ".*-([^-]+).gir" "\\1" _gir_version "${gir}")
+               endif ()
+
+               # _PROGRAM is an optional variable which needs its own --program argument
+               set(_gir_program "${${_gir_name}_PROGRAM}")
+               if (NOT _gir_program STREQUAL "")
+                       set(_gir_program "--program=${_gir_program}")
+               endif ()
+
+               # Variables which provides a list of things
+               _gir_list_prefix_libs(_gir_libraries ${_gir_name}_LIBS "--library=")
+               _gir_list_prefix(_gir_packages ${_gir_name}_PACKAGES "--pkg=")
+               _gir_list_prefix(_gir_includes ${_gir_name}_INCLUDES "--include=")
+
+               # Reuse the LIBTOOL variable from by automake if it's set
+               set(_gir_libtool "--no-libtool")
+
+               add_custom_command(
+                       COMMAND ${G_IR_SCANNER}
+                               ${INTROSPECTION_SCANNER_ARGS}
+                               --namespace=${_gir_namespace}
+                               --nsversion=${_gir_version}
+                               ${_gir_libtool}
+                               ${_gir_program}
+                               ${_gir_libraries}
+                               ${_gir_packages}
+                               ${_gir_includes}
+                               ${${_gir_name}_SCANNERFLAGS}
+                               ${${_gir_name}_CFLAGS}
+                               ${${_gir_name}_FILES}
+                               --output ${CMAKE_CURRENT_BINARY_DIR}/${gir}
+                               --accept-unprefixed
+                       DEPENDS ${${_gir_name}_FILES}
+                               ${${_gir_name}_LIBS}
+                       OUTPUT ${gir}
+                       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                       VERBATIM
+               )
+               list(APPEND _gir_girs ${CMAKE_CURRENT_BINARY_DIR}/${gir})
+               install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${gir} DESTINATION ${SHARE_INSTALL_DIR}/gir-1.0)
+
+               string(REPLACE ".gir" ".typelib" _typelib "${gir}")
+               add_custom_command(
+                       COMMAND ${G_IR_COMPILER}
+                               ${INTROSPECTION_COMPILER_ARGS}
+                               --includedir=.
+                               ${CMAKE_CURRENT_BINARY_DIR}/${gir}
+                               -o ${CMAKE_CURRENT_BINARY_DIR}/${_typelib}
+                       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${gir}
+                       OUTPUT ${_typelib}
+                       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+               )
+               list(APPEND _gir_typelibs ${CMAKE_CURRENT_BINARY_DIR}/${_typelib})
+               install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_typelib} DESTINATION 
${LIB_INSTALL_DIR}/girepository-1.0)
+
+               add_custom_target(gir-girs-${_gir_name} ALL DEPENDS ${_gir_girs})
+               add_custom_target(gir-typelibs-${_gir_name} ALL DEPENDS ${_gir_typelibs})
+       endif(ENABLE_INTROSPECTION)
+endmacro(gir_add_introspection)
+
+macro(gir_add_introspection_simple gir_library pkg_export_prefix gir_library_version c_include 
gir_identifies_prefixes_var gir_includes_var extra_cflags_var gir_extra_libdirs_var gir_libs_var 
gir_sources_var)
+       gir_construct_names(${gir_library} ${gir_library_version} gir_name gir_vars_prefix)
+
+       unset(INTROSPECTION_SCANNER_FLAGS)
+       unset(INTROSPECTION_SCANNER_ARGS)
+       unset(INTROSPECTION_COMPILER_ARGS)
+
+       set(${gir_vars_prefix} ${gir_library})
+       set(${gir_vars_prefix}_SCANNERFLAGS "--warn-all")
+       set(${gir_vars_prefix}_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
+       set(${gir_vars_prefix}_LIBRARY "${gir_vars_prefix}")
+       set(${gir_vars_prefix}_INCLUDES ${${gir_includes_var}})
+       set(${gir_vars_prefix}_CFLAGS
+               -I${CMAKE_CURRENT_BINARY_DIR}
+               -I${CMAKE_BINARY_DIR}
+               -I${CMAKE_CURRENT_SOURCE_DIR}
+               -I${CMAKE_SOURCE_DIR}
+               ${${extra_cflags_var}}
+       )
+       set(${gir_vars_prefix}_LIBS ${${gir_libs_var}})
+       set(${gir_vars_prefix}_FILES ${${gir_sources_var}})
+
+       _gir_list_prefix(_gir_identifies_prefixes ${gir_identifies_prefixes_var} "--identifier-prefix=")
+       _gir_list_prefix(_gir_extra_libdirs ${gir_extra_libdirs_var} "--library-path=")
+
+       set(INTROSPECTION_SCANNER_ARGS
+               --add-include-path=${CMAKE_BINARY_DIR}
+               --add-include-path=${CMAKE_SOURCE_DIR}
+               --add-include-path=${CMAKE_CURRENT_BINARY_DIR}
+               --add-include-path=${CMAKE_CURRENT_SOURCE_DIR}
+               --library-path=${LIB_INSTALL_DIR}
+               --library-path=${CMAKE_BINARY_DIR}
+               --library-path=${CMAKE_CURRENT_BINARY_DIR}
+               ${_gir_extra_libdirs}
+               ${_gir_identifies_prefixes}
+               --pkg-export ${pkg_export_prefix}-${gir_library_version}
+               --c-include="${c_include}"
+               --cflags-begin
+               ${${gir_vars_prefix}_CFLAGS}
+               --cflags-end
+               --verbose
+       )
+
+       gir_add_introspection(${gir_name})
+
+endmacro(gir_add_introspection_simple)
+
+macro(gir_filter_out_sources _inout_listvar _contains_str)
+       set(_tmp)
+       foreach(_item IN LISTS ${_inout_listvar})
+               string(FIND "${_item}" "${_contains_str}" _contains)
+               if(_contains EQUAL -1)
+                       list(APPEND _tmp ${_prefix}${_item})
+               endif(_contains EQUAL -1)
+       endforeach()
+       set(${_inout_listvar} ${_tmp})
+endmacro(gir_filter_out_sources)
diff --git a/libedataserver/CMakeLists.txt b/libedataserver/CMakeLists.txt
index 80cdae6..2574a8c 100644
--- a/libedataserver/CMakeLists.txt
+++ b/libedataserver/CMakeLists.txt
@@ -78,7 +78,6 @@ set(SOURCES
        e-source-credentials-provider-impl.c
        e-source-credentials-provider-impl-google.c
        e-source-credentials-provider-impl-password.c
-       e-source-enumtypes.c
        e-source-goa.c
        e-source-ldap.c
        e-source-local.c
@@ -113,6 +112,7 @@ set(SOURCES
        e-xml-hash-utils.c
        libedataserver-private.h
        eds-version.c
+       ${CMAKE_CURRENT_BINARY_DIR}/e-source-enumtypes.c
 )
 
 set(HEADERS
@@ -209,7 +209,7 @@ set_target_properties(edataserver PROPERTIES
 target_compile_definitions(edataserver PRIVATE
        -DG_LOG_DOMAIN=\"e-data-server\"
        -DE_DATA_SERVER_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"
-       -DE_DATA_SERVER_LOCALEDIR=\"${LOCALE_INSTALL_PREFIX}\"
+       -DE_DATA_SERVER_LOCALEDIR=\"${LOCALE_INSTALL_DIR}\"
        -DE_DATA_SERVER_IMAGESDIR=\"${imagesdir}\"
        -DE_DATA_SERVER_CREDENTIALMODULEDIR=\"${credentialmoduledir}\"
        -DE_DATA_SERVER_PRIVDATADIR=\"${privdatadir}\"
@@ -255,3 +255,26 @@ install(TARGETS edataserver
 install(FILES ${HEADERS}
        DESTINATION ${privincludedir}/libedataserver
 )
+
+set(gir_sources ${SOURCES} ${HEADERS})
+set(gir_identifies_prefixes E)
+set(gir_includes GObject-2.0 Gio-2.0 Soup-2.4 libxml2-2.0)
+set(gir_cflags ${CAMEL_CFLAGS} ${DATA_SERVER_CFLAGS} -DLIBEDATASERVER_COMPILATION)
+set(gir_libdirs ${CMAKE_BINARY_DIR}/private)
+set(gir_libs camel edataserver)
+
+gir_filter_out_sources(gir_sources e-sexp.h)
+gir_filter_out_sources(gir_sources -private.h)
+
+gir_add_introspection_simple(
+       EDataServer
+       libedataserver
+       ${API_VERSION}
+       "libedataserver/libedataserver.h"
+       gir_identifies_prefixes
+       gir_includes
+       gir_cflags
+       gir_libdirs
+       gir_libs
+       gir_sources
+)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]