45749bf7a4918fbcdeef197ba576cafefa7be420
[staging/xdg-launcher.git] / cmake / cmake.d / 03-extra_targets.cmake
1 ###########################################################################
2 # Copyright 2015, 2016, 2017 IoT.bzh
3 #
4 # author: Fulup Ar Foll <fulup@iot.bzh>
5 # contrib: Romain Forlot <romain.forlot@iot.bzh>
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 ###########################################################################
19
20
21 #--------------------------------------------------------------------------
22 #  WARNING:
23 #     Do not change this cmake template
24 #     Customise your preferences in "./conf.d/cmake/config.cmake"
25 #--------------------------------------------------------------------------
26
27 # Add a dummy target to enable global dependency order
28 # -----------------------------------------------------
29 if(EXTRA_DEPENDENCIES_ORDER)
30         set(DEPENDENCIES_TARGET ${PROJECT_NAME}_extra_dependencies)
31         add_custom_target(${DEPENDENCIES_TARGET} ALL
32                 DEPENDS ${EXTRA_DEPENDENCY_ORDER}
33         )
34 endif()
35
36 # Add RSYNCTARGET
37 remote_targets_populate()
38
39 # ----------------------------------------------------------------------------
40 #                                Archive target
41 # ----------------------------------------------------------------------------
42 add_custom_command(OUTPUT  ${ARCHIVE_OUTPUT}
43         DEPENDS ${PROJECT_TARGETS}
44         #Create git archive of the main project
45         COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}\; git --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git archive --format=tar --prefix=${NPKG_PROJECT_NAME}-${PROJECT_VERSION}/ HEAD -o ${ARCHIVE_OUTPUT_ARCHIVE}
46         #Create tmp git archive for each submodule
47         COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}\; git --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git submodule foreach --recursive ${CMD_ARCHIVE_SUBMODULE}
48         #Concatenate main archive and tmp submodule archive
49         COMMAND  for SUBTAR in ${TMP_ARCHIVE_SUBMODULE}-*.tar\; do tar --concatenate --file=${ARCHIVE_OUTPUT_ARCHIVE} $$SUBTAR\;done
50         #Remove tmp submodule archive
51         COMMAND rm -rf ${TMP_ARCHIVE_SUBMODULE}-*.tar
52         #Compress main archive
53         COMMAND gzip --force --verbose ${ARCHIVE_OUTPUT_ARCHIVE}
54 )
55 add_custom_target(archive DEPENDS ${ARCHIVE_OUTPUT})
56
57         #Format Build require package
58         foreach (PKG_CONFIG ${PKG_REQUIRED_LIST})
59                 #Unset TMP variable
60                 unset(XPREFIX)
61                 unset(XRULE)
62                 unset(RPM_EXTRA_DEP)
63                 unset(DEB_EXTRA_DEP)
64                 #For deb package,add EOL format only for a new line
65                 if(DEB_PKG_DEPS)
66                         set(DEB_PKG_DEPS "${DEB_PKG_DEPS},\n")
67                 endif()
68                 #Get pkg-config rule on version
69                 string(REGEX REPLACE "[<>]?=.*$" "" XPREFIX ${PKG_CONFIG})
70                 string(REGEX MATCH "[<>]?="  XRULE ${PKG_CONFIG})
71                 #Only if pkg-config has rule on version
72                 if(XRULE)
73                         string(REGEX REPLACE ".*[<>]?=" "" XVERS ${PKG_CONFIG})
74                         set(RPM_EXTRA_DEP " ${XRULE} ${XVERS}")
75                         set(DEB_EXTRA_DEP " (${XRULE} ${XVERS})")
76                 endif()
77                 #Format for rpm package
78                 set(RPM_PKG_DEPS "${RPM_PKG_DEPS}BuildRequires: pkgconfig(${XPREFIX})${RPM_EXTRA_DEP}\n")
79                 #Format for deb package
80                 #Because the tool "dpkg" is used on the packages db to find the
81                 #package providing the pkg-cong file ${XPREFIX}.pc, we need
82                 #to test the OS release package type
83                 if( OSRELEASE MATCHES "debian" )
84                         execute_process(
85                                 COMMAND dpkg -S *${XPREFIX}.pc
86                                                 OUTPUT_VARIABLE TMP_PKG_BIN
87                                                 )
88                         #Need to be harden check
89                         string(REGEX REPLACE ":.*$" "" PKG_BIN ${TMP_PKG_BIN})
90                         set(DEB_PKG_DEPS "${DEB_PKG_DEPS} ${PKG_BIN} ${DEB_EXTRA_DEP}")
91                 endif()
92         endforeach()
93
94         if(NOT EXISTS ${RPM_TEMPLATE_DIR}/rpm-config.spec.in)
95                 MESSAGE(FATAL_ERROR "${Red}Missing mandatory files: you need rpm-config.spec.in in ${RPM_TEMPLATE_DIR} folder.${ColourReset}")
96         endif()
97
98         set(PACKAGING_SPEC_OUTPUT ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.spec)
99         add_custom_command(OUTPUT ${PACKAGING_SPEC_OUTPUT}
100                 DEPENDS ${RPM_TEMPLATE_DIR}/rpm-config.spec.in
101                 COMMAND ${CMAKE_COMMAND} -DINFILE=${RPM_TEMPLATE_DIR}/rpm-config.spec.in -DOUTFILE=${PACKAGING_SPEC_OUTPUT} -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
102         )
103
104 # ----------------------------------------------------------------------------
105 #                                Packaging target
106 # ----------------------------------------------------------------------------
107 #Because the tool "dpkg" is used on the packages db to find the
108 #package providing the pkg-cong file ${XPREFIX}.pc, we need
109 #to test the OS release package type
110 if(OSRELEASE MATCHES "debian")
111         add_custom_command(OUTPUT ${PACKAGING_DEB_OUTPUT_DSC}
112                                 ${PACKAGING_DEB_OUTPUT_INSTALL}
113                                 ${PACKAGING_DEB_OUTPUT_CHANGELOG}
114                                 ${PACKAGING_DEB_OUTPUT_COMPAT}
115                                 ${PACKAGING_DEB_OUTPUT_CONTROL}
116                                 ${PACKAGING_DEB_OUTPUT_RULES}
117                 DEPENDS ${DEB_TEMPLATE_DIR}/debian.compat.in
118                                 ${DEB_TEMPLATE_DIR}/debian.changelog.in
119                                 ${DEB_TEMPLATE_DIR}/deb-config.dsc.in
120                                 ${DEB_TEMPLATE_DIR}/deb-config.install.in
121                                 ${DEB_TEMPLATE_DIR}/debian.control.in
122                                 ${DEB_TEMPLATE_DIR}/debian.rules.in
123                                 COMMAND ${CMAKE_COMMAND} -DINFILE=${DEB_TEMPLATE_DIR}/debian.compat.in          -DOUTFILE=${PACKAGING_DEB_OUTPUT_COMPAT}        -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}        -P      ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
124                                 COMMAND ${CMAKE_COMMAND} -DINFILE=${DEB_TEMPLATE_DIR}/debian.changelog.in       -DOUTFILE=${PACKAGING_DEB_OUTPUT_CHANGELOG}     -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}        -P      ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
125                                 COMMAND ${CMAKE_COMMAND} -DINFILE=${DEB_TEMPLATE_DIR}/deb-config.dsc.in         -DOUTFILE=${PACKAGING_DEB_OUTPUT_DSC}           -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}        -P      ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
126                                 COMMAND ${CMAKE_COMMAND} -DINFILE=${DEB_TEMPLATE_DIR}/deb-config.install.in     -DOUTFILE=${PACKAGING_DEB_OUTPUT_INSTALL}       -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}        -P      ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
127                                 COMMAND ${CMAKE_COMMAND} -DINFILE=${DEB_TEMPLATE_DIR}/debian.control.in         -DOUTFILE=${PACKAGING_DEB_OUTPUT_CONTROL}       -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}        -P      ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
128                                 COMMAND ${CMAKE_COMMAND} -DINFILE=${DEB_TEMPLATE_DIR}/debian.rules.in           -DOUTFILE=${PACKAGING_DEB_OUTPUT_RULES}         -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}        -P      ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
129         )
130         add_custom_target(packaging_deb DEPENDS ${PACKAGING_DEB_OUTPUT_DSC}
131                                                 ${PACKAGING_DEB_OUTPUT_INSTALL}
132                                                 ${PACKAGING_DEB_OUTPUT_CHANGELOG}
133                                                 ${PACKAGING_DEB_OUTPUT_COMPAT}
134                                                 ${PACKAGING_DEB_OUTPUT_CONTROL}
135                                                 ${PACKAGING_DEB_OUTPUT_CONTROL}
136                                                 ${PACKAGING_DEB_OUTPUT_RULES})
137 endif()
138
139 add_custom_target(packaging)
140 add_custom_target(packaging_rpm DEPENDS ${PACKAGING_SPEC_OUTPUT})
141 add_dependencies(packaging packaging_rpm)
142 if(TARGET packaging_wgt)
143         add_dependencies(packaging packaging_wgt)
144 endif()
145 if(OSRELEASE MATCHES "debian")
146         # Target to add dependencies indirectly to "packaging" target.
147         add_dependencies(packaging packaging_deb)
148 endif()
149
150 #Generate a cmake cache file usable by cmake script.
151 set(CacheForScript ${CMAKE_BINARY_DIR}/CMakeCacheForScript.cmake)
152 #Create a tmp cmake file.
153 file(WRITE ${CacheForScript} "")
154
155 get_cmake_property(Vars VARIABLES)
156 foreach(Var ${Vars})
157         if(${Var})
158                 #Replace unwanted char.
159                 string(REPLACE "\\" "\\\\" VALUE ${${Var}})
160                 string(REPLACE "\n" "\\n" VALUE ${VALUE})
161                 string(REPLACE "\r" "\\n" VALUE ${VALUE})
162                 string(REPLACE "\"" "\\\"" VALUE ${VALUE})
163         endif()
164         file(APPEND ${CacheForScript} "set(${Var} \"${VALUE}\")\n")
165 endforeach()
166
167 # ----------------------------------------------------------------------------
168 #                                Autobuild target
169 # ----------------------------------------------------------------------------
170
171 add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/conf.d/autobuild/agl/autobuild
172                         ${CMAKE_SOURCE_DIR}/conf.d/autobuild/linux/autobuild
173         DEPENDS ${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/autobuild/agl/autobuild.in
174                 ${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/autobuild/linux/autobuild.in
175         COMMAND ${CMAKE_COMMAND} -DINFILE=${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/autobuild/agl/autobuild.in -DOUTFILE=${CMAKE_SOURCE_DIR}/conf.d/autobuild/agl/autobuild -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
176         COMMAND ${CMAKE_COMMAND} -DINFILE=${CMAKE_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/autobuild/agl/autobuild.in -DOUTFILE=${CMAKE_SOURCE_DIR}/conf.d/autobuild/linux/autobuild -DPROJECT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_APP_TEMPLATES_DIR}/cmake/configure_file.cmake
177         )
178
179 add_custom_target(autobuild ALL DEPENDS ${CMAKE_SOURCE_DIR}/conf.d/autobuild/agl/autobuild
180                                         ${CMAKE_SOURCE_DIR}/conf.d/autobuild/linux/autobuild)