forked from Slicer/Slicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTestPackage.cmake
75 lines (60 loc) · 2.26 KB
/
CTestPackage.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
################################################################################
#
# Program: 3D Slicer
#
# Copyright (c) Kitware Inc.
#
# See COPYRIGHT.txt
# or http://www.slicer.org/copyright/copyright.txt for details.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 3P41RR013218-12S1
#
################################################################################
include(CMakeParseArguments)
function(ctest_package)
set(options)
set(oneValueArgs BINARY_DIR CONFIG RETURN_VAR)
set(multiValueArgs)
cmake_parse_arguments(MY "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Sanity checks
if(NOT DEFINED MY_BINARY_DIR)
message(SEND_ERROR "BINARY_DIR is mandatory")
endif()
if(NOT DEFINED MY_CONFIG)
message(SEND_ERROR "CONFIG is mandatory")
endif()
# The following variable could be used while testing the macro ...
set(_build_target TRUE)
set(cpack_output_file ${MY_BINARY_DIR}/ctest_package_make_package_output.txt)
if(_build_target)
execute_process(
COMMAND ${CMAKE_COMMAND} --build ${MY_BINARY_DIR} --target package --config ${MY_CONFIG}
WORKING_DIRECTORY ${MY_BINARY_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_FILE ${cpack_output_file}
RESULT_VARIABLE rv
)
endif()
# TODO Display errors so that they can be sent to CDash
set(rv 0)
# List of filepath corresponding to the generated packages or installers
set(package_list)
if(rv EQUAL 0)
set(regexp ".*CPack: - package: (.*) generated\\.")
# Extract list of generated packages
set(raw_package_list)
file(STRINGS ${cpack_output_file} raw_package_list REGEX ${regexp})
foreach(package ${raw_package_list})
string(REGEX REPLACE ${regexp} "\\1" package_path "${package}" )
list(APPEND package_list ${package_path})
endforeach()
endif()
set(${MY_RETURN_VAR} ${package_list} PARENT_SCOPE)
endfunction()