2
0

CheckCXXStdPutTime.cmake 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #
  2. # SRT - Secure, Reliable, Transport Copyright (c) 2022 Haivision Systems Inc.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public License,
  5. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  6. # obtain one at http://mozilla.org/MPL/2.0/.
  7. #
  8. # Check for C++11 std::put_time().
  9. #
  10. # Sets:
  11. # HAVE_CXX_STD_PUT_TIME
  12. include(CheckCSourceCompiles)
  13. function(CheckCXXStdPutTime)
  14. unset(HAVE_CXX_STD_PUT_TIME CACHE)
  15. set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE) # CMake 3.6
  16. unset(CMAKE_REQUIRED_FLAGS)
  17. unset(CMAKE_REQUIRED_LIBRARIES)
  18. unset(CMAKE_REQUIRED_LINK_OPTIONS)
  19. set(CheckCXXStdPutTime_CODE
  20. "
  21. #include <iostream>
  22. #include <iomanip>
  23. #include <ctime>
  24. int main(void)
  25. {
  26. const int result = 0;
  27. std::time_t t = std::time(nullptr);
  28. std::tm tm = *std::localtime(&t);
  29. std::cout
  30. << std::put_time(&tm, \"%FT%T\")
  31. << std::setfill('0')
  32. << std::setw(6)
  33. << std::endl;
  34. return result;
  35. }
  36. "
  37. )
  38. # NOTE: Should we set -std or use the current compiler configuration.
  39. # It seems that the top level build does not track the compiler
  40. # in a consistent manner. So Maybe we need this?
  41. set(CMAKE_REQUIRED_FLAGS "-std=c++11")
  42. # Check that the compiler can build the std::put_time() example:
  43. message(STATUS "Checking for C++ 'std::put_time()':")
  44. check_cxx_source_compiles(
  45. "${CheckCXXStdPutTime_CODE}"
  46. HAVE_CXX_STD_PUT_TIME)
  47. endfunction(CheckCXXStdPutTime)