Ticket #68109: googletest-build-MacPorts.cmake

File googletest-build-MacPorts.cmake, 2.5 KB (added by ith140 (Ian Hoffman), 14 months ago)

googletest tile

Line 
1
2cmake_minimum_required(VERSION 3.15)
3
4set(command "/opt/local/bin/cmake;--build;.")
5set(log_merged "")
6set(log_output_on_failure "")
7set(stdout_log "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_science_root6/root6/work/build/googletest-prefix/src/googletest-stamp/googletest-build-out.log")
8set(stderr_log "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_science_root6/root6/work/build/googletest-prefix/src/googletest-stamp/googletest-build-err.log")
9execute_process(
10  COMMAND ${command}
11  RESULT_VARIABLE result
12  OUTPUT_FILE "${stdout_log}"
13  ERROR_FILE "${stderr_log}"
14)
15macro(read_up_to_max_size log_file output_var)
16  file(SIZE ${log_file} determined_size)
17  set(max_size 10240)
18  if (determined_size GREATER max_size)
19    math(EXPR seek_position "${determined_size} - ${max_size}")
20    file(READ ${log_file} ${output_var} OFFSET ${seek_position})
21    set(${output_var} "...skipping to end...\n${${output_var}}")
22  else()
23    file(READ ${log_file} ${output_var})
24  endif()
25endmacro()
26if(result)
27  set(msg "Command failed: ${result}\n")
28  foreach(arg IN LISTS command)
29    set(msg "${msg} '${arg}'")
30  endforeach()
31  if (${log_merged})
32    set(msg "${msg}\nSee also\n  ${stderr_log}")
33  else()
34    set(msg "${msg}\nSee also\n  /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_science_root6/root6/work/build/googletest-prefix/src/googletest-stamp/googletest-build-*.log")
35  endif()
36  if (${log_output_on_failure})
37    message(SEND_ERROR "${msg}")
38    if (${log_merged})
39      read_up_to_max_size("${stderr_log}" error_log_contents)
40      message(STATUS "Log output is:\n${error_log_contents}")
41    else()
42      read_up_to_max_size("${stdout_log}" out_log_contents)
43      read_up_to_max_size("${stderr_log}" err_log_contents)
44      message(STATUS "stdout output is:\n${out_log_contents}")
45      message(STATUS "stderr output is:\n${err_log_contents}")
46    endif()
47    message(FATAL_ERROR "Stopping after outputting logs.")
48  else()
49    message(FATAL_ERROR "${msg}")
50  endif()
51else()
52  if(NOT "Ninja" MATCHES "Ninja")
53    set(msg "googletest build command succeeded.  See also /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_science_root6/root6/work/build/googletest-prefix/src/googletest-stamp/googletest-build-*.log")
54    message(STATUS "${msg}")
55  endif()
56endif()