File: CheckCXXStdPutTime.cmake

package info (click to toggle)
srt 1.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,804 kB
  • sloc: cpp: 52,175; ansic: 5,746; tcl: 1,183; sh: 318; python: 99; makefile: 38
file content (57 lines) | stat: -rw-r--r-- 1,576 bytes parent folder | download | duplicates (2)
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
#
# SRT - Secure, Reliable, Transport Copyright (c) 2022 Haivision Systems Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.
#

# Check for C++11 std::put_time().
#
# Sets:
#   HAVE_CXX_STD_PUT_TIME

include(CheckCSourceCompiles)

function(CheckCXXStdPutTime)

   unset(HAVE_CXX_STD_PUT_TIME CACHE)

   set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE) # CMake 3.6

   unset(CMAKE_REQUIRED_FLAGS)
   unset(CMAKE_REQUIRED_LIBRARIES)
   unset(CMAKE_REQUIRED_LINK_OPTIONS)

   set(CheckCXXStdPutTime_CODE
      "
      #include <iostream>
      #include <iomanip>
      #include <ctime>
      int main(void)
      {
         const int result = 0;
         std::time_t t = std::time(nullptr);
         std::tm tm = *std::localtime(&t);
         std::cout
            << std::put_time(&tm, \"%FT%T\")
            << std::setfill('0')
            << std::setw(6)
            << std::endl;
         return result;
      }
      "
   )

   # NOTE: Should we set -std or use the current compiler configuration.
   #     It seems that the top level build does not track the compiler
   #     in a consistent manner. So Maybe we need this?
   set(CMAKE_REQUIRED_FLAGS "-std=c++11")

   # Check that the compiler can build the std::put_time() example:
   message(STATUS "Checking for C++ 'std::put_time()':")
   check_cxx_source_compiles(
      "${CheckCXXStdPutTime_CODE}"
      HAVE_CXX_STD_PUT_TIME)

endfunction(CheckCXXStdPutTime)