Digikam/CMake Documentation(Frameworks): Difference between revisions

From KDE Community Wiki
*>Veaceslav
No edit summary
m (11 revisions imported)
 
(8 intermediate revisions by one other user not shown)
Line 19: Line 19:


each of them depend on various sources which must be compiled before.
each of them depend on various sources which must be compiled before.
===Folder structure===
Sources are still not completely modular, but still follows this structure:
* core/app - digikamgui components - used in digikam main app
*core/libs - digikamcore components
*core/libs/database - digikamdatabase shared library components + digikam gui sources
*core/utilities - digikam main executable components
*core/imageplugins - image plugins shared libraries
*core/showfoto - showfoto sources for showfoto executable
==CMake Implementation Details ==
== Include directories ==
Local include directories are all managed by this snippet of code:
<source lang="bash">
set(DK_INCLUDES_ALL "")
HEADER_DIRECTORIES(DK_LOCAL_INCLUDES_RAW)
</source>
The libjpeg- folders are all included, so we need to delete them all and include the correct one only:
<source lang="bash">
# This macro will set all paths which do not containt libjpeg-
# We will add later the directory we need
FOREACH(var ${DK_LOCAL_INCLUDES_RAW})
    STRING(REGEX MATCH "libjpeg-" item ${var})
    IF(item STREQUAL "")
        LIST(APPEND DK_LOCAL_INCLUDES ${var})
    ENDIF(item)
ENDFOREACH(var)
set(DK_LOCAL_INCLUDES ${DK_LOCAL_INCLUDES}
                      libs/jpegutils/${DIGIKAM_LIBJPEG_DIR})
include_directories(${DK_LOCAL_INCLUDES})
</source>
There is no need for manual intervention to add new includes, even if you add a new folder, just keep in mind to use:
<source lang="C">
#include "tagmngrlistitem.h"
</source>
instead of :
<source lang="C">
#include "models/tagmngrlistitem.h"
</source>


=== Shared Libraries ===
=== Shared Libraries ===
Line 24: Line 72:
* digikamcore - core components used by almost all executables
* digikamcore - core components used by almost all executables
*digikamdatabase - database components, also used together with digikamcore
*digikamdatabase - database components, also used together with digikamcore
* imageplugins - image plugin implementation
* imageplugins - image plugin implementation - soon to be deprecated
*kio modules - soon to be deprecated
*kio modules - soon to be deprecated


