source: calamares/trunk/fuentes/CMakeModules/CalamaresAddPlugin.cmake @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 6.0 KB
Line 
1# === This file is part of Calamares - <https://github.com/calamares> ===
2#
3#   Calamares is free software: you can redistribute it and/or modify
4#   it under the terms of the GNU General Public License as published by
5#   the Free Software Foundation, either version 3 of the License, or
6#   (at your option) any later version.
7#
8#   Calamares is distributed in the hope that it will be useful,
9#   but WITHOUT ANY WARRANTY; without even the implied warranty of
10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11#   GNU General Public License for more details.
12#
13#   You should have received a copy of the GNU General Public License
14#   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
15#
16#   SPDX-License-Identifier: GPL-3.0+
17#   License-Filename: LICENSE
18#
19###
20#
21# Convenience function for creating a C++ (qtplugin) module for Calamares.
22# This function provides cmake-time feedback about the plugin, adds
23# targets for compilation and boilerplate information, and creates
24# a module.desc with standard values if none is provided (which only
25# happens for very unusual plugins).
26#
27# Usage:
28#
29# calamares_add_plugin(
30#   module-name
31#   TYPE <view|job>
32#   EXPORT_MACRO macro-name
33#   SOURCES source-file...
34#   UI ui-file...
35#   LINK_LIBRARIES lib...
36#   LINK_PRIVATE_LIBRARIES lib...
37#   COMPILE_DEFINITIONS def...
38#   RESOURCES resource-file
39#   [NO_INSTALL]
40#   [SHARED_LIB]
41# )
42
43include( CMakeParseArguments )
44include( CalamaresAddLibrary  )
45include( CMakeColors )
46
47function( calamares_add_plugin )
48    # parse arguments ( name needs to be saved before passing ARGN into the macro )
49    set( NAME ${ARGV0} )
50    set( options NO_INSTALL SHARED_LIB )
51    set( oneValueArgs NAME TYPE EXPORT_MACRO RESOURCES )
52    set( multiValueArgs SOURCES UI LINK_LIBRARIES LINK_PRIVATE_LIBRARIES COMPILE_DEFINITIONS )
53    cmake_parse_arguments( PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
54    set( PLUGIN_NAME ${NAME} )
55    set( PLUGIN_DESTINATION ${CMAKE_INSTALL_LIBDIR}/calamares/modules/${PLUGIN_NAME} )
56    set( PLUGIN_DESC_FILE module.desc )
57    file( GLOB PLUGIN_CONFIG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.conf" )
58    set( PLUGIN_DATA_DESTINATION share/calamares/modules )
59    set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
60    set( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
61    set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
62
63    message( "-- ${BoldYellow}Found ${CALAMARES_APPLICATION_NAME} module: ${BoldRed}${PLUGIN_NAME}${ColorReset}" )
64    if( NOT CMAKE_BUILD_TYPE STREQUAL "Release" )
65        message( "   ${Green}TYPE:${ColorReset} ${PLUGIN_TYPE}" )
66        message( "   ${Green}LINK_LIBRARIES:${ColorReset} ${PLUGIN_LINK_LIBRARIES}" )
67        message( "   ${Green}LINK_PRIVATE_LIBRARIES:${ColorReset} ${PLUGIN_LINK_PRIVATE_LIBRARIES}" )
68#        message( "   ${Green}SOURCES:${ColorReset} ${PLUGIN_SOURCES}" )
69#        message( "   ${Green}UI:${ColorReset} ${PLUGIN_UI}" )
70#        message( "   ${Green}EXPORT_MACRO:${ColorReset} ${PLUGIN_EXPORT_MACRO}" )
71#        message( "   ${Green}NO_INSTALL:${ColorReset} ${PLUGIN_NO_INSTALL}" )
72        message( "   ${Green}PLUGIN_DESTINATION:${ColorReset} ${PLUGIN_DESTINATION}" )
73        if( PLUGIN_CONFIG_FILES )
74            if ( INSTALL_CONFIG )
75                message( "   ${Green}CONFIGURATION_FILES:${ColorReset} ${PLUGIN_CONFIG_FILES} => ${PLUGIN_DATA_DESTINATION}" )
76            else()
77                message( "   ${Green}CONFIGURATION_FILES:${ColorReset} ${PLUGIN_CONFIG_FILES} => [Skipping installation]" )
78            endif()
79        endif()
80        if( PLUGIN_RESOURCES )
81            message( "   ${Green}RESOURCES:${ColorReset} ${PLUGIN_RESOURCES}" )
82        endif()
83        message( "" )
84    endif()
85    # create target name once for convenience
86    set( target "calamares_${PLUGIN_TYPE}_${PLUGIN_NAME}" )
87
88    # determine target type
89    if( NOT ${PLUGIN_SHARED_LIB} )
90        set( target_type "MODULE" )
91    else()
92        set( target_type "SHARED" )
93    endif()
94
95    list( APPEND calamares_add_library_args
96        "${target}"
97        "EXPORT_MACRO" "${PLUGIN_EXPORT_MACRO}"
98        "TARGET_TYPE" "${target_type}"
99        "SOURCES" "${PLUGIN_SOURCES}"
100    )
101
102    if( PLUGIN_UI )
103        list( APPEND calamares_add_library_args "UI" "${PLUGIN_UI}" )
104    endif()
105
106    if( PLUGIN_LINK_LIBRARIES )
107        list( APPEND calamares_add_library_args "LINK_LIBRARIES" "${PLUGIN_LINK_LIBRARIES}" )
108    endif()
109
110    if( PLUGIN_LINK_PRIVATE_LIBRARIES )
111        list( APPEND calamares_add_library_args "LINK_PRIVATE_LIBRARIES" "${PLUGIN_LINK_PRIVATE_LIBRARIES}" )
112    endif()
113
114    if( PLUGIN_COMPILE_DEFINITIONS )
115        list( APPEND calamares_add_library_args "COMPILE_DEFINITIONS" ${PLUGIN_COMPILE_DEFINITIONS} )
116    endif()
117
118    list( APPEND calamares_add_library_args "NO_VERSION" )
119
120    list( APPEND calamares_add_library_args "INSTALL_BINDIR" "${PLUGIN_DESTINATION}" )
121
122    if( PLUGIN_RESOURCES )
123        list( APPEND calamares_add_library_args "RESOURCES" "${PLUGIN_RESOURCES}" )
124    endif()
125
126    calamares_add_library( ${calamares_add_library_args} )
127
128    if ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN_DESC_FILE} )
129        configure_file( ${PLUGIN_DESC_FILE} ${PLUGIN_DESC_FILE} COPYONLY )
130    else()
131        set( _file ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_DESC_FILE} )
132        set( _type ${PLUGIN_TYPE} )
133        file( WRITE  ${_file} "# AUTO-GENERATED metadata file\n# Syntax is YAML 1.2\n---\n" )
134        file( APPEND ${_file} "type: \"${_type}\"\nname: \"${PLUGIN_NAME}\"\ninterface: \"qtplugin\"\nload: \"lib${target}.so\"\n" )
135    endif()
136
137    install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_DESC_FILE}
138             DESTINATION ${PLUGIN_DESTINATION} )
139
140    if ( INSTALL_CONFIG )
141        foreach( PLUGIN_CONFIG_FILE ${PLUGIN_CONFIG_FILES} )
142            configure_file( ${PLUGIN_CONFIG_FILE} ${PLUGIN_CONFIG_FILE} COPYONLY )
143            install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_CONFIG_FILE}
144                     DESTINATION ${PLUGIN_DATA_DESTINATION} )
145        endforeach()
146    endif()
147endfunction()
Note: See TracBrowser for help on using the repository browser.