Skip to content

Commit ab06fad

Browse files
author
Raphael Dumusc
committed
Add macro in CommonCPackUtils to help package subprojects
1 parent 61e9179 commit ab06fad

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

Common.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ include(CommonInstallProject)
146146
include(CommonLibrary)
147147
include(CommonCompiler)
148148
include(CommonCoverage)
149+
include(CommonCPackUtils)
149150
include(CommonSmokeTest)
150151
include(GitInfo)
151152
include(GitTargets)

CommonCPackUtils.cmake

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) 2017 Raphael.Dumusc@epfl.ch
2+
#
3+
# Helper function for packaging subprojects using CommonCPack.
4+
#
5+
# Add subproject dependencies to the current project's package:
6+
# add_deb_depends(<Subproject>
7+
# [PACKAGE_NAME <subproject_package_name>]
8+
# [MIN_VERSION <subproject_min_version>] [<subproject_deb_depends>])
9+
#
10+
# Arguments:
11+
# * Subproject: name of the subproject
12+
# * PACKAGE_NAME: if subproject package name differs from lower_case(Subproject)
13+
# * MIN_VERSION: minimum version of the subproject's package
14+
# * ARGN: list of dependencies of the subproject
15+
#
16+
# Output (list append):
17+
# * NAME_PACKAGE_REPLACES: Subproject package name if it is being built
18+
# * NAME_PACKAGE_DEB_DEPENDS: the list of Subproject's dependencies if it is
19+
# being built; otherwise its package name.
20+
21+
macro(add_deb_depends Subproject)
22+
set(_opts)
23+
set(_singleArgs PACKAGE_NAME MIN_VERSION)
24+
set(_multiArgs)
25+
cmake_parse_arguments(THIS "${_opts}" "${_singleArgs}" "${_multiArgs}"
26+
${ARGN})
27+
set(_packages ${THIS_UNPARSED_ARGUMENTS})
28+
29+
if(THIS_PACKAGE_NAME)
30+
set(_subproject_pkg ${THIS_PACKAGE_NAME})
31+
else()
32+
string(TOLOWER ${Subproject} _subproject_pkg)
33+
endif()
34+
35+
if(${Subproject}_IS_SUBPROJECT)
36+
list(APPEND ${UPPER_PROJECT_NAME}_PACKAGE_REPLACES ${_subproject_pkg})
37+
list(APPEND ${UPPER_PROJECT_NAME}_PACKAGE_DEB_DEPENDS ${_packages})
38+
else()
39+
if(THIS_MIN_VERSION)
40+
set(_subproject_pkg "${_subproject_pkg} (>= ${THIS_MIN_VERSION})")
41+
endif()
42+
list(APPEND ${UPPER_PROJECT_NAME}_PACKAGE_DEB_DEPENDS "${_subproject_pkg}")
43+
endif()
44+
endmacro()

0 commit comments

Comments
 (0)