{{Warning| Please add sources to digikam core or digikam database only if they don't depend on any big component from digikam main executable. These two shared libs must be kept small because they link in a lot of places}}
{{Warning| Please add sources to digikam core or digikam database only if they don't depend on any big component from digikam main executable. These two shared libs must be kept small because they link in a lot of places}}
Line 36: Line 85:
*baloowrap
*baloowrap
This libs are linked in digikam main executable and some tests
This libs are linked in digikam main executable and some tests
{{Warning| Avoid making static libs, use OBJECT libraries instead. Only make STATIC libraries which does not depend on other digikam code. Also make sure you put the PRIVATE parameter when setting the target_link_libraries.}}
{{Warning| Avoid making static libs, use OBJECT libraries instead. Only make STATIC libraries which does not depend on other digikam code. Also make sure you put the PRIVATE parameter when setting the target_link_libraries.
<source lang="bash">
target_link_libraries(digikamcore
                      PRIVATE
                      Qt5::Core
                      Qt5::Gui
                      Qt5::Widgets
)
</source>
}}


===Object Libraries ===
===Object Libraries ===
Line 59: Line 117:
add_library(digikamcore
add_library(digikamcore
             SHARED
             SHARED
            $<TARGET_OBJECTS:slideshow_src> # the lib we made  few lines above
             $<TARGET_OBJECTS:digikamdatabasecore_src>
             $<TARGET_OBJECTS:digikamdatabasecore_src>
             $<TARGET_OBJECTS:dimg_src>
             $<TARGET_OBJECTS:dimg_src>
Line 64: Line 123:
)
)
</source>
</source>
==Final Words==
==Final Words==
{{Remember|Please follow the guidelines when adding sources to CMakeFiles:
{{Remember|Please follow the guidelines when adding sources to CMakeFiles:

Latest revision as of 17:44, 18 March 2016

Introduction

CMake configuration files were rewritten by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com> at 10 June 2014. The aim of new configuration was to reduce the linking overhead and improve CPU utilization while still keeping the modular design implemented by Teemu Rytilahti

CMake Structure

Independent Cmake configuration is presents in following folders:

  • digikam-software-compilation
  • core
  • extra
  • docs

The rewrite touched mostly the core folder.

CMake executables for core

Core cmake will link the following executable:

  • digikam
  • showfoto
  • digikam database server - if compilation is enabled in cmake files
  • various test executables - if testing is enabled

each of them depend on various sources which must be compiled before.

Folder structure

Sources are still not completely modular, but still follows this structure:

  • core/app - digikamgui components - used in digikam main app
  • core/libs - digikamcore components
  • core/libs/database - digikamdatabase shared library components + digikam gui sources
  • core/utilities - digikam main executable components
  • core/imageplugins - image plugins shared libraries
  • core/showfoto - showfoto sources for showfoto executable

CMake Implementation Details

Include directories

Local include directories are all managed by this snippet of code:

set(DK_INCLUDES_ALL "")

HEADER_DIRECTORIES(DK_LOCAL_INCLUDES_RAW)

The libjpeg- folders are all included, so we need to delete them all and include the correct one only:

# This macro will set all paths which do not containt libjpeg-
# We will add later the directory we need

FOREACH(var ${DK_LOCAL_INCLUDES_RAW})
    STRING(REGEX MATCH "libjpeg-" item ${var})
    IF(item STREQUAL "")
        LIST(APPEND DK_LOCAL_INCLUDES ${var})
    ENDIF(item)
ENDFOREACH(var)

set(DK_LOCAL_INCLUDES ${DK_LOCAL_INCLUDES}
                      libs/jpegutils/${DIGIKAM_LIBJPEG_DIR})

include_directories(${DK_LOCAL_INCLUDES})

There is no need for manual intervention to add new includes, even if you add a new folder, just keep in mind to use:

#include "tagmngrlistitem.h"

instead of :

#include "models/tagmngrlistitem.h"

Shared Libraries

To avoid linking overhead and make a better use of sources there are some dynamic libs.

  • digikamcore - core components used by almost all executables
  • digikamdatabase - database components, also used together with digikamcore
  • imageplugins - image plugin implementation - soon to be deprecated
  • kio modules - soon to be deprecated


Warning

Please add sources to digikam core or digikam database only if they don't depend on any big component from digikam main executable. These two shared libs must be kept small because they link in a lot of places


Static Libraries

Currently cmake configuration features 4 shared libs:

  • queuemanager
  • advancedrename
  • importui
  • baloowrap

This libs are linked in digikam main executable and some tests

Warning

Avoid making static libs, use OBJECT libraries instead. Only make STATIC libraries which does not depend on other digikam code. Also make sure you put the PRIVATE parameter when setting the target_link_libraries.
target_link_libraries(digikamcore
                      PRIVATE
                      Qt5::Core
                      Qt5::Gui
                      Qt5::Widgets
)


Object Libraries

While static libraries are still collection of objects, CMake offer a better approach by allowing to specify an OBJECT library:

set(libslideshow_SRCS
    slidetoolbar.cpp
    slideosd.cpp
    slideproperties.cpp
    slideimage.cpp
    slideerror.cpp
    slideend.cpp
    slideshow.cpp
    slidehelp.cpp
    slideshowsettings.cpp
)

add_library(slideshow_src OBJECT ${libslideshow_SRCS})

OBJECT library is a cmake internal implementation feature and allow to easily manage sources. Here is an example of how to make a shared lib using OBJECT libraries:

add_library(digikamcore
            SHARED
            $<TARGET_OBJECTS:slideshow_src> # the lib we made  few lines above
            $<TARGET_OBJECTS:digikamdatabasecore_src>
            $<TARGET_OBJECTS:dimg_src>
           ....
)

Final Words

 
Remember
Please follow the guidelines when adding sources to CMakeFiles:
  • Use OBJECT libraries
  • Avoid using STATIC libraries
  • Use PRIVATE parameter on target_link_libraries
  • Keep digikamcore and digikamdatabase libraries small